Skip to content

Commit

Permalink
Create mocks for PlatformHookLib and PciLib (#1094)
Browse files Browse the repository at this point in the history
Create mocks for PlatformHookLib and PciLib

- [ ] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [x] Includes tests?
- [ ] Includes documentation?

Unit tests component can call PlatformHookLib and PciLib mock functions
success

N/A
  • Loading branch information
TsunFeng authored and os-d committed Aug 24, 2024
1 parent 4d722ac commit 47134bd
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 0 deletions.
1 change: 1 addition & 0 deletions MdeModulePkg/Test/MdeModulePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@
# Build HOST_APPLICATION Libraries
#
MdeModulePkg/Test/Mock/Library/GoogleTest/MockPciHostBridgeLib/MockPciHostBridgeLib.inf
MdeModulePkg/Test/Mock/Library/GoogleTest/MockPlatformHookLib/MockPlatformHookLib.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @file MockPlatformHookLib.h
Google Test mocks for PlatformHookLib
Copyright (c) 2023, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_PLATFORM_HOOK_LIB_
#define MOCK_PLATFORM_HOOK_LIB_

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

struct MockPlatformHookLib {
MOCK_INTERFACE_DECLARATION (MockPlatformHookLib);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
PlatformHookSerialPortInitialize,
(

)
);
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @file MockPlatformHookLib.cpp
Mock instance of the PCI Host Bridge Library.
Copyright (c) 2023, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <GoogleTest/Library/MockPlatformHookLib.h>

MOCK_INTERFACE_DEFINITION (MockPlatformHookLib);

MOCK_FUNCTION_DEFINITION (MockPlatformHookLib, PlatformHookSerialPortInitialize, 0, EFIAPI);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## @file MockPlatformHookLib.inf
# Mock instance of the Platform hook library.
#
# Copyright (c) 2023, Intel Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockPlatformHookLib
FILE_GUID = B7721E18-FC59-4333-AE5E-B07EE71D6737
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = PlatformHookLib

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

[Sources]
MockPlatformHookLib.cpp

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

[LibraryClasses]
GoogleTestLib

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /EHsc
1 change: 1 addition & 0 deletions MdePkg/Test/MdePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@
MdePkg/Test/Mock/Library/Stub/StubUefiLib/StubUefiLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockPciExpressLib/MockPciExpressLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockUefiDevicePathLib/MockUefiDevicePathLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockPciLib/MockPciLib.inf
# MU_CHANGE [END]
127 changes: 127 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/** @file MockPciLib.h
Google Test mocks for PciLib
Copyright (c) 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_PCI_LIB_H_
#define MOCK_PCI_LIB_H_

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

struct MockPciLib {
MOCK_INTERFACE_DECLARATION (MockPciLib);

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

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

MOCK_FUNCTION_DECLARATION (
UINT8,
PciOr8,
(
IN UINTN Address,
IN UINT8 OrData
)
);

MOCK_FUNCTION_DECLARATION (
UINT8,
PciAnd8,
(
IN UINTN Address,
IN UINT8 AndData
)
);

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

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

MOCK_FUNCTION_DECLARATION (
UINT16,
PciOr16,
(
IN UINTN Address,
IN UINT16 OrData
)
);

MOCK_FUNCTION_DECLARATION (
UINT16,
PciAnd16,
(
IN UINTN Address,
IN UINT16 AndData
)
);

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

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

MOCK_FUNCTION_DECLARATION (
UINT32,
PciOr32,
(
IN UINTN Address,
IN UINT32 OrData
)
);

MOCK_FUNCTION_DECLARATION (
UINT32,
PciAnd32,
(
IN UINTN Address,
IN UINT32 AndData
)
);
};

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

#include <GoogleTest/Library/MockPciLib.h>

MOCK_INTERFACE_DEFINITION (MockPciLib);

MOCK_FUNCTION_DEFINITION (MockPciLib, PciRead8, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciWrite8, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciOr8, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciAnd8, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciRead16, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciWrite16, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciOr16, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciAnd16, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciRead32, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciWrite32, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciOr32, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciLib, PciAnd32, 2, EFIAPI);
33 changes: 33 additions & 0 deletions MdePkg/Test/Mock/Library/GoogleTest/MockPciLib/MockPciLib.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## @file MockPciLib.inf
# Google Test mocks for PciLib
#
# Copyright (c) 2023, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockPciLib
FILE_GUID = B64B61FF-8682-482E-A4DA-2BB8A7FB24AE
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = PciLib

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

[Sources]
MockPciLib.cpp

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

[LibraryClasses]
GoogleTestLib

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

0 comments on commit 47134bd

Please sign in to comment.