From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.3300.1687163923870039416 for ; Mon, 19 Jun 2023 01:38:43 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=fzznPpuZ; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: lakx.huang@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687163923; x=1718699923; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=5ASrRlZDgeSVoj6mk+uf1eg7puC9prSWJk92GuXilTw=; b=fzznPpuZ8kPn44Yr2g6z+nq0JzsV3rv/wIfaLog+V6hC5gUkNGjVWiuv LkcIqdv3mTVR9q7aL7xVBF0uGmc7Ka2q05wc9KeRZBUk7TA34rtF2wzRB t4lTMnxG6eSo1gXiZU6DuoDrG5JFrBpkMRQ+g3m8c1evfFhZQlaqpwkss owblDX/XOIB84Dqf56f8wAsjWG38Hf6dy30x+maeiFQAZNQVmhx0bWXoG 0r/Rcjbze+cicdJDmT3VgM1UKWZDTMDln4lLnBPEbyFzP0O1/2wW8TpL9 qVb9Xp4OvV+2QqSsu6JKhn1PD9oba0BQReA7049WakonRtVmO+cZQB4i/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10745"; a="344326757" X-IronPort-AV: E=Sophos;i="6.00,254,1681196400"; d="scan'208";a="344326757" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2023 01:38:42 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10745"; a="747475849" X-IronPort-AV: E=Sophos;i="6.00,254,1681196400"; d="scan'208";a="747475849" Received: from lakhuanx-desk.gar.corp.intel.com ([10.227.107.14]) by orsmga001.jf.intel.com with ESMTP; 19 Jun 2023 01:38:41 -0700 From: lakx.huang@intel.com To: devel@edk2.groups.io Cc: lakx.huang@intel.com, Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [PATCH v1] MdePkg: Add UefiBootServicesTableLib gmock support Date: Mon, 19 Jun 2023 16:38:29 +0800 Message-Id: <20230619083829.743-1-lakx.huang@intel.com> X-Mailer: git-send-email 2.26.2.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: LakX Huang REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4485 Add Google Mock Library for UefiBootServicesTableLib Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: LakX Huang --- MdePkg/Test/MdePkgHostTest.dsc | 1 + .../Library/MockUefiBootServicesTableLib.h | 71 ++++++++++++++++++ .../MockUefiBootServicesTableLib.cpp | 75 +++++++++++++++++++ .../MockUefiBootServicesTableLib.inf | 33 ++++++++ 4 files changed, 180 insertions(+) create mode 100644 MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBoo= tServicesTableLib.h create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootService= sTableLib/MockUefiBootServicesTableLib.cpp create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootService= sTableLib/MockUefiBootServicesTableLib.inf diff --git a/MdePkg/Test/MdePkgHostTest.dsc b/MdePkg/Test/MdePkgHostTest.dsc index 529ea69024..872db61b2f 100644 --- a/MdePkg/Test/MdePkgHostTest.dsc +++ b/MdePkg/Test/MdePkgHostTest.dsc @@ -38,3 +38,4 @@ MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/Mock= UefiRuntimeServicesTableLib.inf=0D MdePkg/Test/Mock/Library/GoogleTest/MockPeiServicesLib/MockPeiServicesLi= b.inf=0D MdePkg/Test/Mock/Library/GoogleTest/MockHobLib/MockHobLib.inf=0D + MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUef= iBootServicesTableLib.inf \ No newline at end of file diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServic= esTableLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServ= icesTableLib.h new file mode 100644 index 0000000000..e36c6efdb9 --- /dev/null +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTable= Lib.h @@ -0,0 +1,71 @@ +/** @file=0D + Google Test mocks for UefiBootServicesTableLib=0D +=0D + Copyright (c) 2022, Intel Corporation. All rights reserved.=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#ifndef MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_=0D +#define MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_=0D +=0D +#include =0D +#include =0D +extern "C" {=0D +#include =0D +#include =0D +}=0D +=0D +struct MockUefiBootServicesTableLib {=0D + MOCK_INTERFACE_DECLARATION (MockUefiBootServicesTableLib);=0D +=0D + MOCK_FUNCTION_DECLARATION (=0D + EFI_STATUS,=0D + gBS_LocateProtocol,=0D + (IN EFI_GUID *Protocol,=0D + IN VOID *Registration OPTIONAL,=0D + OUT VOID **Interface)=0D + );=0D +=0D + MOCK_FUNCTION_DECLARATION (=0D + EFI_STATUS,=0D + gBS_LocateHandleBuffer,=0D + (IN EFI_LOCATE_SEARCH_TYPE SearchType,=0D + IN EFI_GUID *Protocol OPTIONAL,=0D + IN VOID *SearchKey OPTIONAL,=0D + OUT UINTN *NoHandles,=0D + OUT EFI_HANDLE **Buffer)=0D + );=0D +=0D + MOCK_FUNCTION_DECLARATION (=0D + EFI_STATUS,=0D + gBS_DisconnectController,=0D + (IN EFI_HANDLE ControllerHandle,=0D + IN EFI_HANDLE DriverImageHandle OPTIONAL,=0D + IN EFI_HANDLE ChildHandle OPTIONAL)=0D + );=0D +=0D + MOCK_FUNCTION_DECLARATION (=0D + EFI_STATUS,=0D + gBS_FreePool,=0D + (IN VOID *Buffer)=0D + );=0D + =0D + MOCK_FUNCTION_DECLARATION (=0D + EFI_STATUS,=0D + gBS_ConnectController,=0D + (IN EFI_HANDLE ControllerHandle,=0D + IN EFI_HANDLE *DriverImageHandle OPTIONAL,=0D + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,=0D + IN BOOLEAN Recursive)=0D + );=0D +=0D + MOCK_FUNCTION_DECLARATION (=0D + EFI_STATUS,=0D + gBS_HandleProtocol,=0D + (IN EFI_HANDLE Handle,=0D + IN EFI_GUID *Protocol,=0D + OUT VOID **Interface)=0D + );=0D +};=0D +=0D +#endif=0D diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableL= ib/MockUefiBootServicesTableLib.cpp b/MdePkg/Test/Mock/Library/GoogleTest/M= ockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp new file mode 100644 index 0000000000..79964d18f9 --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/Mock= UefiBootServicesTableLib.cpp @@ -0,0 +1,75 @@ +/** @file=0D + Google Test mocks for UefiBootServicesTableLib=0D +=0D + Copyright (c) 2022, Intel Corporation. All rights reserved.=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +#include =0D +=0D +MOCK_INTERFACE_DEFINITION(MockUefiBootServicesTableLib);=0D +=0D +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_LocateProtocol,= 3, EFIAPI);=0D +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_LocateHandleBuf= fer, 5, EFIAPI);=0D +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_DisconnectContr= oller, 3, EFIAPI);=0D +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_FreePool, 1, EF= IAPI);=0D +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_ConnectControll= er, 4, EFIAPI);=0D +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_HandleProtocol,= 3, EFIAPI);=0D +=0D +=0D +static EFI_BOOT_SERVICES localBs =3D {=0D + {=0D + (UINT64)NULL, // Signature=0D + 0, // Revision=0D + 0, // HeaderSize=0D + 0, // CRC32=0D + 0 // Reserved=0D + },=0D + NULL, // RaiseTPL=0D + NULL, // RestoreTPL=0D + NULL, // AllocatePages= =0D + NULL, // FreePages=0D + NULL, // GetMemoryMap= =0D + NULL, // AllocatePool= =0D + (EFI_FREE_POOL)gBS_FreePool, // FreePool=0D + NULL, // CreateEvent=0D + NULL, // SetTimer=0D + NULL, // WaitForEvent= =0D + NULL, // SignalEvent=0D + NULL, // CloseEvent=0D + NULL, // CheckEvent=0D + NULL, // InstallProtoc= olInterface=0D + NULL, // ReinstallProt= ocolInterface=0D + NULL, // UninstallProt= ocolInterface=0D + (EFI_HANDLE_PROTOCOL)gBS_HandleProtocol, // HandleProtoco= l=0D + (VOID *)NULL, // Reserved=0D + NULL, // RegisterProto= colNotify=0D + NULL, // LocateHandle= =0D + NULL, // LocateDeviceP= ath=0D + NULL, // InstallConfig= urationTable=0D + NULL, // LoadImage=0D + NULL, // StartImage=0D + NULL, // Exit=0D + NULL, // UnloadImage=0D + NULL, // ExitBootServi= ces=0D + NULL, // GetNextMonoto= nicCount=0D + NULL, // Stall=0D + NULL, // SetWatchdogTi= mer=0D + (EFI_CONNECT_CONTROLLER)gBS_ConnectController, // ConnectContro= ller=0D + (EFI_DISCONNECT_CONTROLLER)gBS_DisconnectController, // DisconnectCon= troller=0D + NULL, // OpenProtocol= =0D + NULL, // CloseProtocol= =0D + NULL, // OpenProtocolI= nformation=0D + NULL, // ProtocolsPerH= andle=0D + (EFI_LOCATE_HANDLE_BUFFER)gBS_LocateHandleBuffer, // LocateHandleB= uffer=0D + (EFI_LOCATE_PROTOCOL)gBS_LocateProtocol, // LocateProtoco= l=0D + NULL, // InstallMultip= leProtocolInterfaces=0D + NULL, // UninstallMult= ipleProtocolInterfaces=0D + NULL, // CalculateCrc3= 2=0D + NULL, // CopyMem=0D + NULL, // SetMem=0D + NULL // CreateEventEx= =0D +};=0D +=0D +extern "C" {=0D + EFI_BOOT_SERVICES* gBS =3D &localBs;=0D +} \ No newline at end of file diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableL= ib/MockUefiBootServicesTableLib.inf b/MdePkg/Test/Mock/Library/GoogleTest/M= ockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf new file mode 100644 index 0000000000..e8dcca8fb8 --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/Mock= UefiBootServicesTableLib.inf @@ -0,0 +1,33 @@ +## @file=0D +# Google Test mocks for UefiBootServicesTableLib=0D +#=0D +# Copyright (c) 2023, Intel Corporation. All rights reserved.=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D MockUefiBootServicesTableLib=0D + FILE_GUID =3D 9C6D2161-61B2-4094-BC8D-92F70C5E3C06= =0D + MODULE_TYPE =3D HOST_APPLICATION=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D MockUefiBootServicesTableLib=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64=0D +#=0D +=0D +[Sources]=0D + MockUefiBootServicesTableLib.cpp=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec=0D +=0D +[LibraryClasses]=0D + GoogleTestLib=0D +=0D +[BuildOptions]=0D + MSFT:*_*_*_CC_FLAGS =3D /EHsc=0D --=20 2.26.2.windows.1