From nobody Thu May 16 09:01:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106195+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106195+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687251962; cv=none; d=zohomail.com; s=zohoarc; b=CuEh+QXPS5IQnfA++HD2C14pBrZXGN/Te72dZ0aaWOmxEOQmh66nltxJcCOI2U4iLkTXyrAifFk0hTpMiG9fDp2YyG/O5CGTbFDjnJzCXP1TvA4ww0AFay9eukqq2fDYkJHyMCoIwThWqwNgmKn23iwwn0Furz7/Dv2Cne3vb68= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687251962; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=oVI/zrn1m9Asgng6J1B6lrVLP9Tf0/qXzBo8gp4lfU0=; b=MLmnau9gnIimnZVob1yUyqiHo1NbnIysARRRvYw4qQ70CYQd9unjquYwf0bDKwG6R3k9g/uIFjfe7PjALUlXYnqrVJRsHb+PW+yCJizpPh6ADeNz/p3uue+HpFUiPN9+QaFUU9U0oPYpBn8IikG7B4anOKQ/UmwhgS8FLXB69zI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106195+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1687251962396536.9967629920402; Tue, 20 Jun 2023 02:06:02 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7z64YY1788612x8vVlwlxBt1; Tue, 20 Jun 2023 02:06:02 -0700 X-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 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" X-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" X-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: [edk2-devel] [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> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lakx.huang@intel.com X-Gm-Message-State: HfZU0xtHjsJYMlBCvU5eLPVAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687251962; bh=1vnJSVD1fahLjzM9hB9Vf2PgKkGvdLy2kNaC17jkMQA=; h=Cc:Date:From:Reply-To:Subject:To; b=SMkBoFC1TMOQFvirKzmbbReEtvDEN7VefcO7aYcalM5I/yavNqBYvKtkmeghTd/2h6S dydl3WoPXmUTOJHcSzyCVFWrr0tqWqqPxYjcOC/fWHIgsho4++SUoMWmFLyFtVJiX5Srk XGZ83V6GYpipqLU+0JWlGo3gWqnUFbFwCYM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687251964658100035 Content-Type: text/plain; charset="utf-8" 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 MdePkg/Test/Mock/Library/GoogleTest/MockPeiServicesLib/MockPeiServicesLi= b.inf MdePkg/Test/Mock/Library/GoogleTest/MockHobLib/MockHobLib.inf + 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 + Google Test mocks for UefiBootServicesTableLib + + Copyright (c) 2022, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_ +#define MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_ + +#include +#include +extern "C" { +#include +#include +} + +struct MockUefiBootServicesTableLib { + MOCK_INTERFACE_DECLARATION (MockUefiBootServicesTableLib); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + gBS_LocateProtocol, + (IN EFI_GUID *Protocol, + IN VOID *Registration OPTIONAL, + OUT VOID **Interface) + ); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + gBS_LocateHandleBuffer, + (IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol OPTIONAL, + IN VOID *SearchKey OPTIONAL, + OUT UINTN *NoHandles, + OUT EFI_HANDLE **Buffer) + ); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + gBS_DisconnectController, + (IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE DriverImageHandle OPTIONAL, + IN EFI_HANDLE ChildHandle OPTIONAL) + ); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + gBS_FreePool, + (IN VOID *Buffer) + ); + =20 + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + gBS_ConnectController, + (IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE *DriverImageHandle OPTIONAL, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL, + IN BOOLEAN Recursive) + ); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + gBS_HandleProtocol, + (IN EFI_HANDLE Handle, + IN EFI_GUID *Protocol, + OUT VOID **Interface) + ); +}; + +#endif 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 + Google Test mocks for UefiBootServicesTableLib + + Copyright (c) 2022, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +#include + +MOCK_INTERFACE_DEFINITION(MockUefiBootServicesTableLib); + +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_LocateProtocol,= 3, EFIAPI); +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_LocateHandleBuf= fer, 5, EFIAPI); +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_DisconnectContr= oller, 3, EFIAPI); +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_FreePool, 1, EF= IAPI); +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_ConnectControll= er, 4, EFIAPI); +MOCK_FUNCTION_DEFINITION(MockUefiBootServicesTableLib, gBS_HandleProtocol,= 3, EFIAPI); + + +static EFI_BOOT_SERVICES localBs =3D { + { + (UINT64)NULL, // Signature + 0, // Revision + 0, // HeaderSize + 0, // CRC32 + 0 // Reserved + }, + NULL, // RaiseTPL + NULL, // RestoreTPL + NULL, // AllocatePages + NULL, // FreePages + NULL, // GetMemoryMap + NULL, // AllocatePool + (EFI_FREE_POOL)gBS_FreePool, // FreePool + NULL, // CreateEvent + NULL, // SetTimer + NULL, // WaitForEvent + NULL, // SignalEvent + NULL, // CloseEvent + NULL, // CheckEvent + NULL, // InstallProtoc= olInterface + NULL, // ReinstallProt= ocolInterface + NULL, // UninstallProt= ocolInterface + (EFI_HANDLE_PROTOCOL)gBS_HandleProtocol, // HandleProtocol + (VOID *)NULL, // Reserved + NULL, // RegisterProto= colNotify + NULL, // LocateHandle + NULL, // LocateDeviceP= ath + NULL, // InstallConfig= urationTable + NULL, // LoadImage + NULL, // StartImage + NULL, // Exit + NULL, // UnloadImage + NULL, // ExitBootServi= ces + NULL, // GetNextMonoto= nicCount + NULL, // Stall + NULL, // SetWatchdogTi= mer + (EFI_CONNECT_CONTROLLER)gBS_ConnectController, // ConnectContro= ller + (EFI_DISCONNECT_CONTROLLER)gBS_DisconnectController, // DisconnectCon= troller + NULL, // OpenProtocol + NULL, // CloseProtocol + NULL, // OpenProtocolI= nformation + NULL, // ProtocolsPerH= andle + (EFI_LOCATE_HANDLE_BUFFER)gBS_LocateHandleBuffer, // LocateHandleB= uffer + (EFI_LOCATE_PROTOCOL)gBS_LocateProtocol, // LocateProtocol + NULL, // InstallMultip= leProtocolInterfaces + NULL, // UninstallMult= ipleProtocolInterfaces + NULL, // CalculateCrc32 + NULL, // CopyMem + NULL, // SetMem + NULL // CreateEventEx +}; + +extern "C" { + EFI_BOOT_SERVICES* gBS =3D &localBs; +} \ 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 +# Google Test mocks for UefiBootServicesTableLib +# +# Copyright (c) 2023, Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D MockUefiBootServicesTableLib + FILE_GUID =3D 9C6D2161-61B2-4094-BC8D-92F70C5E3C06 + MODULE_TYPE =3D HOST_APPLICATION + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D MockUefiBootServicesTableLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + MockUefiBootServicesTableLib.cpp + +[Packages] + MdePkg/MdePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + GoogleTestLib + +[BuildOptions] + MSFT:*_*_*_CC_FLAGS =3D /EHsc --=20 2.26.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106195): https://edk2.groups.io/g/devel/message/106195 Mute This Topic: https://groups.io/mt/99640663/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-