From d6d36cf810b81ad84ed3047165d02813644732dd Mon Sep 17 00:00:00 2001 From: Vivian Nowka-Keane Date: Mon, 7 Oct 2024 11:03:26 -0700 Subject: [PATCH] [CHERRY-PICK] BoardModulePkg: Added Mock library for BiosIdLib (#301) ## Description Added a gmock for GoogleTests that pull in BiosIdLib. Cherry picked from edk2_platforms [c53db4dc8bbc6cec6016792b9e08b1f0630498ae](https://github.com/tianocore/edk2-platforms/commit/c53db4dc8bbc6cec6016792b9e08b1f0630498ae) Amended to add newline in header file description. - [ ] Impacts functionality? - [ ] Impacts security? - [ ] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested Consumed mock in GoogleTest ## Integration Instructions N/A Signed-off-by: Vivian Nowka-Keane Co-authored-by: Bhavani Subramanian --- BoardModulePkg/BoardModulePkg.dec | 1 + .../Test/BoardModulePkgHostTest.dsc | 32 +++++++++++++++ .../GoogleTest/Library/MockBiosIdLib.h | 41 +++++++++++++++++++ .../MockBiosIdLib/MockBiosIdLib.cpp | 12 ++++++ .../MockBiosIdLib/MockBiosIdLib.inf | 33 +++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 BoardModulePkg/Test/BoardModulePkgHostTest.dsc create mode 100644 BoardModulePkg/Test/Mock/Include/GoogleTest/Library/MockBiosIdLib.h create mode 100644 BoardModulePkg/Test/Mock/Library/GoogleTest/MockBiosIdLib/MockBiosIdLib.cpp create mode 100644 BoardModulePkg/Test/Mock/Library/GoogleTest/MockBiosIdLib/MockBiosIdLib.inf diff --git a/BoardModulePkg/BoardModulePkg.dec b/BoardModulePkg/BoardModulePkg.dec index 0e557ee39b..c5284d3ef3 100644 --- a/BoardModulePkg/BoardModulePkg.dec +++ b/BoardModulePkg/BoardModulePkg.dec @@ -22,6 +22,7 @@ [Includes] Include + Test/Mock/Include [LibraryClasses] ## @libraryclass Provide services to access CMOS area. diff --git a/BoardModulePkg/Test/BoardModulePkgHostTest.dsc b/BoardModulePkg/Test/BoardModulePkgHostTest.dsc new file mode 100644 index 0000000000..569a3f237f --- /dev/null +++ b/BoardModulePkg/Test/BoardModulePkgHostTest.dsc @@ -0,0 +1,32 @@ +## @file BoardModulePkgHostTest.dsc +# +# BoardModulePkg DSC file used to build host-based unit tests. +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + PLATFORM_NAME = BoardModulePkgHostTest + PLATFORM_GUID = 67275336-A324-4F69-BD38-70A4C7898F06 + PLATFORM_VERSION = 0.1 + DSC_SPECIFICATION = 0x00010005 + OUTPUT_DIRECTORY = Build/BoardModulePkg/HostTest + SUPPORTED_ARCHITECTURES = IA32|X64 + BUILD_TARGETS = NOOPT + SKUID_IDENTIFIER = DEFAULT + +!include UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc + +[LibraryClasses] + +[Components] + # + # Build HOST_APPLICATIONs that test the BoardModulePkg + # + + # + # Build HOST_APPLICATION Libraries With GoogleTest + # + BoardModulePkg/Test/Mock/Library/GoogleTest/MockBiosIdLib/MockBiosIdLib.inf diff --git a/BoardModulePkg/Test/Mock/Include/GoogleTest/Library/MockBiosIdLib.h b/BoardModulePkg/Test/Mock/Include/GoogleTest/Library/MockBiosIdLib.h new file mode 100644 index 0000000000..728bbbe8cc --- /dev/null +++ b/BoardModulePkg/Test/Mock/Include/GoogleTest/Library/MockBiosIdLib.h @@ -0,0 +1,41 @@ +/** @file MockBiosIdLib.h + Google Test mocks for BiosIdLib + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MOCK_BIOS_ID_LIB_H_ +#define MOCK_BIOS_ID_LIB_H_ + +#include +#include +extern "C" { + #include + #include + #include +} + +struct MockBiosIdLib { + MOCK_INTERFACE_DECLARATION (MockBiosIdLib); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + GetBiosId, + ( + OUT BIOS_ID_IMAGE *BiosIdImage OPTIONAL + ) + ); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + GetBiosVersionDateTime, + ( + OUT CHAR16 *BiosVersion, OPTIONAL + OUT CHAR16 *BiosReleaseDate, OPTIONAL + OUT CHAR16 *BiosReleaseTime OPTIONAL + ) + ); +}; + +#endif diff --git a/BoardModulePkg/Test/Mock/Library/GoogleTest/MockBiosIdLib/MockBiosIdLib.cpp b/BoardModulePkg/Test/Mock/Library/GoogleTest/MockBiosIdLib/MockBiosIdLib.cpp new file mode 100644 index 0000000000..12a1c38163 --- /dev/null +++ b/BoardModulePkg/Test/Mock/Library/GoogleTest/MockBiosIdLib/MockBiosIdLib.cpp @@ -0,0 +1,12 @@ +/** @file MockBiosIdLib.cpp + Google Test mocks for BiosIdLib + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +MOCK_INTERFACE_DEFINITION (MockBiosIdLib); +MOCK_FUNCTION_DEFINITION (MockBiosIdLib, GetBiosId, 1, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockBiosIdLib, GetBiosVersionDateTime, 3, EFIAPI); diff --git a/BoardModulePkg/Test/Mock/Library/GoogleTest/MockBiosIdLib/MockBiosIdLib.inf b/BoardModulePkg/Test/Mock/Library/GoogleTest/MockBiosIdLib/MockBiosIdLib.inf new file mode 100644 index 0000000000..4d96f41f43 --- /dev/null +++ b/BoardModulePkg/Test/Mock/Library/GoogleTest/MockBiosIdLib/MockBiosIdLib.inf @@ -0,0 +1,33 @@ +## @file MockBiosIdLib.inf +# Google Test mock for BiosIdLib +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = MockBiosIdLib + FILE_GUID = FD03FA6D-7447-499C-B3AF-D89450F7739A + MODULE_TYPE = HOST_APPLICATION + VERSION_STRING = 1.0 + LIBRARY_CLASS = BiosIdLib + PI_SPECIFICATION_VERSION = 0x0001000A + +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + MockBiosIdLib.cpp + +[Packages] + MdePkg/MdePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + BoardModulePkg/BoardModulePkg.dec + +[LibraryClasses] + GoogleTestLib + +[BuildOptions] + MSFT:*_*_*_CC_FLAGS = /EHsc