Skip to content

Commit

Permalink
Added Mock Library for IoLib (#788)
Browse files Browse the repository at this point in the history
# Preface

Please ensure you have read the [contribution
docs](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md) prior
to submitting the pull request. In particular,
[pull request
guidelines](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md#pull-request-best-practices).

## Description
Added Mock Library for IoLib

For each item, place an "x" in between `[` and `]` if true. Example:
`[x]`.
_(you can also check items in the GitHub UI)_

- [ ] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested
Added Mock IoLib to a Gen11 library and checked no build errors and
ensured MockIolib definitions are called appropriately

## Integration Instructions
N/A

---------

Signed-off-by: v-bhavanisu <[email protected]>
Co-authored-by: Aaron <[email protected]>
  • Loading branch information
v-bhavanisu and apop5 authored Apr 4, 2024
1 parent 96f6943 commit 8a0ac50
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
2 changes: 2 additions & 0 deletions MdePkg/Test/MdePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@
MdePkg/Test/Mock/Library/GoogleTest/MockPeiServicesLib/MockPeiServicesLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockHobLib/MockHobLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockIoLib/MockIoLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockSmmServicesTableLib/MockSmmServicesTableLib.inf

134 changes: 134 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Library/MockIoLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/** @file MockIoLib.h
Google Test mocks for IoLib
Copyright (c) 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_IO_LIB_H_
#define MOCK_IO_LIB_H_

#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>
extern "C" {
#include <Uefi.h>
#include <Library/IoLib.h>
}

struct MockIoLib {
MOCK_INTERFACE_DECLARATION (MockIoLib);

MOCK_FUNCTION_DECLARATION (
UINT32,
MmioAndThenOr32,
(
IN UINTN Address,
IN UINT32 AndData,
IN UINT32 OrData
)
);

MOCK_FUNCTION_DECLARATION (
UINT8,
IoWrite8,
(
IN UINTN Port,
IN UINT8 Value
)
);

MOCK_FUNCTION_DECLARATION (
UINT8,
IoRead8,
(
IN UINTN Port
)
);

MOCK_FUNCTION_DECLARATION (
UINT64,
IoRead64,
(
IN UINTN Port
)
);

MOCK_FUNCTION_DECLARATION (
UINT64,
IoWrite64,
(
IN UINTN Port,
IN UINT64 Value
)
);

MOCK_FUNCTION_DECLARATION (
UINT8,
MmioRead8,
(
IN UINTN Address
)
);

MOCK_FUNCTION_DECLARATION (
UINT8,
MmioWrite8,
(
IN UINTN Address,
IN UINT8 Value
)
);

MOCK_FUNCTION_DECLARATION (
UINT16,
MmioRead16,
(
IN UINTN Address
)
);

MOCK_FUNCTION_DECLARATION (
UINT16,
MmioWrite16,
(
IN UINTN Address,
IN UINT16 Value
)
);

MOCK_FUNCTION_DECLARATION (
UINT32,
MmioRead32,
(
IN UINTN Address
)
);

MOCK_FUNCTION_DECLARATION (
UINT32,
MmioWrite32,
(
IN UINTN Address,
IN UINT32 Value
)
);

MOCK_FUNCTION_DECLARATION (
UINT64,
MmioRead64,
(
IN UINTN Address
)
);

MOCK_FUNCTION_DECLARATION (
UINT64,
MmioWrite64,
(
IN UINTN Address,
IN UINT64 Value
)
);
};

#endif
24 changes: 24 additions & 0 deletions MdePkg/Test/Mock/Library/GoogleTest/MockIoLib/MockIoLib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @file MockIoLib.cpp
Google Test mocks for IoLib
Copyright (c) 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <GoogleTest/Library/MockIoLib.h>

MOCK_INTERFACE_DEFINITION (MockIoLib);

MOCK_FUNCTION_DEFINITION (MockIoLib, MmioAndThenOr32, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, IoWrite8, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, IoRead8, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, IoRead64, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, IoWrite64, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, MmioRead8, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, MmioWrite8, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, MmioRead16, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, MmioWrite16, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, MmioRead32, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, MmioWrite32, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, MmioRead64, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockIoLib, MmioWrite64, 2, EFIAPI);
33 changes: 33 additions & 0 deletions MdePkg/Test/Mock/Library/GoogleTest/MockIoLib/MockIoLib.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## @file MockIoLib.inf
# Google Test mocks for IoLib
#
# Copyright (c) 2023, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockIoLib
FILE_GUID = C9BB51CC-F9CD-4CCF-8B11-B8E1C9C864F5
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = IoLib

#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
#

[Sources]
MockIoLib.cpp

[Packages]
MdePkg/MdePkg.dec
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec

[LibraryClasses]
GoogleTestLib

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /EHsc

0 comments on commit 8a0ac50

Please sign in to comment.