From 91008b93cf5bd65c857a78459a749fefdf944fc2 Mon Sep 17 00:00:00 2001 From: v-bhavanisu <144935558+v-bhavanisu@users.noreply.github.com> Date: Wed, 27 Mar 2024 07:59:28 -0700 Subject: [PATCH] Added Mock GoogleTest folder for PolicyLibCommon (#780) Issue #867 cherry-pick from c8f98831a5 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). Added Mock GoogleTest folder for PolicyLibCommon 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, ... Added this mock lib definition and declaration to one of the library under Gen 11 and made sure local build is successful N/A --- PolicyServicePkg/PolicyServicePkg.dec | 1 + .../GoogleTest/Library/MockPolicyLibCommon.h | 33 +++++++++++++++++++ .../MockPolicyLibCommon.cpp | 11 +++++++ .../MockPolicyLibCommon.inf | 33 +++++++++++++++++++ .../Test/PolicyServicePkgHostTest.dsc | 4 +++ 5 files changed, 82 insertions(+) create mode 100644 PolicyServicePkg/Test/Mock/Include/GoogleTest/Library/MockPolicyLibCommon.h create mode 100644 PolicyServicePkg/Test/Mock/Library/GoogleTest/MockPolicyLibCommon/MockPolicyLibCommon.cpp create mode 100644 PolicyServicePkg/Test/Mock/Library/GoogleTest/MockPolicyLibCommon/MockPolicyLibCommon.inf diff --git a/PolicyServicePkg/PolicyServicePkg.dec b/PolicyServicePkg/PolicyServicePkg.dec index 883c9f77a71..cb1201561bd 100644 --- a/PolicyServicePkg/PolicyServicePkg.dec +++ b/PolicyServicePkg/PolicyServicePkg.dec @@ -14,6 +14,7 @@ [Includes] Include + Test/Mock/Include [LibraryClasses] PolicyLib|Include/Library/PolicyLib.h diff --git a/PolicyServicePkg/Test/Mock/Include/GoogleTest/Library/MockPolicyLibCommon.h b/PolicyServicePkg/Test/Mock/Include/GoogleTest/Library/MockPolicyLibCommon.h new file mode 100644 index 00000000000..127ae05465d --- /dev/null +++ b/PolicyServicePkg/Test/Mock/Include/GoogleTest/Library/MockPolicyLibCommon.h @@ -0,0 +1,33 @@ +/** @file + Google Test mocks for PolicyLibCommon + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MOCK_POLICY_LIB_COMMON_LIB_H_ +#define MOCK_POLICY_LIB_COMMON_LIB_H_ + +#include +#include +extern "C" { + #include + #include +} + +struct MockPolicyLibCommon { + MOCK_INTERFACE_DECLARATION (MockPolicyLibCommon); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + GetPolicy, + ( + IN CONST EFI_GUID *PolicyGuid, + OUT UINT64 *Attributes OPTIONAL, + OUT VOID *Policy, + IN OUT UINT16 *PolicySize + ) + ); +}; + +#endif diff --git a/PolicyServicePkg/Test/Mock/Library/GoogleTest/MockPolicyLibCommon/MockPolicyLibCommon.cpp b/PolicyServicePkg/Test/Mock/Library/GoogleTest/MockPolicyLibCommon/MockPolicyLibCommon.cpp new file mode 100644 index 00000000000..4ea6fce871f --- /dev/null +++ b/PolicyServicePkg/Test/Mock/Library/GoogleTest/MockPolicyLibCommon/MockPolicyLibCommon.cpp @@ -0,0 +1,11 @@ +/** @file + Google Test mocks for PolicyLibCommon + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +MOCK_INTERFACE_DEFINITION (MockPolicyLibCommon); +MOCK_FUNCTION_DEFINITION (MockPolicyLibCommon, GetPolicy, 4, EFIAPI); diff --git a/PolicyServicePkg/Test/Mock/Library/GoogleTest/MockPolicyLibCommon/MockPolicyLibCommon.inf b/PolicyServicePkg/Test/Mock/Library/GoogleTest/MockPolicyLibCommon/MockPolicyLibCommon.inf new file mode 100644 index 00000000000..1e498765f27 --- /dev/null +++ b/PolicyServicePkg/Test/Mock/Library/GoogleTest/MockPolicyLibCommon/MockPolicyLibCommon.inf @@ -0,0 +1,33 @@ +## @file +# Google Test mocks for PolicyLibCommon +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = MockPolicyLibCommon + FILE_GUID = 65E475F7-FD55-4008-A0E7-F63495C3C5DC + MODULE_TYPE = HOST_APPLICATION + VERSION_STRING = 1.0 + LIBRARY_CLASS = PolicyLib + PI_SPECIFICATION_VERSION = 0x0001000A + +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + MockPolicyLibCommon.cpp + +[Packages] + MdePkg/MdePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + PolicyServicePkg/PolicyServicePkg.dec + +[LibraryClasses] + GoogleTestLib + +[BuildOptions] + MSFT:*_*_*_CC_FLAGS = /EHsc diff --git a/PolicyServicePkg/Test/PolicyServicePkgHostTest.dsc b/PolicyServicePkg/Test/PolicyServicePkgHostTest.dsc index 05e6a9d4ede..8191e98b428 100644 --- a/PolicyServicePkg/Test/PolicyServicePkgHostTest.dsc +++ b/PolicyServicePkg/Test/PolicyServicePkgHostTest.dsc @@ -25,3 +25,7 @@ PolicyServicePkg/PolicyService/DxeMm/UnitTest/DxeMmPolicyUnitTest.inf PolicyServicePkg/PolicyService/Pei/UnitTest/PeiPolicyUnitTest.inf + # + # Build HOST_APPLICATION Libraries With GoogleTest + # + PolicyServicePkg/Test/Mock/Library/GoogleTest/MockPolicyLibCommon/MockPolicyLibCommon.inf