From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.2854.1680906059556530823 for ; Fri, 07 Apr 2023 15:21:02 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=PAakaTWy; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: michael.d.kinney@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680906062; x=1712442062; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Smx63j0mMomgQ7gIzpuvF67ZYSJMQFISr0vd+exOPGM=; b=PAakaTWyCwDiz3JPS4R5wM7PIqVSlzt8SNNlXxVOchiE+s1To3jIxwqG H1ZRJ45fI2RjMOEIYjx1eWiINyNtxaJPSpWZ3XBsd/p0qS4j4PUtVfU87 3C/YLsSgmxqr3s4aeQf6Fe3ICWw26hJFNqrJMfvHJt/vTx49izpI7c+a0 zdo3nVuqKgnk3JBGWlor+86aGn9Fl0BeDzufGb2FHILVuBKznDic2Lhiw G3CrcFCDSZFGqdUc5gfa31TI3MhGdkqJvmupZh90zvyVpxqVfs/RLLHt9 qR7pR1RXGEPVNPzGxFvH9rtjc35TT5pPe/dwUYr51Jh5pkzecBIv+PGxJ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085655" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085655" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2023 15:21:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177471" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177471" Received: from mdkinney-mobl2.amr.corp.intel.com ([10.209.18.108]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2023 15:21:01 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Chris Johnson , Liming Gao , Zhiguang Liu , Oliver Smith-Denny Subject: [Patch v3 05/12] MdePkg: Add gmock examples Date: Fri, 7 Apr 2023 15:20:43 -0700 Message-Id: <20230407222051.1095-6-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.39.1.windows.1 In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chris Johnson REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4389 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chris Johnson Acked-by: Liming Gao Reviewed-by: Oliver Smith-Denny Reviewed-by: Michael D Kinney --- MdePkg/MdePkg.dec | 1 + MdePkg/Test/MdePkgHostTest.dsc | 2 + .../Include/GoogleTest/Library/MockUefiLib.h | 39 +++++++++++++++++ .../Library/MockUefiRuntimeServicesTableLib.h | 42 +++++++++++++++++++ .../GoogleTest/MockUefiLib/MockUefiLib.cpp | 12 ++++++ .../GoogleTest/MockUefiLib/MockUefiLib.inf | 33 +++++++++++++++ .../MockUefiRuntimeServicesTableLib.cpp | 40 ++++++++++++++++++ .../MockUefiRuntimeServicesTableLib.inf | 33 +++++++++++++++ 8 files changed, 202 insertions(+) create mode 100644 MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiLib.h create mode 100644 MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServicesTableLib.h create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.cpp create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.cpp create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 5cf04bc0cb69..a46f28fff40a 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -27,6 +27,7 @@ [Defines] [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 b8b186dd8b17..35e3ef6d9729 100644 --- a/MdePkg/Test/MdePkgHostTest.dsc +++ b/MdePkg/Test/MdePkgHostTest.dsc @@ -34,3 +34,5 @@ [Components] # 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 000000000000..dec2c93e1b34 --- /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 +#include +extern "C" { +#include +#include +} + +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 000000000000..afdfc6b85597 --- /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 +#include +extern "C" { +#include +#include +} + +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 000000000000..5339d040c999 --- /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 + +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 000000000000..1a7461e44449 --- /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 000000000000..ecd1ba82366c --- /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 + +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 000000000000..7ba74d93bfc2 --- /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 -- 2.39.1.windows.1