diff options
author | Chris Johnson <chris.n.johnson@intel.com> | 2023-03-24 16:10:22 -0700 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2023-04-10 05:59:02 +0000 |
commit | 09458c2b0bc531478337ceb37cb30a4b5d550c13 (patch) | |
tree | 05d74395b2f277631ad506b9e908226daa99e773 /MdePkg | |
parent | e4af282e9f60940105023d6988aa1688a107494e (diff) | |
download | edk2-09458c2b0bc531478337ceb37cb30a4b5d550c13.zip edk2-09458c2b0bc531478337ceb37cb30a4b5d550c13.tar.gz edk2-09458c2b0bc531478337ceb37cb30a4b5d550c13.tar.bz2 |
MdePkg: Add gmock examples
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4389
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Chris Johnson <chris.n.johnson@intel.com>
Acked-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Oliver Smith-Denny <osde@linux.microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Diffstat (limited to 'MdePkg')
8 files changed, 202 insertions, 0 deletions
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 5cf04bc..a46f28f 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -27,6 +27,7 @@ [Includes]
Include
Test/UnitTest/Include
+ Test/Mock/Include
[Includes.IA32]
Include/Ia32
diff --git a/MdePkg/Test/MdePkgHostTest.dsc b/MdePkg/Test/MdePkgHostTest.dsc index b8b186d..35e3ef6 100644 --- a/MdePkg/Test/MdePkgHostTest.dsc +++ b/MdePkg/Test/MdePkgHostTest.dsc @@ -34,3 +34,5 @@ # Build HOST_APPLICATION Libraries
#
MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
+ MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf
+ MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf
diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiLib.h new file mode 100644 index 0000000..dec2c93 --- /dev/null +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiLib.h @@ -0,0 +1,39 @@ +/** @file
+ Google Test mocks for UefiLib
+
+ Copyright (c) 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_UEFI_LIB_H_
+#define MOCK_UEFI_LIB_H_
+
+#include <Library/GoogleTestLib.h>
+#include <Library/FunctionMockLib.h>
+extern "C" {
+#include <Uefi.h>
+#include <Library/UefiLib.h>
+}
+
+struct MockUefiLib {
+ MOCK_INTERFACE_DECLARATION (MockUefiLib);
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ GetVariable2,
+ (IN CONST CHAR16 *Name,
+ IN CONST EFI_GUID *Guid,
+ OUT VOID **Value,
+ OUT UINTN *Size OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ GetEfiGlobalVariable2,
+ (IN CONST CHAR16 *Name,
+ OUT VOID **Value,
+ OUT UINTN *Size OPTIONAL)
+ );
+};
+
+#endif
diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServicesTableLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServicesTableLib.h new file mode 100644 index 0000000..afdfc6b --- /dev/null +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServicesTableLib.h @@ -0,0 +1,42 @@ +/** @file
+ Google Test mocks for UefiRuntimeServicesTableLib
+
+ Copyright (c) 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_UEFI_RUNTIME_SERVICES_TABLE_LIB_H_
+#define MOCK_UEFI_RUNTIME_SERVICES_TABLE_LIB_H_
+
+#include <Library/GoogleTestLib.h>
+#include <Library/FunctionMockLib.h>
+extern "C" {
+#include <Uefi.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+}
+
+struct MockUefiRuntimeServicesTableLib {
+ MOCK_INTERFACE_DECLARATION (MockUefiRuntimeServicesTableLib);
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ gRT_GetVariable,
+ (IN CHAR16 *VariableName,
+ IN EFI_GUID *VendorGuid,
+ OUT UINT32 *Attributes OPTIONAL,
+ IN OUT UINTN *DataSize,
+ OUT VOID *Data)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ gRT_SetVariable,
+ (IN CHAR16 *VariableName,
+ IN EFI_GUID *VendorGuid,
+ IN UINT32 Attributes,
+ IN UINTN DataSize,
+ IN VOID *Data)
+ );
+};
+
+#endif
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.cpp b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.cpp new file mode 100644 index 0000000..5339d04 --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.cpp @@ -0,0 +1,12 @@ +/** @file
+ Google Test mocks for UefiLib
+
+ Copyright (c) 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include <GoogleTest/Library/MockUefiLib.h>
+
+MOCK_INTERFACE_DEFINITION(MockUefiLib);
+
+MOCK_FUNCTION_DEFINITION(MockUefiLib, GetVariable2, 4, EFIAPI);
+MOCK_FUNCTION_DEFINITION(MockUefiLib, GetEfiGlobalVariable2, 3, EFIAPI);
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf new file mode 100644 index 0000000..1a7461e --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf @@ -0,0 +1,33 @@ +## @file
+# Google Test mocks for UefiLib
+#
+# Copyright (c) 2022, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = MockUefiLib
+ FILE_GUID = 47211F7A-6D90-4DFB-BDF9-610B69197C2E
+ MODULE_TYPE = HOST_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = UefiLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ MockUefiLib.cpp
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ GoogleTestLib
+
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /EHsc
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.cpp b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.cpp new file mode 100644 index 0000000..ecd1ba8 --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.cpp @@ -0,0 +1,40 @@ +/** @file
+ Google Test mocks for UefiRuntimeServicesTableLib
+
+ Copyright (c) 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include <GoogleTest/Library/MockUefiRuntimeServicesTableLib.h>
+
+MOCK_INTERFACE_DEFINITION(MockUefiRuntimeServicesTableLib);
+
+MOCK_FUNCTION_DEFINITION(MockUefiRuntimeServicesTableLib, gRT_GetVariable, 5, EFIAPI);
+MOCK_FUNCTION_DEFINITION(MockUefiRuntimeServicesTableLib, gRT_SetVariable, 5, EFIAPI);
+
+static EFI_RUNTIME_SERVICES localRt = {
+ {0}, // EFI_TABLE_HEADER
+
+ NULL, // EFI_GET_TIME
+ NULL, // EFI_SET_TIME
+ NULL, // EFI_GET_WAKEUP_TIME
+ NULL, // EFI_SET_WAKEUP_TIME
+
+ NULL, // EFI_SET_VIRTUAL_ADDRESS_MAP
+ NULL, // EFI_CONVERT_POINTER
+
+ gRT_GetVariable, // EFI_GET_VARIABLE
+ NULL, // EFI_GET_NEXT_VARIABLE_NAME
+ gRT_SetVariable, // EFI_SET_VARIABLE
+
+ NULL, // EFI_GET_NEXT_HIGH_MONO_COUNT
+ NULL, // EFI_RESET_SYSTEM
+
+ NULL, // EFI_UPDATE_CAPSULE
+ NULL, // EFI_QUERY_CAPSULE_CAPABILITIES
+
+ NULL, // EFI_QUERY_VARIABLE_INFO
+};
+
+extern "C" {
+ EFI_RUNTIME_SERVICES* gRT = &localRt;
+}
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf new file mode 100644 index 0000000..7ba74d9 --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf @@ -0,0 +1,33 @@ +## @file
+# Google Test mocks for UefiRuntimeServicesTableLib
+#
+# Copyright (c) 2022, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = MockUefiRuntimeServicesTableLib
+ FILE_GUID = 0A0E13C2-4176-4293-89C7-C2497AA31B92
+ MODULE_TYPE = HOST_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = UefiRuntimeServicesTableLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ MockUefiRuntimeServicesTableLib.cpp
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ GoogleTestLib
+
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /EHsc
|