From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from zrleap.intel-email.com (zrleap.intel-email.com [114.80.218.36]) by mx.groups.io with SMTP id smtpd.web10.148092.1680743753403911114 for ; Wed, 05 Apr 2023 18:15:53 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@byosoft.com.cn header.s=cloud-union header.b=TKm9WzJw; spf=pass (domain: byosoft.com.cn, ip: 114.80.218.36, mailfrom: gaoliming@byosoft.com.cn) Received: from zrleap.intel-email.com (localhost [127.0.0.1]) by zrleap.intel-email.com (Postfix) with ESMTP id 4E3FFA32E132 for ; Thu, 6 Apr 2023 09:15:51 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=byosoft.com.cn; s=cloud-union; t=1680743751; bh=6Qfkjp+bVg8GJ3CDhqmLaFnDxw2ad0Uwg5AWo0KUnZw=; h=From:To:Cc:References:In-Reply-To:Subject:Date; b=TKm9WzJwkJbI+le6ykbuiGZUY0in096KD6wqAz9M24vh9TsXmrmgGWWl1J4Oc6e+x 7yE7UEixzgmfUBi3b8r4SInJ4FGU06dtp6Gvfg/ny9x94tb529GKXGkbecg+PLH6yP dASi/VO1cZXkFklFdqpGN34XFWQf8kC2bGIvfg+I= Received: from localhost (localhost [127.0.0.1]) by zrleap.intel-email.com (Postfix) with ESMTP id 176B3A32E129 for ; Thu, 6 Apr 2023 09:15:51 +0800 (CST) Received: from zrleap.intel-email.com (localhost [127.0.0.1]) by zrleap.intel-email.com (Postfix) with ESMTP id 5F6A8A32E0FA for ; Thu, 6 Apr 2023 09:15:50 +0800 (CST) Authentication-Results: zrleap.intel-email.com; none Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by zrleap.intel-email.com (Postfix) with SMTP id E9DF0A32E0CA for ; Thu, 6 Apr 2023 09:15:47 +0800 (CST) Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Thu, 06 Apr 2023 09:15:44 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: "'Michael D Kinney'" , Cc: "'Chris Johnson'" , "'Zhiguang Liu'" References: <20230404182220.688-1-michael.d.kinney@intel.com> <20230404182220.688-6-michael.d.kinney@intel.com> In-Reply-To: <20230404182220.688-6-michael.d.kinney@intel.com> Subject: =?UTF-8?B?5Zue5aSNOiBbUGF0Y2ggdjIgMDUvMTJdIE1kZVBrZzogQWRkIGdtb2NrIGV4YW1wbGVz?= Date: Thu, 6 Apr 2023 09:15:47 +0800 Message-ID: <00f701d96825$519c3290$f4d497b0$@byosoft.com.cn> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQJx+ORxE/ZjgPnjvjNeU6bPsDMo0AHcCrvZrd14eDA= Sender: "gaoliming" Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn Acked-by: Liming Gao > -----=D3=CA=BC=FE=D4=AD=BC=FE----- > =B7=A2=BC=FE=C8=CB: Michael D Kinney > =B7=A2=CB=CD=CA=B1=BC=E4: 2023=C4=EA4=D4=C25=C8=D5 2:22 > =CA=D5=BC=FE=C8=CB: devel@edk2.groups.io > =B3=AD=CB=CD: Chris Johnson ; Liming Gao > ; Zhiguang Liu > =D6=F7=CC=E2: [Patch v2 05/12] MdePkg: Add gmock examples >=20 > From: Chris Johnson >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4389 >=20 > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu > Signed-off-by: Chris Johnson > --- > 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/MockUefiRuntimeServicesTa > bleLib.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 >=20 > diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec > index 2d643bede1d7..2a1d7694aa18 100644 > --- a/MdePkg/MdePkg.dec > +++ b/MdePkg/MdePkg.dec > @@ -26,6 +26,7 @@ [Defines] > [Includes] > Include > Test/UnitTest/Include > + Test/Mock/Include >=20 > [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/MockUefiRuntimeServices > TableLib.h > b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServices > TableLib.h > new file mode 100644 > index 000000000000..afdfc6b85597 > --- /dev/null > +++ > b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServices > TableLib.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 =3D 0x00010005 > + BASE_NAME =3D MockUefiLib > + FILE_GUID =3D > 47211F7A-6D90-4DFB-BDF9-610B69197C2E > + MODULE_TYPE =3D HOST_APPLICATION > + VERSION_STRING =3D 1.0 > + LIBRARY_CLASS =3D UefiLib > + > +# > +# The following information is for reference only and not required by = the > build tools. > +# > +# VALID_ARCHITECTURES =3D IA32 X64 > +# > + > +[Sources] > + MockUefiLib.cpp > + > +[Packages] > + MdePkg/MdePkg.dec > + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec > + > +[LibraryClasses] > + GoogleTestLib > + > +[BuildOptions] > + MSFT:*_*_*_CC_FLAGS =3D /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 =3D { > + {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 =3D &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 =3D 0x00010005 > + BASE_NAME =3D > MockUefiRuntimeServicesTableLib > + FILE_GUID =3D > 0A0E13C2-4176-4293-89C7-C2497AA31B92 > + MODULE_TYPE =3D HOST_APPLICATION > + VERSION_STRING =3D 1.0 > + LIBRARY_CLASS =3D UefiRuntimeServicesTableLib > + > +# > +# The following information is for reference only and not required by = the > build tools. > +# > +# VALID_ARCHITECTURES =3D IA32 X64 > +# > + > +[Sources] > + MockUefiRuntimeServicesTableLib.cpp > + > +[Packages] > + MdePkg/MdePkg.dec > + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec > + > +[LibraryClasses] > + GoogleTestLib > + > +[BuildOptions] > + MSFT:*_*_*_CC_FLAGS =3D /EHsc > -- > 2.39.1.windows.1