From nobody Thu May 2 23:04:55 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+102725+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+102725+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906060; cv=none; d=zohomail.com; s=zohoarc; b=BBCzerwkZ6YCLsbnAT87azOd+aYoOIg43z2/e0pZkLmVqyUudTJzdKBi+UcV1KNra2Ryc+zcWvL1uCWR2qoV0bHYqlz0fWLAHgtlcPPZqX/gibLvFbmUuKKnyZNuZE8kQ0hHPxDh1Ppl58h/Vv55iYh4D/cmQlkdSrWIJ3xubUY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906060; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=SqDvk7jmsp4578HhHF3E2/gAl632UkZQzyfVZzvsDoA=; b=G4FGBo7tbS/Jh1oFXmGXP6eNrgjq8E1nUdAwYEdQuuyWwwEhqmrOVg5gjtH0uD2gePnJ8wQFyKENWBFsxPG8XR3kUDGMhExkRKZA8esN4f9JcwDj2zgH1+UwtdmC6J0pOGCR/W/vQylYEuOjV5WeFAxXHM69S4rOSTa0Lj7Ddcc= 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+102725+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 1680906060819414.41237021579263; Fri, 7 Apr 2023 15:21:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id O1icYY1788612xOu91zjePJ7; Fri, 07 Apr 2023 15:21:00 -0700 X-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:20:59 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085636" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085636" X-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:20:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177458" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177458" X-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:20:59 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Chris Johnson , Andrew Fish , Leif Lindholm , Michael Kubacki , Sean Brogan , Michael Kubacki , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 01/12] UnitTestFrameworkPkg: Add subhook submodule required for gmock Date: Fri, 7 Apr 2023 15:20:39 -0700 Message-Id: <20230407222051.1095-2-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: AjlnF7xPwxaYxjT4AxVrj6mPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906060; bh=zVLLVn4WgAegnCatqDTByGj+b6B67UPKui4HTPYxjAo=; h=Cc:Date:From:Reply-To:Subject:To; b=xXDgVfzZ951Nnc1+MuFZjqtop42vot6yBcAr3JdwoacipgGgLCooTA2KA67oc9hn2zG zUGhiFx3bR9bOVyVrz7+YUDBEEDmD3eFC4dKYX7oXPBZKYPkb4izg/u03IB1Foe0NWyaT tqtav/wak6hvfOEmrSc2Oq7bvufQQTHFVpA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906062001100003 Content-Type: text/plain; charset="utf-8" From: Chris Johnson REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4389 Add subhook submodule that is required to hook internal functions when using gmock. https://github.com/Zeex/subhook Add SubhookLib library class and SubhookLib library instance. Include the SUBHOOK_STATIC define in the SubhookLib INF file so it builds as a static library. Also include the SUBHOOK_STATIC define in SubhookLib.h so all modules using SubhookLib properly link SubhookLib as a static library. Cc: Andrew Fish Cc: Leif Lindholm Cc: Michael D Kinney Cc: Michael Kubacki Cc: Sean Brogan Signed-off-by: Chris Johnson Reviewed-by: Leif Lindholm Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny Reviewed-by: Michael D Kinney --- .gitmodules | 3 ++ ReadMe.rst | 1 + .../Include/Library/SubhookLib.h | 15 +++++++++ .../Library/SubhookLib/SubhookLib.inf | 31 +++++++++++++++++++ .../Library/SubhookLib/SubhookLib.uni | 11 +++++++ .../Library/SubhookLib/subhook | 1 + .../Test/UnitTestFrameworkPkgHostTest.dsc | 1 + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec | 2 ++ .../UnitTestFrameworkPkgHost.dsc.inc | 1 + 9 files changed, 66 insertions(+) create mode 100644 UnitTestFrameworkPkg/Include/Library/SubhookLib.h create mode 100644 UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf create mode 100644 UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.uni create mode 160000 UnitTestFrameworkPkg/Library/SubhookLib/subhook diff --git a/.gitmodules b/.gitmodules index 8011a88d9d25..fe8a43be93ba 100644 --- a/.gitmodules +++ b/.gitmodules @@ -23,3 +23,6 @@ [submodule "UnitTestFrameworkPkg/Library/GoogleTestLib/googletest"] path =3D UnitTestFrameworkPkg/Library/GoogleTestLib/googletest url =3D https://github.com/google/googletest.git +[submodule "UnitTestFrameworkPkg/Library/SubhookLib/subhook"] + path =3D UnitTestFrameworkPkg/Library/SubhookLib/subhook + url =3D https://github.com/Zeex/subhook.git diff --git a/ReadMe.rst b/ReadMe.rst index 497d96355908..91b9cf3c5e50 100644 --- a/ReadMe.rst +++ b/ReadMe.rst @@ -94,6 +94,7 @@ that are covered by additional licenses. - `MdeModulePkg/Universal/RegularExpressionDxe/oniguruma `__ - `UnitTestFrameworkPkg/Library/CmockaLib/cmocka `__ - `UnitTestFrameworkPkg/Library/GoogleTestLib/googletest `__ +- `UnitTestFrameworkPkg/Library/SubhookLib/subhook `__ - `RedfishPkg/Library/JsonLib/jansson `__ =20 The EDK II Project is composed of packages. The maintainers for each packa= ge diff --git a/UnitTestFrameworkPkg/Include/Library/SubhookLib.h b/UnitTestFr= ameworkPkg/Include/Library/SubhookLib.h new file mode 100644 index 000000000000..46783adfccfb --- /dev/null +++ b/UnitTestFrameworkPkg/Include/Library/SubhookLib.h @@ -0,0 +1,15 @@ +/** @file + SubhookLib class with APIs from the subhook project + + Copyright (c) 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SUBHOOK_LIB_H_ +#define SUBHOOK_LIB_H_ + +#define SUBHOOK_STATIC +#include + +#endif diff --git a/UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf b/UnitT= estFrameworkPkg/Library/SubhookLib/SubhookLib.inf new file mode 100644 index 000000000000..a67be890d8cd --- /dev/null +++ b/UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf @@ -0,0 +1,31 @@ +## @file +# This module provides Subhook Library implementation. +# +# Copyright (c) 2022, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010018 + BASE_NAME =3D SubhookLib + MODULE_UNI_FILE =3D SubhookLib.uni + FILE_GUID =3D 70E03378-E140-46A8-8E65-7719DA14A240 + MODULE_TYPE =3D HOST_APPLICATION + VERSION_STRING =3D 0.1 + LIBRARY_CLASS =3D SubhookLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + subhook/subhook.c + +[Packages] + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[BuildOptions] + MSFT:*_*_*_CC_FLAGS =3D=3D /c /EHsc /Zi /DSUBHOOK_STATIC /Od + GCC:*_*_IA32_CC_FLAGS =3D=3D -g -c -O0 -m32 + GCC:*_*_X64_CC_FLAGS =3D=3D -g -c -O0 -m64 diff --git a/UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.uni b/UnitT= estFrameworkPkg/Library/SubhookLib/SubhookLib.uni new file mode 100644 index 000000000000..eb61f034047e --- /dev/null +++ b/UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.uni @@ -0,0 +1,11 @@ +// /** @file +// This module provides Subhook Library implementation. +// +// Copyright (c) 2022, Intel Corporation. All rights reserved.
+// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Subhook Library i= mplementation" + +#string STR_MODULE_DESCRIPTION #language en-US "This module provi= des Subhook Library implementation." diff --git a/UnitTestFrameworkPkg/Library/SubhookLib/subhook b/UnitTestFram= eworkPkg/Library/SubhookLib/subhook new file mode 160000 index 000000000000..83d4e1ebef35 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/SubhookLib/subhook @@ -0,0 +1 @@ +Subproject commit 83d4e1ebef3588fae48b69a7352cc21801cb70bc diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc b/U= nitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc index 708ef7f9ab35..722509c8f26f 100644 --- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc +++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc @@ -33,6 +33,7 @@ [Components] # UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf + UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAlloca= tionLibPosix.inf UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec b/UnitTestFramew= orkPkg/UnitTestFrameworkPkg.dec index 14e387d63a0f..30b489915d4a 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec @@ -20,6 +20,7 @@ [Includes] Library/CmockaLib/cmocka/include Library/GoogleTestLib/googletest/googletest/include Library/GoogleTestLib/googletest/googlemock/include + Library/SubhookLib/subhook =20 [Includes.Common.Private] PrivateInclude @@ -34,6 +35,7 @@ [LibraryClasses] ## @libraryclass GoogleTest infrastructure # GoogleTestLib|Include/Library/GoogleTestLib.h + SubhookLib|Include/Library/SubhookLib.h =20 [LibraryClasses.Common.Private] ## @libraryclass Provides a unit test result report diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTe= stFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index 7f5dfa30ed60..e77897bd326f 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -15,6 +15,7 @@ [LibraryClasses.common.HOST_APPLICATION] CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLibNull/BaseCache= MaintenanceLibNull.inf CmockaLib|UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf GoogleTestLib|UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.i= nf + SubhookLib|UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.i= nf DebugLib|UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.= inf MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationL= ibPosix/MemoryAllocationLibPosix.inf --=20 2.39.1.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 (#102725): https://edk2.groups.io/g/devel/message/102725 Mute This Topic: https://groups.io/mt/98134490/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102726+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+102726+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906061; cv=none; d=zohomail.com; s=zohoarc; b=OheW3wmqLHAAy0vB/M/3JUMTnG2kZySS50pbYGef/0mIlW7tqnFE4nSStGkZQ7Jgu+dTmT0ANjtWCCEl2JgdB5z1kgLTj6VaLEBDltcUbGNsGRhBmVvpAWk0nw6YeDJ23kal2q2cdcrNDw3sM/1eRiCRJs2KFCGjevEhyMzHsKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906061; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=x2SQ1Zdhsnm1k+X9/hPQ+bK3RUOOMrtkjeL7Cl8EqD8=; b=auW2JgNrldUI5Ipcvb+QvSRqc31rVorfPeK4VSnuiRHZGBRV3X+DqenisphY5HALZ88IqdnPz8d53dzFFWrG7FyEW6kTY8YvNbZ9xTf8B5zCsMMPOsqM+Jd2yGVVnAwN4upGM1lKm3jvGq8j3llLlpOfxr9OPjSvzQ7tNSYkH3Q= 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+102726+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 1680906061567450.9470690350421; Fri, 7 Apr 2023 15:21:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Tp4QYY1788612xHIvRo8cInG; Fri, 07 Apr 2023 15:21:01 -0700 X-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:00 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085642" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085642" X-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:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177462" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177462" X-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:20:59 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Chris Johnson , Sean Brogan , Michael Kubacki , Liming Gao , Leif Lindholm , Michael Kubacki , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 02/12] .pytool/CISettings.py: Add subhook submodule Date: Fri, 7 Apr 2023 15:20:40 -0700 Message-Id: <20230407222051.1095-3-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: WaEwwPaLTp93DKoY1J3eEgAIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906061; bh=lPHcPSOpcz+uGfSabZURtkRzTwDAqpkruSZRlnkYWPA=; h=Cc:Date:From:Reply-To:Subject:To; b=Aepo5xiTp5RTY/yu3A4W+o1MoUIEL6WLerZrEA5tB/+XE4Gzo/wLSwfDR/eNrTL0hrm ke5l9AAXWjfOR62lWAGgwyNFQrVmMpx3wP25dHjIqHzHrCKVls4LaAP+i43itE7t3VJl9 XJfswDmSl7obrjuG/cwqlAU52lvlf0Xk2+8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906063265100011 Content-Type: text/plain; charset="utf-8" From: Chris Johnson REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4389 Add submodule for https://github.com/Zeex/subhook This submodule is required to hook internal functions when using gmock. Cc: Sean Brogan Cc: Michael Kubacki Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Chris Johnson Reviewed-by: Leif Lindholm Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny Reviewed-by: Michael D Kinney --- .pytool/CISettings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pytool/CISettings.py b/.pytool/CISettings.py index d87c8e838e61..e3f44add5834 100644 --- a/.pytool/CISettings.py +++ b/.pytool/CISettings.py @@ -193,6 +193,8 @@ class Settings(CiBuildSettingsManager, UpdateSettingsMa= nager, SetupSettingsManag "BaseTools/Source/C/BrotliCompress/brotli", False)) rs.append(RequiredSubmodule( "RedfishPkg/Library/JsonLib/jansson", False)) + rs.append(RequiredSubmodule( + "UnitTestFrameworkPkg/Library/SubhookLib/subhook", False)) return rs =20 def GetName(self): --=20 2.39.1.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 (#102726): https://edk2.groups.io/g/devel/message/102726 Mute This Topic: https://groups.io/mt/98134491/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102727+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+102727+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906062; cv=none; d=zohomail.com; s=zohoarc; b=iAZiwn45oG5ebfB8TVsUe1fPT48cmovJhkK8J59HTX4Elq2XHRgByfy1l/1oan7l02XU/2MiBIzjHERWmf1jkeOd6Ezy/URf3y9Z0T+38bn3ShgZgp0BjxhzmdfzUmotPwmI6t79yhZjwjiLc3bx795GeC40sxVNRPxFA3CwT5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906062; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=xrUriOTsrcSFZqGjaRRQQrJ5BwyKy7aFCah42gjLb9k=; b=PC0bVLDNKXSf4Zv5U+HqSi7UlCEEd3u0LJlO8hzijsyOgB7rZ6FhYcSA7Vn7Qt7iSpA6JVsegA0Ayulm7W3e5zDyQ/vsVpfokWqck/25bTpnzg25bOd6PeLXmLbiqzRe8iNl0ghwv9NjEqao/P9XRfxPrNwl9xvmg0imuyNA2Nc= 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+102727+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 1680906062323184.50928113704606; Fri, 7 Apr 2023 15:21:02 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id iaf5YY1788612x1EPw8Oem2H; Fri, 07 Apr 2023 15:21:01 -0700 X-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:01 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085646" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085646" X-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:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177465" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177465" X-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:00 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Chris Johnson , Sean Brogan , Michael Kubacki , Michael Kubacki , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 03/12] UnitTestFrameworkPkg: Add gmock support to GoogleTestLib Date: Fri, 7 Apr 2023 15:20:41 -0700 Message-Id: <20230407222051.1095-4-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: pYEuT4B4v2giy5JQQKjx8tOtx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906061; bh=Wq5WhbnDzfwJyEanMOKzrioNWizXXNmLHH1pyU+C5oo=; h=Cc:Date:From:Reply-To:Subject:To; b=GXXiM9NziKTXJ84oG6MmL8I2LB9uh3kXR0bBFmYy4nVDy06oMWBKSyZQ0m50D+gcj8V oZybG3AmikfdDVuM8Xle1jAJ5z309iDeNxqvBBdMIeTecDN5nJWr9o3lxyBBhqygBoZwQ ZqUf1gQKjzhHS14nWjT3xeBBRzxa9qvmYqs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906063445100015 Content-Type: text/plain; charset="utf-8" From: Chris Johnson REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4389 * Add gmock support to GoogleTestLib * Add FunctionMockLib library class and library instance * Add GoogleTest extension to GoogleTestLib.h for CHAR16 type * Add GoogleTest extension to GoogleTestLib.h for buffer types * HOST_APPLICATION only supports IA32/X64 Cc: Sean Brogan Cc: Michael Kubacki Cc: Michael D Kinney Signed-off-by: Chris Johnson Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny Reviewed-by: Michael D Kinney --- .../Include/Library/FunctionMockLib.h | 131 ++++++++++++++++++ .../Include/Library/GoogleTestLib.h | 96 +++++++++++++ .../Library/CmockaLib/CmockaLib.inf | 2 +- .../Library/FunctionMockLib/FunctionMockLib.c | 7 + .../FunctionMockLib/FunctionMockLib.inf | 31 +++++ .../FunctionMockLib/FunctionMockLib.uni | 11 ++ .../Library/GoogleTestLib/GoogleTestLib.inf | 21 ++- .../Library/GoogleTestLib/GoogleTestLib.uni | 3 - .../Test/UnitTestFrameworkPkgHostTest.dsc | 3 +- .../UnitTestFrameworkPkg.ci.yaml | 7 +- UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec | 2 + .../UnitTestFrameworkPkgHost.dsc.inc | 1 + 12 files changed, 297 insertions(+), 18 deletions(-) create mode 100644 UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h create mode 100644 UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMo= ckLib.c create mode 100644 UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMo= ckLib.inf create mode 100644 UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMo= ckLib.uni diff --git a/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h b/UnitT= estFrameworkPkg/Include/Library/FunctionMockLib.h new file mode 100644 index 000000000000..bf7a7066560a --- /dev/null +++ b/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h @@ -0,0 +1,131 @@ +/** @file + This header allows the mocking of free (C style) functions using gmock. + + Copyright (c) 2023, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef FUNCTION_MOCK_LIB_H_ +#define FUNCTION_MOCK_LIB_H_ + +#include +#include +#include + +//////////////////////////////////////////////////////////////////////////= //// +// The below macros are the public function mock interface that are intend= ed +// to be used outside this file. + +#define MOCK_INTERFACE_DECLARATION(MOCK) \ + static MOCK * Instance; \ + MOCK (); \ + ~MOCK (); + +#define MOCK_INTERFACE_DEFINITION(MOCK) \ + MOCK_STATIC_INSTANCE_DEFINITION (MOCK) \ + MOCK_INTERFACE_CONSTRUCTOR (MOCK) \ + MOCK_INTERFACE_DECONSTRUCTOR (MOCK) + +// Mock function declaration for external functions (i.e. functions to +// mock that do not exist in the compilation unit). +#define MOCK_FUNCTION_DECLARATION(RET_TYPE, FUNC, ARGS) \ + MOCK_FUNCTION_TYPE_DEFINITIONS(RET_TYPE, FUNC, ARGS) \ + MOCK_METHOD (RET_TYPE, FUNC, ARGS); + +// Mock function definition for external functions (i.e. functions to +// mock that do not exist in the compilation unit). +#define MOCK_FUNCTION_DEFINITION(MOCK, FUNC, NUM_ARGS, CALL_TYPE) \ + FUNCTION_DEFINITION_TO_CALL_MOCK(MOCK, FUNC, FUNC, NUM_ARGS, CALL_TYPE) + +// Mock function declaration for internal functions (i.e. functions to +// mock that already exist in the compilation unit). +#define MOCK_FUNCTION_INTERNAL_DECLARATION(RET_TYPE, FUNC, ARGS) \ + MOCK_FUNCTION_DECLARATION(RET_TYPE, FUNC, ARGS) \ + MOCK_FUNCTION_HOOK_DECLARATIONS(FUNC) + +// Mock function definition for internal functions (i.e. functions to +// mock that already exist in the compilation unit). This definition also +// implements MOCK_FUNC() which is later hooked as FUNC(). +#define MOCK_FUNCTION_INTERNAL_DEFINITION(MOCK, FUNC, NUM_ARGS, CALL_TYPE)= \ + FUNCTION_DEFINITION_TO_CALL_MOCK(MOCK, FUNC, MOCK##_##FUNC, NUM_ARGS, CA= LL_TYPE) \ + MOCK_FUNCTION_HOOK_DEFINITIONS(MOCK, FUNC) + +//////////////////////////////////////////////////////////////////////////= //// +// The below macros are private and should not be used outside this file. + +#define MOCK_FUNCTION_HOOK_DECLARATIONS(FUNC) \ + static subhook::Hook Hook##FUNC; \ + struct MockContainer_##FUNC { \ + MockContainer_##FUNC (); \ + ~MockContainer_##FUNC (); \ + }; \ + MockContainer_##FUNC MockContainerInst_##FUNC; + +// This definition implements a constructor and destructor inside a nested +// class to enable automatic installation of the hooks to the associated +// MOCK_FUNC() when the mock object is instantiated in scope and automatic +// removal when the instantiated mock object goes out of scope. +#define MOCK_FUNCTION_HOOK_DEFINITIONS(MOCK, FUNC) \ + subhook :: Hook MOCK :: Hook##FUNC; \ + MOCK :: MockContainer_##FUNC :: MockContainer_##FUNC () { \ + if (MOCK :: Instance =3D=3D NULL) = \ + MOCK :: Hook##FUNC .Install( \ + (FUNC##_ret_type *) ::FUNC, \ + (FUNC##_ret_type *) MOCK##_##FUNC); \ + } \ + MOCK :: MockContainer_##FUNC :: ~MockContainer_##FUNC () { \ + MOCK :: Hook##FUNC .Remove(); \ + } \ + static_assert( \ + std::is_same::value, \ + "Function signature from 'MOCK_FUNCTION_INTERNAL_DEFINITION' macro " \ + "invocation for '" #FUNC "' does not match the function signature " \ + "of '" #FUNC "' function it is mocking. Mismatch could be due to " \ + "different return type, arguments, or calling convention. See " \ + "associated 'MOCK_FUNCTION_INTERNAL_DECLARATION' macro invocation " \ + "for more details."); + +#define MOCK_FUNCTION_TYPE_DEFINITIONS(RET_TYPE, FUNC, ARGS) \ + using FUNC##_ret_type =3D RET_TYPE; \ + using FUNC##_type =3D FUNC##_ret_type ARGS; + +// This function definition simply calls MOCK::Instance->FUNC() which is t= he +// mocked counterpart of the original function. This allows using gmock wi= th +// C free functions (since by default gmock only works with object methods= ). +#define FUNCTION_DEFINITION_TO_CALL_MOCK(MOCK, FUNC, FUNC_DEF_NAME, NUM_AR= GS, CALL_TYPE) \ + extern "C" { = \ + typename MOCK :: FUNC##_ret_type CALL_TYPE FUNC_DEF_NAME( = \ + GMOCK_PP_REPEAT(GMOCK_INTERNAL_PARAMETER, = \ + (MOCK :: FUNC##_type), = \ + NUM_ARGS)) = \ + { = \ + EXPECT_TRUE(MOCK :: Instance !=3D NULL) = \ + << "Called '" #FUNC "' in '" #MOCK "' function mock object before = " \ + << "an instance of '" #MOCK "' was created in test '" = \ + << ::testing::UnitTest::GetInstance()->current_test_info()->name()= \ + << "'."; = \ + return MOCK :: Instance->FUNC( = \ + GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, = \ + (MOCK :: FUNC##_type), = \ + NUM_ARGS)); = \ + } = \ + } + +#define MOCK_STATIC_INSTANCE_DEFINITION(MOCK) MOCK * MOCK :: Instance =3D= NULL; + +#define MOCK_INTERFACE_CONSTRUCTOR(MOCK) = \ + MOCK :: MOCK () { = \ + EXPECT_TRUE(MOCK :: Instance =3D=3D NULL) = \ + << "Multiple instances of '" #MOCK "' function mock object were " = \ + << "created and only one instance is allowed in test '" = \ + << ::testing::UnitTest::GetInstance()->current_test_info()->name() = \ + << "'."; = \ + MOCK :: Instance =3D this; = \ + } + +#define MOCK_INTERFACE_DECONSTRUCTOR(MOCK) \ + MOCK :: ~ MOCK () { \ + MOCK :: Instance =3D NULL; \ + } + +#endif // FUNCTION_MOCK_LIB_H_ diff --git a/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h b/UnitTes= tFrameworkPkg/Include/Library/GoogleTestLib.h index ebec766d4cf7..c0a3d8e66011 100644 --- a/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h +++ b/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h @@ -10,5 +10,101 @@ #define GOOGLE_TEST_LIB_H_ =20 #include +#include +#include + +extern "C" { +#include +} + +//////////////////////////////////////////////////////////////////////////= //// +// Below are the action extensions to GoogleTest and gmock for EDK2 types. +// These actions are intended to be used in EXPECT_CALL (and related gmock +// macros) to support assignments to output arguments in the expected call. +// + +// Action to support pointer types to a buffer (such as UINT8* or VOID*) +ACTION_TEMPLATE ( + SetArgBuffer, + HAS_1_TEMPLATE_PARAMS (size_t, ArgNum), + AND_2_VALUE_PARAMS (Buffer, ByteSize) + ) { + auto ArgBuffer =3D std::get(args); + + std::memcpy (ArgBuffer, Buffer, ByteSize); +} + +//////////////////////////////////////////////////////////////////////////= //// +// Below are the matcher extensions to GoogleTest and gmock for EDK2 types. +// These matchers are intended to be used in EXPECT_CALL (and related gmock +// macros) to support comparisons to input arguments in the expected call. +// +// Note that these matchers can also be used in the EXPECT_THAT or ASSERT_= THAT +// macros to compare whether two values are equal. +// + +// Matcher to support pointer types to a buffer (such as UINT8* or VOID* or +// any structure pointer) +MATCHER_P2 ( + BufferEq, + Buffer, + ByteSize, + std::string ("buffer data to ") + (negation ? "not " : "") + "be the sam= e" + ) { + UINT8 *Actual =3D (UINT8 *)arg; + UINT8 *Expected =3D (UINT8 *)Buffer; + + for (size_t i =3D 0; i < ByteSize; i++) { + if (Actual[i] !=3D Expected[i]) { + *result_listener << "byte at offset " << i + << " does not match expected. [" << std::hex + << "Actual: 0x" << std::setw (2) << std::setfill ('0') + << (unsigned int)Actual[i] << ", " + << "Expected: 0x" << std::setw (2) << std::setfill ('0') + << (unsigned int)Expected[i] << "]"; + return false; + } + } + + *result_listener << "all bytes match"; + return true; +} + +// Matcher to support CHAR16* type +MATCHER_P ( + Char16StrEq, + String, + std::string ("strings to ") + (negation ? "not " : "") + "be the same" + ) { + CHAR16 *Actual =3D (CHAR16 *)arg; + CHAR16 *Expected =3D (CHAR16 *)String; + + for (size_t i =3D 0; Actual[i] !=3D 0; i++) { + if (Actual[i] !=3D Expected[i]) { + *result_listener << "character at offset " << i + << " does not match expected. [" << std::hex + << "Actual: 0x" << std::setw (4) << std::setfill ('0') + << Actual[i]; + + if (std::isprint (Actual[i])) { + *result_listener << " ('" << (char)Actual[i] << "')"; + } + + *result_listener << ", Expected: 0x" << std::setw (4) << std::setfil= l ('0') + << Expected[i]; + + if (std::isprint (Expected[i])) { + *result_listener << " ('" << (char)Expected[i] << "')"; + } + + *result_listener << "]"; + + return false; + } + } + + *result_listener << "strings match"; + return true; +} =20 #endif diff --git a/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf b/UnitTes= tFrameworkPkg/Library/CmockaLib/CmockaLib.inf index 052c7f557210..eeee6bc2b3f5 100644 --- a/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf +++ b/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf @@ -16,7 +16,7 @@ [Defines] LIBRARY_CLASS =3D CmockaLib|HOST_APPLICATION =20 # -# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] diff --git a/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.c= b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.c new file mode 100644 index 000000000000..b7bb23f1868b --- /dev/null +++ b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.c @@ -0,0 +1,7 @@ +/** @file + Macro-only FunctionMockLib library instance with no services. + + Copyright (c) 2023, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ diff --git a/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.i= nf b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf new file mode 100644 index 000000000000..44c5946be533 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf @@ -0,0 +1,31 @@ +## @file +# This module provides FunctionMockLib Library implementation. +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010018 + BASE_NAME =3D FunctionMockLib + MODULE_UNI_FILE =3D FunctionMockLib.uni + FILE_GUID =3D DF1CAF2F-D584-4EC1-9ABF-07E8B10AD560 + MODULE_TYPE =3D HOST_APPLICATION + VERSION_STRING =3D 0.1 + LIBRARY_CLASS =3D FunctionMockLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + FunctionMockLib.c + +[LibraryClasses] + GoogleTestLib + SubhookLib + +[Packages] + MdePkg/MdePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec diff --git a/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.u= ni b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.uni new file mode 100644 index 000000000000..13e5308ce0e7 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.uni @@ -0,0 +1,11 @@ +// /** @file +// This module provides FunctionMockLib Library implementation. +// +// Copyright (c) 2023, Intel Corporation. All rights reserved.
+// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "FunctionMockLib L= ibrary implementation" + +#string STR_MODULE_DESCRIPTION #language en-US "This module provi= des FunctionMockLib Library implementation." diff --git a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf b= /UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf index 68db75d7023f..0104384953c3 100644 --- a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf +++ b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf @@ -7,30 +7,27 @@ ## =20 [Defines] - INF_VERSION =3D 0x00010005 + INF_VERSION =3D 0x00010018 BASE_NAME =3D GoogleTestLib MODULE_UNI_FILE =3D GoogleTestLib.uni FILE_GUID =3D A90E4751-AD30-43CC-980B-01E356B49ADF - MODULE_TYPE =3D BASE + MODULE_TYPE =3D HOST_APPLICATION VERSION_STRING =3D 0.1 - LIBRARY_CLASS =3D GoogleTestLib|HOST_APPLICATION + LIBRARY_CLASS =3D GoogleTestLib =20 # -# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] googletest/googletest/src/gtest-all.cc + googletest/googlemock/src/gmock-all.cc =20 [Packages] + MdePkg/MdePkg.dec UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec =20 [BuildOptions] - MSFT:*_*_*_CC_FLAGS =3D=3D /c /EHsc /Zi - MSFT:NOOPT_*_*_CC_FLAGS =3D /Od - - GCC:*_*_*_CC_FLAGS =3D=3D -g -c - - GCC:NOOPT_*_*_CC_FLAGS =3D -O0 - GCC:*_*_IA32_CC_FLAGS =3D -m32 - GCC:*_*_X64_CC_FLAGS =3D -m64 + MSFT:*_*_*_CC_FLAGS =3D=3D /c /EHsc /Zi /Od + GCC:*_*_IA32_CC_FLAGS =3D=3D -g -c -fshort-wchar -O0 -m32 + GCC:*_*_X64_CC_FLAGS =3D=3D -g -c -fshort-wchar -O0 -m64 diff --git a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.uni b= /UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.uni index 14c862a23744..695588ce3f46 100644 --- a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.uni +++ b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.uni @@ -1,10 +1,7 @@ // /** @file // This module provides GoogleTest Library implementation. // -// This module provides GoogleTest Library implementation. -// // Copyright (c) 2022, Intel Corporation. All rights reserved.
-// // SPDX-License-Identifier: BSD-2-Clause-Patent // // **/ diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc b/U= nitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc index 722509c8f26f..dbb429faaeca 100644 --- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc +++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc @@ -32,8 +32,9 @@ [Components] # Build HOST_APPLICATION Libraries # UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf + UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf - UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAlloca= tionLibPosix.inf + UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml b/UnitTestFr= ameworkPkg/UnitTestFrameworkPkg.ci.yaml index d8f8e024c476..be839d1af0a7 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml @@ -79,9 +79,14 @@ "AuditOnly": False, # Fails test but run in AuditOnly mo= de to collect log "IgnoreFiles": [ # use gitignore syntax to ignore erro= rs in matching files "Library/CmockaLib/cmocka/**/*.*", # not going to spell check= a submodule - "Library/GoogleTestLib/googletest/**/*.*" # not going to spel= l check a submodule + "Library/GoogleTestLib/googletest/**/*.*", # not going to spe= ll check a submodule + "Library/SubhookLib/subhook/**/*.*" # not going to spell chec= k a submodule ], "ExtendWords": [ # words to extend to the dictionary f= or this package + "Pointee", + "gmock", + "GMOCK", + "DSUBHOOK", "testcase", "testsuites", "cmocka", diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec b/UnitTestFramew= orkPkg/UnitTestFrameworkPkg.dec index 30b489915d4a..ef0a148d4876 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec @@ -26,6 +26,7 @@ [Includes.Common.Private] PrivateInclude Library/CmockaLib/cmocka/include/cmockery Library/GoogleTestLib/googletest/googletest + Library/GoogleTestLib/googletest/googlemock =20 [LibraryClasses] ## @libraryclass Allows save and restore unit test internal state @@ -36,6 +37,7 @@ [LibraryClasses] # GoogleTestLib|Include/Library/GoogleTestLib.h SubhookLib|Include/Library/SubhookLib.h + FunctionMockLib|Include/Library/FunctionMockLib.h =20 [LibraryClasses.Common.Private] ## @libraryclass Provides a unit test result report diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTe= stFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index e77897bd326f..7866c36e6693 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -16,6 +16,7 @@ [LibraryClasses.common.HOST_APPLICATION] CmockaLib|UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf GoogleTestLib|UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.i= nf SubhookLib|UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf + FunctionMockLib|UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMoc= kLib.inf UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.i= nf DebugLib|UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.= inf MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationL= ibPosix/MemoryAllocationLibPosix.inf --=20 2.39.1.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 (#102727): https://edk2.groups.io/g/devel/message/102727 Mute This Topic: https://groups.io/mt/98134493/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102728+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+102728+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906062; cv=none; d=zohomail.com; s=zohoarc; b=kLjUs0eWQ2EVq0Yj9zAP0jhHCqANX6bsFzImWlj3lPbtXpTX8DANBZKUvXyxL6yc9UzvKr5jXqIOYTog0fhGq9eiftJDZPYHQJBpOvnaLAGeFAlvLu14SaeFcri5tFgy3mM7hd0XmsNRiAyOoHSwT4+Ppr+XLazcmmPuEip+vKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906062; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=TcORCV3t6VvvWazvYAJg4frhGkCpS7GQO2PDMb4RNO4=; b=g64klZWT4k9aNplbWv7vP/gBfl/5T2TE33Gbgf6cWP4o/EXtgqUDkgdVLz0AH26016TekNuKJ9BFLe4Y9CHFitVl3Mag8Q202PLX2RGGOVo7slfeLzE51eL8OD4VQ5uFSbdsbjACJxZyHzjUt2k8v8Ad64yUu+Vodur6PaQs3/Y= 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+102728+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 1680906062672851.6295298362037; Fri, 7 Apr 2023 15:21:02 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PQ1nYY1788612xVDKKX0MnE4; Fri, 07 Apr 2023 15:21:02 -0700 X-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:01 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085650" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085650" X-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="690177468" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177468" X-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:00 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Chris Johnson , Sean Brogan , Michael Kubacki , Michael Kubacki , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 04/12] UnitTestFrameworkPkg/ReadMe.md: Add gmock documentation Date: Fri, 7 Apr 2023 15:20:42 -0700 Message-Id: <20230407222051.1095-5-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: 6lJk5hpySQgx9HFRn8IqKPJEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906062; bh=bnjyqtCwllQXgF53vgJBOrDiREO/mlR/bS53V8cig5U=; h=Cc:Date:From:Reply-To:Subject:To; b=S4Qoopv/Iqee41rPA2B7svrmqp2fmOo56WC6ccs901+cz8bEGKPTVA4gzyqqB/WO3uc KUhXvYDeX184xX2YR2y1z5SNuhfQA7igoNn5dZqcLUga7tmL/ZGHWxtjghNhiLed1euKe xsqjEJIAWeJm1S5uzwEpi5pMEXCDP9ns7tc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906063327100012 Content-Type: text/plain; charset="utf-8" From: Chris Johnson REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4389 Cc: Sean Brogan Cc: Michael Kubacki Cc: Michael D Kinney Signed-off-by: Chris Johnson Reviewed-by: Michael Kubacki Reviewed-by: Oliver Smith-Denny Reviewed-by: Michael D Kinney --- UnitTestFrameworkPkg/ReadMe.md | 1013 ++++++++++++++++++++++++++++++-- 1 file changed, 970 insertions(+), 43 deletions(-) diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md index 3fa4e1910f71..7da6a320a7f1 100644 --- a/UnitTestFrameworkPkg/ReadMe.md +++ b/UnitTestFrameworkPkg/ReadMe.md @@ -20,12 +20,15 @@ that require mocked interfaces can use the mocking infr= astructure provided by ### GoogleTest =20 The second unit test framework supported by the UnitTestFrameworkPkg is -[GoogleTest](http://google.github.io/googletest/) that can be used to impl= ement host-based unit tests. -Use of GoogleTest for target-based unit tests of EDK II components is not = supported. If a -host-based unit test requires mocked interfaces, then the Framework with c= mocka support should be -used instead. Enabling support for mocked interfaces with GoogleTest is be= ing actively investigated. +[GoogleTest](http://google.github.io/googletest/) and can be used to imple= ment host-based unit tests. [GoogleTest on GitHub](https://github.com/google/googletest) is included i= n the UnitTestFrameworkPkg -as a submodule. +as a submodule. Use of GoogleTest for target-based unit tests of EDK II co= mponents is not supported. +Host-based unit tests that require mocked interfaces can use the mocking i= nfrastructure included with +GoogleTest called [gMock](https://github.com/google/googletest/tree/main/g= ooglemock). Note that the +gMock framework does not directly support mocking of free (C style) functi= ons, so the FunctionMockLib +(containing a set of macros that wrap gMock's MOCK_METHOD macro) was creat= ed within the +UnitTestFrameworkPkg to enable this support. The details and usage of thes= e macros in the +FunctionMockLib are described later. =20 GoogleTest requires less overhead to register test suites and test cases c= ompared to the Framework. There are also a number of tools that layer on top of GoogleTest that impr= ove developer productivity. @@ -33,13 +36,19 @@ One example is the VS Code extension [C++ TestMate](https://marketplace.visualstudio.com/items?itemName=3Dmatep= ek.vscode-catch2-test-adapter) that may be used to implement, run, and debug unit tests implemented using= GoogleTest. =20 -If a component can be tested with host-based unit tests without support fo= r mocked interfaces, -then GoogleTest is recommended. The MdePkg contains a port of the BaseSafe= IntLib unit tests in -the GoogleTest style so the differences between GoogleTest and Framework u= nit tests can be reviewed. -The paths to the BaseSafeIntLib unit tests are: +If a component can be tested with host-based unit tests, then GoogleTest i= s recommended. The MdePkg +contains a port of the BaseSafeIntLib unit tests in the GoogleTest style s= o the differences between +GoogleTest and Framework unit tests can be reviewed. The paths to the Base= SafeIntLib unit tests are: =20 -* MdePkg\Test\UnitTest\Library\BaseSafeIntLib -* MdePkg\Test\GoogleTest\Library\BaseSafeIntLib +* `MdePkg/Test/UnitTest/Library/BaseSafeIntLib` +* `MdePkg/Test/GoogleTest/Library/BaseSafeIntLib` + +Furthermore, the SecurityPkg contains unit tests for the SecureBootVariabl= eLib using mocks in both +the Framework/cmocka and GoogleTest/gMock style so the differences between= cmocka and gMock can be +reviewed. The paths to the SecureBootVariableLib unit tests are: + +* `SecurityPkg/Library/SecureBootVariableLib/UnitTest` +* `SecurityPkg/Library/SecureBootVariableLib/GoogleTest` =20 ## Framework and GoogleTest Feature Comparison =20 @@ -56,7 +65,7 @@ The paths to the BaseSafeIntLib unit tests are: | Typed Tests | NO | YES | | Type-Parameterized Tests | NO | YES | | Timeout Support | NO | YES | -| Mocking Support | Cmocka | NO | +| Mocking Support | Cmocka | gMock | | JUNIT XML Reports | YES | YES | | Execute subset of tests | NO | YES | | VS Code Extensions | NO | YES | @@ -104,7 +113,7 @@ This section is built a lot like a "Getting Started". W= e'll go through some of t when constructing a unit test and some of the decisions that are made by t= he test writer. We'll also describe how to check for expected conditions in test cases and a bit of the loggin= g characteristics. =20 -Most of these examples will refer to the SampleUnitTestUefiShell app found= in this package. +Most of these examples will refer to the `SampleUnitTestUefiShell` app fou= nd in this package. =20 ### Framework Requirements - INF =20 @@ -113,7 +122,7 @@ header for the `UnitTestLib` is located in `MdePkg`, so= you shouldn't need to de packages. As long as your DSC file knows where to find the lib implementat= ion that you want to use, you should be good to go. =20 -See this example in 'SampleUnitTestUefiShell.inf'... +See this example in `SampleUnitTestUefiShell.inf`... =20 ``` [Packages] @@ -127,7 +136,7 @@ See this example in 'SampleUnitTestUefiShell.inf'... PrintLib ``` =20 -Also, if you want you test to automatically be picked up by the Test Runne= r plugin, you will need +Also, if you want your test to automatically be picked up by the Test Runn= er plugin, you will need to make sure that the module `BASE_NAME` contains the word `Test`... =20 ``` @@ -135,6 +144,43 @@ to make sure that the module `BASE_NAME` contains the = word `Test`... BASE_NAME =3D SampleUnitTestUefiShell ``` =20 +### Framework Requirements - DSC + +In our DSC file, we'll need to bring in the INF file that was just created= into the `[Components]` +section so that the unit tests will be built. + +See this example in `UnitTestFrameworkPkg.dsc`... + +``` +[Components] + UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestU= efiShell.inf +``` + +Also, based on the type of tests that are being created, the associated DS= C include file from the +UnitTestFrameworkPkg for Host or Target based tests should also be include= d at the top of the DSC +file. + +``` +!include UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc +``` + +Lastly, in the case that the test build has specific dependent libraries a= ssociated with it, +they should be added in the \ sub-section for the INF fil= e in the +`[Components]` section of the DSC file. + +See this example in `SecurityPkgHostTest.dsc`... + +``` +[Components] + SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariableLib= UnitTest.inf { + + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/Secu= reBootVariableLib.inf + UefiRuntimeServicesTableLib|SecurityPkg/Library/SecureBootVariableLi= b/UnitTest/MockUefiRuntimeServicesTableLib.inf + PlatformPKProtectionLib|SecurityPkg/Library/SecureBootVariableLib/Un= itTest/MockPlatformPKProtectionLib.inf + UefiLib|SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiL= ib.inf + } +``` + ### Framework Requirements - Code =20 Not to state the obvious, but let's make sure we have the following includ= e before getting too far along... @@ -143,7 +189,7 @@ Not to state the obvious, but let's make sure we have t= he following include befo #include ``` =20 -Now that we've got that squared away, let's look at our 'Main()'' routine = (or DriverEntryPoint() or whatever). +Now that we've got that squared away, let's look at our 'Main()' routine (= or DriverEntryPoint() or whatever). =20 ### Framework Configuration =20 @@ -157,7 +203,7 @@ The long name and version strings are just for user pre= sentation and relatively will be used to name any cache files and/or test results, so should be a n= ame that makes sense in that context. These strings are copied internally to the Framework, so using stack-alloc= ated or literal strings is fine. =20 -In the 'SampleUnitTestUefiShell' app, the module name is used as the short= name, so the initialization looks like this. +In the `SampleUnitTestUefiShell` app, the module name is used as the short= name, so the initialization looks like this. =20 ```c DEBUG(( DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION = )); @@ -184,7 +230,7 @@ called once at the start of the suite (before _any_ tes= ts have run) and once at tests have run), respectively. If either or both of these are unneeded, pa= ss `NULL`. The function prototypes are `UNIT_TEST_SUITE_SETUP` and `UNIT_TEST_SUITE_TEARDOWN`. =20 -Looking at 'SampleUnitTestUefiShell' app, you can see that the first test = suite is created as below... +Looking at `SampleUnitTestUefiShell` app, you can see that the first test = suite is created as below... =20 ```c // @@ -218,7 +264,7 @@ of the context pointer is to allow test case reuse with= different input data. (A around a system reboot, but that's beyond the scope of this guide.) The te= st case must know how to interpret the context pointer, so it could be a simple value, or it could be a complex structure= . If unneeded, pass `NULL`. =20 -In 'SampleUnitTestUefiShell' app, the first test case is added using the c= ode below... +In `SampleUnitTestUefiShell` app, the first test case is added using the c= ode below... =20 ```c AddTestCase( SimpleMathTests, "Adding 1 to 1 should produce 2", "Addition"= , OnePlusOneShouldEqualTwo, NULL, NULL, NULL ); @@ -282,6 +328,617 @@ leverage the `cmocka.h` interface and write tests wit= h all the features of the C Documentation for Cmocka can be found here: https://api.cmocka.org/ =20 +## GoogleTest Libraries + +### GoogleTestLib + +GoogleTestLib is the core library used for GoogleTest in EDK II. This libr= ary is mainly a wrapper +around the GoogleTest and gMock header and source files. So all the standa= rd +[GoogleTest](http://google.github.io/googletest/) and +[gMock](https://github.com/google/googletest/tree/main/googlemock) documen= tation for writing tests +and using mocks applies. + +Additionally, to support the use of some primitive types that are not dire= ctly supported by +GoogleTest and gMock (but are needed to allow gMock to be used in EDK II),= some custom gMock +actions and matchers were added to GoogleTestLib. These customizations are= briefly described in +the following tables. + +#### Custom Actions + +| Action Name | Similar gMock Generic Action | Usage | +|:--- |:--- |:--- | +| `SetArgBuffer()` | `SetArgPointee()` | Used to set a buffer output argum= ent (such as UINT8*, VOID*, a structure pointer, etc.) with data in an expe= ct call. Can be used in an `EXPECT_CALL()` | + +#### Custom Matchers + +| Matcher Name | Similar gMock Generic Matcher | Usage | +|:--- |:--- |:--- | +| `BufferEq()` | `Pointee(Eq())` | Used to compare two buffer pointer type= s (such as UINT8*, VOID*, a structure pointer, etc.). Can be used in an `EX= PECT_CALL()`, `EXPECT_THAT()`, or anywhere else a matcher to compare two bu= ffers is needed. | +| `Char16StrEq()` | `Pointee(Eq())` | Used to compare two CHAR16* strings.= Can be used in an `EXPECT_CALL()`, `EXPECT_THAT()`, or anywhere else a mat= cher to compare two CHAR16* strings is needed. | + +### FunctionMockLib + +FunctionMockLib is the library that allows gMock to be used with free (C s= tyle) functions. This +library contains a set of macros that wrap gMock's MOCK_METHOD macro to en= able the standard gMock +capabilities to be used with free functions. The details of how this is im= plemented is outside the +scope of this document, but a brief description of each of the public macr= os in FunctionMockLib is +described below. A full example of how to use these macros to create a moc= k is described in a +later section. + +In total there are six public macros in FunctionMockLib. Four of the macro= s are related to creating +the mock functions, and the other two macros are related to creating an in= terface that is necessary +to contain the mock functions and connect them into the gMock framework. + +The macros used to create the interface are... +1. `MOCK_INTERFACE_DECLARATION(MOCK)` +2. `MOCK_INTERFACE_DEFINITION(MOCK)` + +These macros both take one argument which is the name of the interface for= the mock. The +`MOCK_INTERFACE_DECLARATION` macro is used to declare the interface in the= `.h` file and the +`MOCK_INTERFACE_DEFINITION` macro is used to define the interface in the `= .cpp` file. For +example, to create a mock for the `UefiLib`, a `MockUefiLib.h` file would = be created and the +below code would be added to it. + +```cpp +struct MockUefiLib { + MOCK_INTERFACE_DECLARATION(MockUefiLib); +}; +``` + +Additionally, the below code would be written into a `MockUefiLib.cpp` fil= e. + +```cpp +MOCK_INTERFACE_DEFINITION(MockUefiLib); +``` + +The macros used to create the mock functions are... +1. `MOCK_FUNCTION_DECLARATION(RET_TYPE, FUNC, ARGS)` +2. `MOCK_FUNCTION_DEFINITION(MOCK, FUNC, NUM_ARGS, CALL_TYPE)` +3. `MOCK_FUNCTION_INTERNAL_DECLARATION(RET_TYPE, FUNC, ARGS)` +4. `MOCK_FUNCTION_INTERNAL_DEFINITION(MOCK, FUNC, NUM_ARGS, CALL_TYPE)` + +You will notice that there are two sets of macros: one to mock external fu= nctions and +another to mock internal functions. Each set of macros has the exact same = arguments, but +they are used for slightly different use cases. The details of these diffe= rent use cases +is described in detail in a later section. For now, we will focus on the u= sage of the macro +arguments since that is common between them. + +The `MOCK_FUNCTION_DECLARATION` macro is used to declare the mock function= in the `.h` file, +and it takes three arguments: return type, function name, and argument lis= t. The +`MOCK_FUNCTION_DEFINITION` macro is used to define the mock function in th= e `.cpp` file, +and it takes four arguments: name of the interface for the mock, function = name, number of +arguments the function takes, and calling convention type of the function.= For example, to +continue with the `UefiLib` mock example above, the `GetVariable2` and `Ge= tEfiGlobalVariable2` +functions are declared in `UefiLib.h` as shown below. + +```cpp +EFI_STATUS +EFIAPI +GetVariable2 ( + IN CONST CHAR16 *Name, + IN CONST EFI_GUID *Guid, + OUT VOID **Value, + OUT UINTN *Size OPTIONAL + ); + +EFI_STATUS +EFIAPI +GetEfiGlobalVariable2 ( + IN CONST CHAR16 *Name, + OUT VOID **Value, + OUT UINTN *Size OPTIONAL + ); +``` + +To declare mocks for these functions within the previously created `MockUe= fiLib` interface, +the below code would be added to the `MockUefiLib.h` file. Note that the p= reviously added +interface declaration is also included in the code below for context. + +```cpp +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) + ); +}; +``` + +Additionally, the below code would be added into the `MockUefiLib.cpp` fil= e to provide +the definitions for these mock functions. Again, the previously added inte= rface +definition is also included in the code below for context. + +```cpp +MOCK_INTERFACE_DEFINITION(MockUefiLib); + +MOCK_FUNCTION_DEFINITION(MockUefiLib, GetVariable2, 4, EFIAPI); +MOCK_FUNCTION_DEFINITION(MockUefiLib, GetEfiGlobalVariable2, 3, EFIAPI); +``` + +That concludes the basic overview on how to use the macros, but a more det= ailed +description on how to name the mocks, where to put the files, how to build= the +mocks, and how to use the mocks is described in detail later. + +### SubhookLib + +SubhookLib is the library used by FunctionMockLib to implement the macros = to +mock internal functions: `MOCK_FUNCTION_INTERNAL_DECLARATION` and +`MOCK_FUNCTION_INTERNAL_DEFINITION`. These macros require the additional +functionality provided by SubhookLib because they create mock functions +for functions that are already defined and compiled within the module being +tested. More detail on this is provided in a later section, but for now it= is +sufficient to know that the SubhookLib allows a second definition of the +function to be compiled into the test application and then hooked to durin= g a +test. + +This library is mainly a wrapper around the +[subhook](https://github.com/Zeex/subhook) header and source files. It is +important to note that the use of the mock function macros and the creation +of mock functions requires no knowledge about the SubhookLib. The SubhookL= ib +library is entirely hidden and encapsulated within FunctionMockLib, and it +is only mentioned here to provide a complete explanation on all the librar= ies +used in the implementation. + +## FunctionMockLib Mocks + +This section describes the details on how to use the mock function macros = in +FunctionMockLib to create mock functions, name them, organize their files, +and build them so that they can be used within GoogleTest tests. The usage +of the mock functions is detailed in a later section while this section +simply details how to create them, build them, and where to put them. + +### FunctionMockLib Mocks - External vs. Internal + +The first question to ask when creating a mock function is if the function= being +mocked is external or internal to the module being tested. This is very im= portant +because the macros in FunctionMockLib used to create the mock function are= named +differently for these two use cases. Fortunately, the arguments to these m= acros +and the usage of the mock functions within the tests are exactly the same. +However, because of the different underlying implementations, two differen= t sets +of macros are used. + +A more detailed description of when to use the external vs. internal mock = function +macros is in the following sections, but the quick summary is as follows. + +* External mock function macros are used to mock functions that are outsid= e the +module being tested and use link-time replacement. +* Internal mock function macros are used to mock functions that are inside= the +module being tested and use run-time replacement. + +The below table shows which macros to use in these two use cases. However,= note that +for the creation of the interface, the same macros are used in both cases. + +| Mock Function Use Case | Mock Interface Macros | Mock Function Macros | +|:--- |:--- |:--- | +| External mock functions | `MOCK_INTERFACE_DECLARATION`
`MOCK_INTERFA= CE_DEFINITION` | `MOCK_FUNCTION_DECLARATION`
`MOCK_FUNCTION_DEFINITION`= | +| Internal mock functions | `MOCK_INTERFACE_DECLARATION`
`MOCK_INTERFA= CE_DEFINITION` | `MOCK_FUNCTION_INTERNAL_DECLARATION`
`MOCK_FUNCTION_IN= TERNAL_DEFINITION` | + +#### FunctionMockLib Mocks - External mock function + +The external mock function macros are used to create mock function definit= ions +for a library, global service, or protocol that is defined outside of the = module +being tested. These mock function definitions are linked into the test app= lication +instead of linking in the design function definitions. In other words, the +external mock function macros use link-time replacement of the design func= tions. + +The `.h/.cpp` files for these mock functions are created within the package +directory where the library, global table, or protocol that is being mocke= d is +declared. These files are compiled into their own separate library (using +an INF file) that can be shared and linked into many test applications, bu= t more +on that later. + +#### FunctionMockLib Mocks - Internal mock function + +The internal mock function macros are used to create mock function definit= ions +for functions that are defined within the module being tested. These mock +function definitions are compiled into the test application along with the= design +function definitions. This is possible because the mock functions are give= n a +slightly different name during compilation. Then during test execution, the +design function is hooked and replaced with the mock function. In other wo= rds, +the internal mock function macros use run-time replacement of the design +functions. + +The `.h/.cpp` files for these mock functions are created within the Google= Test +directory containing the specific tests that are using them. These files a= re +compiled directly in the GoogleTest INF file that builds the test applicat= ion, +and they are not shared outside of that GoogleTest directory, but more on = that +later. + +### FunctionMockLib Mocks - Declaration + +The declaration of mock functions using the FunctionMockLib macros are done +in header files. The name of the header file is determined by the interface +(such as a library or a protocol) that is being created for the mock funct= ions. +The rules for naming the file are shown in the table below. + +| Interface Type | Header File Name | +| :--- | :--- | +| Library | Mock\Lib.h | +| Global Table (e.g. gRT, gBS, etc.) | Mock\Lib.h= | +| Protocol | Mock\Protocol.h | + +The below table shows examples for file names with each of the above cases. + +| Interface Type | Interface Name | Header File Name | +| :--- | :--- | :--- | +| Library | UefiLib | MockUefiLib.h | +| Global Table (e.g. gRT, gBS, etc.) | UefiRuntimeServicesTableLib | MockU= efiRuntimeServicesTableLib.h | +| Protocol | EFI_USB_IO_PROTOCOL | MockEfiUsbIoProtocol.h | + +Once the header file name is known, the file needs to be created in the pr= oper +location. For internal mock functions, the location is simply the same +GoogleTest directory that contains the INF file that builds the test appli= cation. +For external mock functions, the location is within the `Test` directory u= nder the +package where the library, global table, or protocol that is being mocked = is +declared. The exact location depends on the interface type and is shown in= the +below table. + +| Interface Type | Header File Location | +| :--- | :--- | +| Library | \/Test/Mock/Include/GoogleTest/Library | +| Global Table (e.g. gRT, gBS, etc.) | \/Test/Mock/Include/G= oogleTest/Library | +| Protocol | \/Test/Mock/Include/GoogleTest/Protocol | + +The below table shows examples for file locations with each of the above c= ases. + +| Interface Type | Interface Name | Header File Location | +| :--- | :--- | :--- | +| Library | UefiLib | MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefi= Lib.h | +| Global Table (e.g. gRT, gBS, etc.) | UefiRuntimeServicesTableLib | MdePk= g/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServicesTableLib.h | +| Protocol | EFI_USB_IO_PROTOCOL | MdePkg/Test/Mock/Include/GoogleTest/Pro= tocol/MockEfiUsbIoProtocol.h | + +Now that the file location is known, the contents can be added to it. Afte= r the +standard `#ifndef` for a header file is added at the top of the file, the +`GoogleTestLib.h` and `FunctionMockLib.h` files are always added. Followin= g these +includes other EDK II related include files are added and must be wrapped = in +`extern "C" {}` because they are C include files. Failure to do this will = cause +link errors to occur. Note that a `#include` of the interface being mocked= must +also be added. This causes the declarations of the functions being mocked = to be +included in the compilation and allows the compilation to verify that the = function +signatures of the mock and design functions are identical. + +After all the needed includes have been added in the file , a `struct` is = declared +using the same name as the header file (which was determined using the rul= es +above). Within this structure declaration a `MOCK_INTERFACE_DECLARATION` is +added along with a `MOCK_FUNCTION_DECLARATION` (or a +`MOCK_FUNCTION_INTERNAL_DECLARATION` if this interface is for internal mock +functions) for each function in the interface. To build on the examples ab= ove, +the complete `MockUefiLib.h` file would be as shown below. Note that for b= revity +only the `GetVariable2` and `GetEfiGlobalVariable2` declarations are inclu= ded in +the example. + +```cpp +#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 +``` + +In the case of libraries, the function names in the mock declarations +align exactly with the function names in the design. However, in the +case of global tables and protocols, to eliminate possible function +name collisions, the names are adjusted slightly in the mock +declarations as shown in the below table. + +| Mock Function Use Case | Design Function Name | Mock Function Name | +| :--- | :--- | :--- | +| Library | GetVariable2 | GetVariable2 | +| Global Table (e.g. gRT, gBS, etc.) | gRT->GetVariable | gRT_GetVariable | +| Protocol | UsbIoProtocol->UsbPortReset | UsbIoProtocol_UsbPortReset | + +Lastly, when creating mock functions, there are two limitations to be +aware of in gMock that extend into FunctionMockLib. + +1. gMock does not support mocking functions that have more than 15 argumen= ts. +2. gMock does not support mocking variadic functions. + +With those limitations in mind, that completes the mock function +declarations, and now the mock function definitions for those declarations +can be created. + +### FunctionMockLib Mocks - Definition + +The definition of mock functions using the FunctionMockLib macros are done +in source files. The name of the source file is determined by the interface +(such as a library or a protocol) that is being created for the mock funct= ions. +The rules for naming the file align with the naming of the file for declar= ations +and are shown in the table below. + +| Interface Type | Source File Name | +| :--- | :--- | +| Library | Mock\Lib.cpp | +| Global Table (e.g. gRT, gBS, etc.) | Mock\Lib.c= pp | +| Protocol | Mock\Protocol.cpp | + +The below table shows examples for file names with each of the above cases. + +| Interface Type | Interface Name | Source File Name | +| :--- | :--- | :--- | +| Library | UefiLib | MockUefiLib.cpp | +| Global Table (e.g. gRT, gBS, etc.) | UefiRuntimeServicesTableLib | MockU= efiRuntimeServicesTableLib.cpp | +| Protocol | EFI_USB_IO_PROTOCOL | MockEfiUsbIoProtocol.cpp | + +Once the source file name is known, the file needs to be created in the pr= oper +location. The location of the source file is aligned with the location for= the +header file. For internal mock functions, the location is simply the same +GoogleTest directory that contains the INF file that builds the test appli= cation. +For external mock functions, the location is within the `Test` directory u= nder the +package where the library, global table, or protocol that is being mocked = is +declared. The exact location depends on the interface type and is shown in= the +below table. + +| Interface Type | Source File Location | +| :--- | :--- | +| Library | \/Test/Mock/Library/GoogleTest/Mock\Lib | +| Global Table (e.g. gRT, gBS, etc.) | \/Test/Mock/Library/G= oogleTest/Mock\Lib | +| Protocol | \/Test/Mock/Library/GoogleTest/Mock\Protocol | + +The below table shows examples for file locations with each of the above c= ases. + +| Interface Type | Interface Name | Source File Location | +| :--- | :--- | :--- | +| Library | UefiLib | MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/Mock= UefiLib.cpp | +| Global Table (e.g. gRT, gBS, etc.) | UefiRuntimeServicesTableLib | MdePk= g/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRunt= imeServicesTableLib.cpp | +| Protocol | EFI_USB_IO_PROTOCOL | MdePkg/Test/Mock/Library/GoogleTest/Moc= kEfiUsbIoProtocol/MockEfiUsbIoProtocol.cpp | + +Now that the file location is known, the contents can be added to it. At t= he top +of the file, the header file containing the mock function declarations is = always +added. After this `#include`, the interface definition is created using +`MOCK_INTERFACE_DEFINITION` with the interface name that was used in the m= ock +function declaration header file. A `MOCK_FUNCTION_DEFINITION` is then add= ed (or +a `MOCK_FUNCTION_INTERNAL_DEFINITION` if this interface is for internal mo= ck +functions) for each function that was declared in the interface. To build = on the +prior declaration examples, the complete `MockUefiLib.cpp` file would be a= s shown +below. Note that for brevity only the `GetVariable2` and `GetEfiGlobalVari= able2` +definitions are included in the example. + +```cpp +#include + +MOCK_INTERFACE_DEFINITION(MockUefiLib); + +MOCK_FUNCTION_DEFINITION(MockUefiLib, GetVariable2, 4, EFIAPI); +MOCK_FUNCTION_DEFINITION(MockUefiLib, GetEfiGlobalVariable2, 3, EFIAPI); +``` + +When creating the defintions, there are a few things to keep in mind. + +First, when using `MOCK_FUNCTION_DEFINITION`, some functions being mocked = do +not specify a calling convention. In this case, it is fine to leave the la= st +argument of `MOCK_FUNCTION_DEFINITION` empty. For example, if `GetVariable= 2` +did not specify the `EFIAPI` calling convention in its declaration, then t= he +below code would be used for the mock function definition. + +```cpp +MOCK_FUNCTION_DEFINITION(MockUefiLib, GetVariable2, 4, ); +``` + +Second, the function name used in `MOCK_FUNCTION_DEFINITION` must align wi= th +the function name used in the associated `MOCK_FUNCTION_DECLARATION` in the +header file. + +Last, if the interface is mocking a global table or protocol, then the str= ucture +of function pointers for that interface must also be defined within the so= urce +file as a `static` structure with the mock function definitions being assi= gned +to the associated entries in the structure. The address of this `static` +structure is then assigned to the global table or protocol pointer. Note t= hat +this pointer must be wrapped in `extern "C" {}` because it needs C style +linkage. Failure to do this will cause link errors to occur. For example, = when +creating the definition of the mock for the global runtime services table,= the +complete `MockUefiRuntimeServicesTableLib.cpp` file would be as shown belo= w. +Note that for brevity only the `GetVariable` and `SetVariable` definitions= are +included in the example. + +```cpp +#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; +} +``` + +That completes the mock function definitions. So now these mock function +definitions can be compiled. + +### FunctionMockLib Mocks - Build + +The building of mock functions using FunctionMockLib is done slightly +differently for external and internal function mocks. External mock +functions are built using their own separate INF file and internal mock +functions are built as source files directly referenced in the GoogleTest +INF file that builds the test application. + +#### FunctionMockLib Mocks - Build External Mock Functions + +The building of external mock functions is done using their own separate I= NF +file which is placed in the same location as the associated source file +containing the mock function definitions. The name of the INF file is exac= tly +the same as the mock function definitions file, but uses the `.inf` extens= ion +rather than `.cpp`. + +Within the `.inf` file the `BASE_NAME` should be set to the same name as t= he +file (minus the extension), the `MODULE_TYPE` should be set to +`HOST_APPLICATION`, and the `LIBRARY_CLASS` should be the same as the +`BASE_NAME` but without the `Mock` prefix. + +The `[Sources]` section will contain the single mock function definition +source file, the `[Packages]` section will contain all the necessary DEC +files to compile the mock functions (which at a minimum will include the +`UnitTestFrameworkPkg.dec` file), the `[LibraryClasses]` section will cont= ain +the `GoogleTestLib`, and the `[BuildOptions]` will need to append the `/EH= sc` +compilation flag to all MSFT builds to enable proper use of the C++ except= ion +handler. Below is the complete `MockUefiLib.inf` as an example. + +``` +[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 +``` + +To ensure that this specific set of mock functions are always buildable ev= en +if no test uses it yet, this created INF file needs to be added into the +`[Components]` section of the associated `Test` DSC file for the package in +which this INF file resides. For example, the above `MockUefiLib.inf` would +need to be added to the `MdePkg/Test/MdePkgHostTest.dsc` file as shown bel= ow. + +``` +[Components] + MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf +``` + +This created INF file will also be referenced within the necessary `Test` = DSC +files in order to include the mock function definitions in the test +applications which use this set of mock functions, but more on that later. + +One small additional requirement is that if this INF file is added into a +package that does not yet have any other external mock functions in it, th= en +that package's DEC file will need to have the mock include directory (more +specifically the `Test/Mock/Include` directory) added to its `[Includes]` +section so that test files who want to use the mock functions will be able= to +locate the mock function header file. For example, if `MockUefiLib.inf` we= re +the first mock added to the `MdePkg`, then the below snippet would need to= be +added to the `MdePkg.dec` file. + +``` +[Includes] + Test/Mock/Include +``` + +#### FunctionMockLib Mocks - Build Internal Mock Functions + +The building of internal mock functions is done using the GoogleTest INF f= ile +that already needs to exist to build the test application. This is easy to +manage since the source and header files for the internal mock functions a= re +also located in the same GoogleTest directory as the GoogleTest INF file t= hat +will reference them. + +The only additions that are required to the GoogleTest INF file are that t= he +mock function definitions file be added to the `[Sources]` section, the +`UnitTestFrameworkPkg.dec` file be added to the `[Packages]` section, and = the +`GoogleTestLib` and `SubhookLib` be added to the `[LibraryClasses]` sectio= n. +Below is a minimal contrived example for a `MyModuleGoogleTest.inf` that u= ses a +`MockMyModuleInternalFunctions.cpp` source file for its internal mock func= tions. + +``` +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D MyModuleGoogleTest + FILE_GUID =3D 814B09B9-2D51-4786-8A77-2E10CD1C55F3 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D HOST_APPLICATION + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + MyModuleGoogleTest.cpp + MockMyModuleInternalFunctions.cpp + +[Packages] + MdePkg/MdePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + GoogleTestLib + SubhookLib +``` + ## GoogleTest Samples =20 There is a sample unit test provided as both an example of how to write a = unit test and leverage @@ -291,22 +948,31 @@ directory. The sample is provided for the HOST_APPLICATION build type, which can be r= un on a host system without needing a target. =20 +There is also a sample unit test provided as both an example of how to wri= te a unit test with +mock functions and leverage some of the gMock features. This sample can be= found in the +`SecurityPkg/Library/SecureBootVariableLib/GoogleTest` directory. + +It too is provided for the HOST_APPLICATION build type, which can be run o= n a host system without +needing a target. + ## GoogleTest Usage =20 This section is built a lot like a "Getting Started". We'll go through som= e of the components that are needed when constructing a unit test and some of the decisions that are made by t= he test writer. We'll also describe how to check for expected conditions in test cases and a bit of the loggin= g characteristics. =20 -Most of these examples will refer to the SampleGoogleTestHost app found in= this package. +Most of these examples will refer to the `SampleGoogleTestHost` app found = in this package, but +the examples related to mock functions will refer to the `SecureBootVariab= leLibGoogleTest` app +found in the `SecurityPkg`. =20 ### GoogleTest Requirements - INF =20 -In our INF file, we'll need to bring in the `GoogleTest` library. Convenie= ntly, the interface -header for the `GoogleTest` is in `UnitTestFrameworkPkg`, so you shouldn't= need to depend on any other +In our INF file, we'll need to bring in the `GoogleTestLib` library. Conve= niently, the interface +header for the `GoogleTestLib` is in `UnitTestFrameworkPkg`, so you should= n't need to depend on any other packages. As long as your DSC file knows where to find the lib implementat= ion that you want to use, you should be good to go. =20 -See this example in 'SampleGoogleTestHost.inf'... +See this example in `SampleGoogleTestHost.inf`... =20 ``` [Packages] @@ -319,7 +985,7 @@ See this example in 'SampleGoogleTestHost.inf'... DebugLib ``` =20 -Also, if you want you test to automatically be picked up by the Test Runne= r plugin, you will need +Also, if you want your test to automatically be picked up by the Test Runn= er plugin, you will need to make sure that the module `BASE_NAME` contains the word `Test`... =20 ``` @@ -327,12 +993,54 @@ to make sure that the module `BASE_NAME` contains the= word `Test`... BASE_NAME =3D SampleGoogleTestHost ``` =20 +### GoogleTest Requirements - DSC + +In our DSC file, we'll need to bring in the INF file that was just created= into the `[Components]` +section so that the unit tests will be built. + +See this example in `UnitTestFrameworkPkgHostTest.dsc`... + +``` +[Components] + UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogl= eTestHost.inf +``` + +Also, based on the type of tests that are being created, the associated DS= C include file from the +UnitTestFrameworkPkg for Host or Target based tests should also be include= d at the top of the DSC +file. + +``` +!include UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +``` + +Lastly, in the case that the test build has specific dependent libraries a= ssociated with it, +they should be added in the \ sub-section for the INF fil= e in the +`[Components]` section of the DSC file. Note that it is within this sub-se= ction where you can +control whether the design or mock version of a component is linked into t= he test exectuable. + +See this example in `SecurityPkgHostTest.dsc` where the `SecureBootVariabl= eLib` design is +being tested using mock versions of `UefiRuntimeServicesTableLib`, `Platfo= rmPKProtectionLib`, +and `UefiLib`... + +``` +[Components] + SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariableL= ibGoogleTest.inf { + + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/Secu= reBootVariableLib.inf + UefiRuntimeServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/Mock= UefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf + PlatformPKProtectionLib|SecurityPkg/Test/Mock/Library/GoogleTest/Moc= kPlatformPKProtectionLib/MockPlatformPKProtectionLib.inf + UefiLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.= inf + } +``` + ### GoogleTest Requirements - Code =20 -Not to state the obvious, but let's make sure we have the following includ= e before getting too far along... +GoogleTest applications are implemented in C++, so make sure that your tes= t file has +a `.cpp` extension. With that behind us, not to state the obvious, but let= 's make sure +we have the following includes before getting too far along in the file... =20 -``` -#include +```cpp +#include extern "C" { #include #include @@ -340,33 +1048,75 @@ extern "C" { } ``` =20 -GoogleTest applications are implemented in C++. The first include brings i= n the -GoogleTest definitions. Other EDK II related include files must be wrapped= in -`extern "C" {}` because they are C include files. Link failures will occur= if -this is not done. +The first include brings in the GoogleTest definitions. Other EDK II relat= ed include +files must be wrapped in `extern "C" {}` because they are C include files.= Link +failures will occur if this is not done. =20 -Now that we've got that squared away, let's look at our 'Main()'' routine = (or DriverEntryPoint() or whatever). +Also, when using GoogleTest it is helpful to add a `using` declaration for= its +`testing` namespace. This `using` statement greatly reduces the amount of = code you +need to write in the tests when referencing the utilities within the `test= ing` +namespace. For example, instead of writing `::testing::Return` or `::testi= ng::Test`, +you can just write `Return` or `Test` respectively, and these types of ref= erences +occur numerous times within the tests. + +Lastly, in the case that tests within a GoogleTest application require the= usage of +mock functions, it is also necessary to include the header files for those= interfaces +as well. As an example, the `SecureBootVariableLibGoogleTest` uses the moc= k versions +of `UefiLib` and `UefiRuntimeServicesTableLib`. So its test file contains = the below +includes. Note that the `using` declaration mentioned above is also shown = in the code +below for completeness of the example. + +```cpp +#include +#include +#include + +extern "C" { + #include + ... +} + +using namespace testing; +``` + +Now that we've got that squared away, let's look at our 'Main()' routine (= or DriverEntryPoint() or whatever). =20 ### GoogleTest Configuration =20 Unlike the Framework, GoogleTest does not require test suites or test case= s to be registered. Instead, the test cases declare the test suite name and test case name as part of their implementation. The only requirement for Google= Test -is to have a `main()` function that initialize the GoogleTest infrastructu= re and -call the service `RUN_ALL_TESTS()` to run all the unit tests. +is to have a `main()` function that initializes the GoogleTest infrastruct= ure +and calls the service `RUN_ALL_TESTS()` to run all the unit tests. =20 -```c +```cpp int main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } ``` =20 +However, while GoogleTest does not require test suites or test cases to be +registered, there is still one rule within EDK II that currently needs to = be +followed. This rule is that all tests for a given GoogleTest application m= ust +be contained within the same source file that contains the `main()` functi= on +shown above. These tests can be written directly in the file or a `#includ= e` +can be used to add them into the file indirectly. + +The reason for this is due to EDK II taking the host application INF file = and +first compiling all of its source files into a static library. This static +library is then linked into the final host application. The problem with t= his +method is that only the tests in the object file containing the `main()` +function are linked into the final host application. This is because the o= ther +tests are contained in their own object files within the static library and +they have no symbols in them that the final host application depends on, so +those object files are not linked into the final host application. + ### GoogleTest - A Simple Test Case =20 -We'll look at the below test case from 'SampleGoogleTestHost'... +Below is a sample test case from `SampleGoogleTestHost`. =20 -```c +```cpp TEST(SimpleMathTests, OnePlusOneShouldEqualTwo) { UINTN A; UINTN B; @@ -393,9 +1143,175 @@ detailed logs. When in doubt, there are always `ASSE= RT_TRUE` and `ASSERT_FALSE`. test criterium will immediately return from the test case with a failed st= atus and log an error string. _Note_ that this early return can have implications for memory leakage. =20 -There is no return status from a GooglTest unit test. If no assertions are +For most `ASSERT` macros in GoogleTest there is also an equivalent `EXPECT= ` macro. Both macro versions +will ultimately cause the `TEST` to fail if the check fails. However, the = difference between the two +macro versions is that when the check fails, the `ASSERT` version immediat= ely returns from the `TEST` +while the `EXPECT` version continues running the `TEST`. + +There is no return status from a GooglTest unit test. If no assertions (or= expectations) are triggered then the unit test has a passing status. =20 +### GoogleTest - A gMock Test Case + +Below is a sample test case from `SecureBootVariableLibGoogleTest`. Althou= gh +actually, the test case is not written exactly like this in the test file,= but +more on that in a bit. + +```cpp +TEST(SetSecureBootModeTest, SetVarError) { + MockUefiRuntimeServicesTableLib RtServicesMock; + UINT8 SecureBootMode; + EFI_STATUS Status; + + // Any random magic number can be used for these tests + SecureBootMode =3D 0xAB; + + EXPECT_CALL(RtServicesMock, gRT_SetVariable) + .WillOnce(Return(EFI_INVALID_PARAMETER)); + + Status =3D SetSecureBootMode(SecureBootMode); + EXPECT_EQ(Status, EFI_INVALID_PARAMETER); +} +``` + +Keep in mind that this test is written to verify that `SetSecureBootMode()= ` will +return `EFI_INVALID_PARAMETER` when the call to `gRT->SetVariable()` withi= n the +implementation of `SetSecureBootMode()` returns `EFI_INVALID_PARAMETER`. W= ith that +in mind, let's discuss how a mock function is used to accomplish this in t= he test. + +In this test case, the `MockUefiRuntimeServicesTableLib` interface is inst= antiated as +`RtServicesMock` which enables its associated mock functions. These interf= ace +instantiations that contain the mock functions are very important for mock= function +based unit tests because without these instantiations, the mock functions = within that +interface will not exist and can not be used. + +The next line of interest is the `EXPECT_CALL`, which is a standard part o= f the gMock +framework. This macro is telling the test that a call is expected to occur= to a +specific function on a specific interface. The first argument is the name = of the +interface object that was instantiated in this test, and the second argume= nt is the +name of the mock function within that interface that is expected to be cal= led. The +`WillOnce(Return(EFI_INVALID_PARAMETER))` associated with this `EXPECT_CAL= L` states +that the `gRT_SetVariable()` function (remember from earlier in this docum= entation +that this refers to the `gRT->SetVariable()` function) will be called once= during +this test, and when it does get called, we want it to return `EFI_INVALID_= PARAMETER`. + +Once this `EXPECT_CALL` has been setup, the call to `SetSecureBootMode()` = occurs in +the test, and its return value is saved in `Status` so that it can be test= ed. Based +on the `EXPECT_CALL` that was setup earlier, when `SetSecureBootMode()` in= ternally +calls `gRT->SetVariable()`, it returns `EFI_INVALID_PARAMETER`. This value= should +then be returned by `SetSecureBootMode()`, and the +`EXPECT_EQ(Status, EFI_INVALID_PARAMETER)` verifies this is the case. + +There is much more that can be done with `EXPECT_CALL` and mock functions,= but we +will leave those details to be explained in the gMock documentation. + +Now it was mentioned earlier that this test case is not written exactly li= ke this +in the test file, and the next section describes how this test is slightly +refactored to reduce the total amount of code in the entire test suite. + +### GoogleTest - A gMock Test Case (refactored) + +The sample test case from `SecureBootVariableLibGoogleTest` in the prior s= ection is +actually written as shown below. + +```cpp +class SetSecureBootModeTest : public Test { + protected: + MockUefiRuntimeServicesTableLib RtServicesMock; + UINT8 SecureBootMode; + EFI_STATUS Status; + + void SetUp() override { + // Any random magic number can be used for these tests + SecureBootMode =3D 0xAB; + } +}; + +TEST_F(SetSecureBootModeTest, SetVarError) { + EXPECT_CALL(RtServicesMock, gRT_SetVariable) + .WillOnce(Return(EFI_INVALID_PARAMETER)); + + Status =3D SetSecureBootMode(SecureBootMode); + EXPECT_EQ(Status, EFI_INVALID_PARAMETER); +} +``` + +This code may at first seem more complicated, but you will notice that the= code +with in it is still the same. There is still a `MockUefiRuntimeServicesTab= leLib` +instantiation, there is still a `SecureBootMode` and `Status` variable def= ined, +there is still an `EXPECT_CALL`, and etc. However, the benefit of construc= ting +the test this way is that the new `TEST_F()` requires less code than the p= rior +`TEST()`. + +This is made possible by the usage of what GoogleTest calls a _test fixtur= e_. +This concept of a test fixture allows multiple tests to use (or more speci= fically +inherit from a base class) a common set of variables and initial condition= s. +Notice that using `TEST_F()` requires the first argument to be a name that= aligns +with a test fixture (in this case `SetSecureBootModeTest`), and the second +argument is the name of the test (just like in the `TEST()` macro). + +All `TEST_F()` tests that use a specific test fixture can be thought of as= having +all of that test fixture's variables automatically defined in the test as = well as +having that text fixture's `SetUp()` function called before entering the t= est. + +This means that another `TEST_F()` can be written without needing to worry= about +defining a bunch of variables or instantiating a bunch of interfaces for m= ock +functions. For example, the below test (also in `SecureBootVariableLibGoog= leTest`) +uses the same test fixture and makes use of its `RtServicesMock`, `Status`= , and +`SecureBootMode` variables. + +```cpp +TEST_F(SetSecureBootModeTest, PropogateModeToSetVar) { + EXPECT_CALL(RtServicesMock, + gRT_SetVariable( + Char16StrEq(EFI_CUSTOM_MODE_NAME), + BufferEq(&gEfiCustomModeEnableGuid, sizeof(EFI_GUID)), + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof(SecureBootMode), + BufferEq(&SecureBootMode, sizeof(SecureBootMode)))) + .WillOnce(Return(EFI_SUCCESS)); + + Status =3D SetSecureBootMode(SecureBootMode); + EXPECT_EQ(Status, EFI_SUCCESS); +} +``` + +The biggest benefit is that the `TEST_F()` code can now focus on what is b= eing +tested and not worry about any repetitive setup. There is more that can be= done +with test fixtures, but we will leave those details to be explained in the +gMock documentation. + +Now, as for what is in the above test, it is slightly more complicated tha= n the +first test. So let's explain this added complexity and what it is actually +testing. In this test, there is still an `EXPECT_CALL` for the +`gRT_SetVariable()` function. However, in this test we are stating that we +expect the input arguments passed to `gRT_SetVariable()` be specific value= s. +The order they are provided in the `EXPECT_CALL` align with the order of t= he +arguments in the `gRT_SetVariable()` function. In this case the order of t= he +`gRT_SetVariable()` arguments is as shown below. + +```cpp +IN CHAR16 *VariableName, +IN EFI_GUID *VendorGuid, +IN UINT32 Attributes, +IN UINTN DataSize, +IN VOID *Data +``` + +So in the `EXPECT_CALL` we are stating that the call to `gRT_SetVariable()` +will be made with the below input argument values. + +1. `VariableName` is equal to the `EFI_CUSTOM_MODE_NAME` string +2. `VendorGuid` is equal to the `gEfiCustomModeEnableGuid` GUID (which has= a byte length of `sizeof(EFI_GUID)`) +3. `Attributes` is equal to `EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOT= SERVICE_ACCESS` +4. `DataSize` is equal to `sizeof(SecureBootMode)` +5. `Data` is equal to `SecureBootMode` (which has a byte length of `sizeof= (SecureBootMode)`) + +If any one of these input arguments does not match in the actual call to +`gRT_SetVariable()` in the design, then the test will fail. There is much = more +that can be done with `EXPECT_CALL` and mock functions, but again we will +leave those details to be explained in the gMock documentation. + ### GoogleTest - More Complex Cases =20 To write more advanced tests, take a look at the @@ -587,7 +1503,7 @@ This mode is used by the test running plugin to aggreg= ate the results for CI tes =20 Host based Unit Tests will automatically enable coverage data. =20 -For Windows, This is primarily leverage for pipeline builds, but this can = be leveraged locally using the +For Windows, this is primarily leveraged for pipeline builds, but this can= be leveraged locally using the OpenCppCoverage windows tool to parse coverage data to cobertura xml forma= t. =20 - Windows Prerequisite @@ -607,7 +1523,7 @@ OpenCppCoverage windows tool to parse coverage data to= cobertura xml format. ``` =20 =20 -For Linux, This is primarily leveraged for pipeline builds, but this can b= e leveraged locally using the +For Linux, this is primarily leveraged for pipeline builds, but this can b= e leveraged locally using the lcov linux tool, and parsed using the lcov_cobertura python tool to parse = it to cobertura xml format. =20 - Linux Prerequisite @@ -654,8 +1570,8 @@ We will continue trying to make these as similar as po= ssible. =20 Code/Test | Location --------- | -------- -Host-Based Unit Tests for a Library/Protocol/PPI/GUID Interface | If wha= t's being tested is an interface (e.g. a library with a public header file,= like DebugLib), the test should be scoped to the parent package.
Examp= le: `MdePkg/Test/UnitTest/[Library/Protocol/Ppi/Guid]/`

A real-wor= ld example of this is the BaseSafeIntLib test in MdePkg.
`MdePkg/Test/U= nitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost.inf` -Host-Based Unit Tests for a Library/Driver (PEI/DXE/SMM) implementation = | If what's being tested is a specific implementation (e.g. BaseDebugLibSer= ialPort for DebugLib), the test should be scoped to the implementation dire= ctory itself, in a UnitTest subdirectory.

Module Example: `MdeModu= lePkg/Universal/EsrtFmpDxe/UnitTest/`
Library Example: `MdePkg/Library/= BaseMemoryLib/UnitTest/` +Host-Based Unit Tests for a Library/Protocol/PPI/GUID Interface | If wha= t's being tested is an interface (e.g. a library with a public header file,= like DebugLib) and the test is agnostic to a specific implementation, then= the test should be scoped to the parent package.
Example: `MdePkg/Test= /UnitTest/[Library/Protocol/Ppi/Guid]/`

A real-world example of th= is is the BaseSafeIntLib test in MdePkg.
`MdePkg/Test/UnitTest/Library/= BaseSafeIntLib/TestBaseSafeIntLibHost.inf` +Host-Based Unit Tests for a Library/Driver (PEI/DXE/SMM) implementation = | If what's being tested is a specific implementation (e.g. BaseDebugLibSer= ialPort for DebugLib), then the test should be scoped to the implementation= directory itself, in a UnitTest (or GoogleTest) subdirectory.

Mod= ule Example: `MdeModulePkg/Universal/EsrtFmpDxe/UnitTest/`
Library Exam= ple: `MdePkg/Library/BaseMemoryLib/UnitTest/`
Library Example (GoogleTe= st): `SecurityPkg/Library/SecureBootVariableLib/GoogleTest/` Host-Based Tests for a Functionality or Feature | If you're writing a fu= nctional test that operates at the module level (i.e. if it's more than a s= ingle file or library), the test should be located in the package-level Tes= ts directory under the HostFuncTest subdirectory.
For example, if you w= ere writing a test for the entire FMP Device Framework, you might put your = test in:
`FmpDevicePkg/Test/HostFuncTest/FmpDeviceFramework`

I= f the feature spans multiple packages, it's location should be determined b= y the package owners related to the feature. Non-Host-Based (PEI/DXE/SMM/Shell) Tests for a Functionality or Feature = | Similar to Host-Based, if the feature is in one package, should be locate= d in the `*Pkg/Test/[Shell/Dxe/Smm/Pei]Test` directory.

If the fea= ture spans multiple packages, it's location should be determined by the pac= kage owners related to the feature.

USAGE EXAMPLES
PEI Example= : MP_SERVICE_PPI. Or check MTRR configuration in a notification function. SMM Example: a test in a protocol callback function. (It is different w= ith the solution that SmmAgent+ShellApp)
DXE Example: a test in a UEFI = event call back to check SPI/SMRAM status.
Shell Example: the SMM han= dler audit test has a shell-based app that interacts with an SMM handler to= get information. The SMM paging audit test gathers information about both = DXE and SMM. And the SMM paging functional test actually forces errors into= SMM via a DXE driver. =20 @@ -713,8 +1629,19 @@ Non-Host-Based (PEI/DXE/SMM/Shell) Tests for a Functi= onality or Feature | Simi GeneralPurposeLibTest.c GeneralPurposeLibHostUnitTest.inf =20 + Mock/ + Include/ + GoogleTest/ + Library/ + MockGeneralPurposeLib.h + + Library/ + GoogleTest/ + MockGeneralPurposeLib/ + MockGeneralPurposeLib.cpp + MockGeneralPurposeLib.inf + Pkg.dsc # Standard Modules and any Target-Based Test A= pps (including in Test/) - ``` =20 ### Future Locations in Consideration --=20 2.39.1.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 (#102728): https://edk2.groups.io/g/devel/message/102728 Mute This Topic: https://groups.io/mt/98134495/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102729+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+102729+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906063; cv=none; d=zohomail.com; s=zohoarc; b=FuPguW2GsUeGFUB55VJh8uQCs/gTKs3TsSX8FidRU+t/sfUszDwm+lg0Oi8CHxn763FJz0O+LdlOISwQ2XXRyNXuwYbNKAoZL2R5tRmMCTPAtE5WZF59eOuuUvxNE+Djk2lGBFH9YVDLSB1o9zlrsxUWXJIur1rQ8CtXcwvVrTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906063; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=58W0Y0t5vJQ06F5GcqcUfAMXeuhR/NrpykD1iRYG9QE=; b=fOnh/RdepTnjPU1XIqBDDXK0YshbSNaLl1PLhhibBwiEEvYbIOYZfvlcPRpbZBSoS+5ZMeqSuLXvZsz6ycLq3E8wh6baeQGM1NDn/+5NoJWvsoZ8aK2AGZY65u3uBtI150KYZVOOJnKYjNAaNO8HfiH8BUGc1HjgXUmu+q5/1rU= 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+102729+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 1680906063251735.3211299953153; Fri, 7 Apr 2023 15:21:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0NdSYY1788612xHHIUaHHUgB; Fri, 07 Apr 2023 15:21:02 -0700 X-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 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" X-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" X-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: [edk2-devel] [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> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: 2XBjVjX2NPfAcMYoGJyvOEnyx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906062; bh=x6NhioTZnamoOcyEDT7CJB5pkh4zPvl01gAALCgAyVE=; h=Cc:Date:From:Reply-To:Subject:To; b=pF3AHBnFU4w3T9Nor/Y/zTFbeWjVKoHhUkRbFXKBAjC86xUoJKMraEv2V3AAegYmWyA gnZ950ptaGLBiryOLfXkZk19kVNMcC5VpukFjyoxIzADRRdR1iM20wCPmUl5reFIx2m0c SRR6tPOjsmeMUjwUcWTGoztMF6OQbn3WgG8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906064688100021 Content-Type: text/plain; charset="utf-8" From: Chris Johnson REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4389 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/MockUefiRun= timeServicesTableLib.h create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUef= iLib.cpp create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUef= iLib.inf create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServ= icesTableLib/MockUefiRuntimeServicesTableLib.cpp create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServ= icesTableLib/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 =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/Mock= UefiRuntimeServicesTableLib.inf diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiLib.h b/Md= ePkg/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/MockUefiRuntimeSer= vicesTableLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRunti= meServicesTableLib.h new file mode 100644 index 000000000000..afdfc6b85597 --- /dev/null +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServicesTa= bleLib.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.cp= p 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.in= f 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/MockUefiRuntimeServicesTab= leLib/MockUefiRuntimeServicesTableLib.cpp b/MdePkg/Test/Mock/Library/Google= Test/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.cpp new file mode 100644 index 000000000000..ecd1ba82366c --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/M= ockUefiRuntimeServicesTableLib.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/MockUefiRuntimeServicesTab= leLib/MockUefiRuntimeServicesTableLib.inf b/MdePkg/Test/Mock/Library/Google= Test/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf new file mode 100644 index 000000000000..7ba74d93bfc2 --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/M= ockUefiRuntimeServicesTableLib.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 --=20 2.39.1.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 (#102729): https://edk2.groups.io/g/devel/message/102729 Mute This Topic: https://groups.io/mt/98134497/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102730+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+102730+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906063; cv=none; d=zohomail.com; s=zohoarc; b=Thwq27vUTs4IWmhiGEepEJB9/oQY86KUAhz5+641l7qRnpXJwpHNeem29nTS6FESOTLkfkHvBQyD39rBnqWChr09EgawMu142XXD24BRG9WnbMjozNGwa/asL2jSxPVKcVyx82xaoiTC+0fVRsJ3sxeY7zhkzn+zHtcNU3dQe5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906063; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=uElAGYf0S1OHXfNpIxisnPaGq1rP7tOheBEndUk0+OE=; b=hsSGU6fTGp9ZK9Y2qUhFp3+eKFOEReqSRHGuaY3dHbknivLkhUC05eXmq63n5hl8pqDePhB131TwapOO1NkXG0G0kIu1N9WyLHt6FB3lf1dMHkkSuuA4faeUzCf0/zvsMv+HOWllqYJ+ZusxqV+IHS7wsWOeDSlQPNkt0GsUXa0= 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+102730+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 1680906063624302.51848678422175; Fri, 7 Apr 2023 15:21:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wkTFYY1788612xFOkI04Sw8p; Fri, 07 Apr 2023 15:21:03 -0700 X-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 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085659" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085659" X-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:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177474" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177474" X-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 , Jian J Wang , Liming Gao , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 06/12] MdeModulePkg/Library/UefiSortLib: Add GoogleTestLib example Date: Fri, 7 Apr 2023 15:20:44 -0700 Message-Id: <20230407222051.1095-7-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: HjZTww9p4lnfeQaxDxoJYJgDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906063; bh=FytwDwX0U8Xu4tAykThWpaeO4kMPNUeKrnZwZ5ffxQA=; h=Cc:Date:From:Reply-To:Subject:To; b=IwiwC2O/M6q0waSuRaeR7hpyukaOC9fKzpiiRs9GZM0qtfi0qyZ6FttfeN/RGt6dSTp ql4Z36NTa4dym949FTs3Jw9HFOlkWEN04x7pyZgiXa0O62tXoRA+IYnECM3lfg/DSeu48 BCI/iBHiQv7hBsuWKzP4ttsNcl/alTZ8dk4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906064666100019 Content-Type: text/plain; charset="utf-8" From: Chris Johnson REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4389 Cc: Jian J Wang Cc: Liming Gao Signed-off-by: Chris Johnson Reviewed-by: Oliver Smith-Denny Reviewed-by: Michael D Kinney --- .../MockUefiRuntimeServicesTableLib.inf | 4 +- .../GoogleTest/UefiSortLibGoogleTest.cpp | 61 +++++++++++++++++++ .../GoogleTest/UefiSortLibGoogleTest.inf | 31 ++++++++++ MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 6 ++ 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLib= GoogleTest.cpp create mode 100644 MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLib= GoogleTest.inf diff --git a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntim= eServicesTableLib.inf b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/Moc= kUefiRuntimeServicesTableLib.inf index e716b855a31a..15eb646d7c38 100644 --- a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServic= esTableLib.inf +++ b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServic= esTableLib.inf @@ -10,9 +10,9 @@ [Defines] INF_VERSION =3D 0x00010005 BASE_NAME =3D MockUefiRuntimeServicesTableLib FILE_GUID =3D 4EA215EE-85C1-4A0A-847F-D2A8DE20805F - MODULE_TYPE =3D UEFI_DRIVER + MODULE_TYPE =3D HOST_APPLICATION VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D UefiRuntimeServicesTableLib|HOST_APPL= ICATION + LIBRARY_CLASS =3D UefiRuntimeServicesTableLib =20 # # VALID_ARCHITECTURES =3D IA32 X64 EBC diff --git a/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleT= est.cpp b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest= .cpp new file mode 100644 index 000000000000..23f6e9cc0611 --- /dev/null +++ b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.cpp @@ -0,0 +1,61 @@ +/** @file + Unit tests for the implementation of UefiSortLib. + + Copyright (c) 2022, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +#include + +extern "C" { + #include + #include +} + +using namespace testing; + +INTN +EFIAPI +CompareUint32 ( + IN CONST VOID *Left, + IN CONST VOID *Right + ) +{ + if (*(UINT32*)Right > *(UINT32*)Left) { + return 1; + } else if (*(UINT32*)Right < *(UINT32*)Left) { + return -1; + } + + return 0; +} + +// Test PerformQuickSort() API from UefiSortLib to verify a UINT32 array +// with 9 elements in ascending order is sorted into descending order. +TEST(PerformQuickSortTest, SortUint32AscendingArray_Size9) { + CONST UINT32 ArraySize =3D 9; + UINT32 BuffActual[ArraySize]; + UINT32 BuffExpected[ArraySize]; + + for (UINT32 Index =3D 0; Index < ArraySize; Index++) { + BuffActual[Index] =3D Index + 1; + BuffExpected[Index] =3D ArraySize - Index; + } + + PerformQuickSort (BuffActual, (UINTN)ArraySize, sizeof(UINT32), (SORT_CO= MPARE)CompareUint32); + EXPECT_THAT(BuffActual, ElementsAreArray(BuffExpected, ArraySize)); +} + +// Test StringCompare() API from UefiSortLib to verify the comparison +// succeeds when the same buffer is compared with itself. +TEST(StringCompareTest, CompareSameBuffer) { + INTN RetVal; + CONST CHAR16 *Buffer =3D (CHAR16*)L"abcdefg"; + + RetVal =3D StringCompare (&Buffer, &Buffer); + EXPECT_EQ(RetVal, 0); +} + +int main(int argc, char* argv[]) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleT= est.inf b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest= .inf new file mode 100644 index 000000000000..ac5ffb3bc29d --- /dev/null +++ b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf @@ -0,0 +1,31 @@ +## @file +# Unit test suite for the UefiSortLib using Google Test +# +# Copyright (c) 2022, Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D UefiSortLibGoogleTest + FILE_GUID =3D 78FB0BEE-D0EA-4E1A-BD38-67458C8ECDEF + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D HOST_APPLICATION + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + UefiSortLibGoogleTest.cpp + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + GoogleTestLib + UefiSortLib diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test= /MdeModulePkgHostTest.dsc index c9ec835df65d..a2bbbe8adf44 100644 --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc @@ -47,3 +47,9 @@ [Components] UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf } + + MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf { + + UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + } --=20 2.39.1.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 (#102730): https://edk2.groups.io/g/devel/message/102730 Mute This Topic: https://groups.io/mt/98134498/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102731+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+102731+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906064; cv=none; d=zohomail.com; s=zohoarc; b=PCQbICpTLKkDjiUk2hxupvfoP+ue/nCSqtohqaBTZaBG0KDOyodYoGm6dF7ukc1R4dY+aO7jC4hFvDpTJ+yt6bm58h03nIfR9bvoeMIHKF8/tIk39nJ88H5reSvyWJ3Kgzs/WoeCBjq/vCBGyUtpVFiNdDwIods7PqoWAFx6lq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906064; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=vVNQrCByaOWw7Wa8Wet9Ho709Yd0idOoSRVREWjimoY=; b=T4zicH1KvEFXuErg/lmML3Ny2w6iP4TOycjlaVOJ9wn4GvEU4Vpo5VlGNrLCwP3XemG/wki4xwf++C8seVv5MdgRiKT5WLszmocNw7Upq1YunTr0WyPCvNpdUvWfPgIuWhQK5U88I1jmjE3lAf7aYVYn/+trNj5we5zxOQj6hiQ= 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+102731+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 1680906064586945.4072207912301; Fri, 7 Apr 2023 15:21:04 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hSnZYY1788612xbRLIuJJ7Z3; Fri, 07 Apr 2023 15:21:04 -0700 X-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:03 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085663" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085663" X-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:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177477" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177477" X-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:02 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Chris Johnson , Jiewen Yao , Jian J Wang , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 07/12] SecurityPkg: Add gmock example Date: Fri, 7 Apr 2023 15:20:45 -0700 Message-Id: <20230407222051.1095-8-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: 9w2b8wZFjMFOz1vf3dMII7T8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906064; bh=LK9tu6zb2NKJPLdnWAa1srtp9e8qjgzvUtvGqmumcrc=; h=Cc:Date:From:Reply-To:Subject:To; b=BHpo2VSRAG6dFW82ZJu/NzlMBAi4tP5uNTJlAgN1J53YvprjQ7JFQP3F0MdAv+NU3Sz hTXBP/UQF1t8qZUbXbPe86j0oGN0vL4o9ZWJijDy/fm8pHYfzSsmronEBL4jemHgvCyJT OWR0WVoGJZlUtX0euiR0n0ziKkyMHXTrQaw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906066115100035 Content-Type: text/plain; charset="utf-8" From: Chris Johnson REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4389 Cc: Jiewen Yao Cc: Jian J Wang Signed-off-by: Chris Johnson Acked-by: Jiewen Yao Reviewed-by: Oliver Smith-Denny Reviewed-by: Michael D Kinney --- .../SecureBootVariableLibGoogleTest.cpp | 174 ++++++++++++++++++ .../SecureBootVariableLibGoogleTest.inf | 32 ++++ .../UnitTest/MockPlatformPKProtectionLib.inf | 4 +- .../UnitTest/MockUefiLib.inf | 4 +- .../MockUefiRuntimeServicesTableLib.inf | 4 +- .../UnitTest/SecureBootVariableLibUnitTest.c | 2 +- SecurityPkg/SecurityPkg.dec | 1 + .../Library/MockPlatformPKProtectionLib.h | 28 +++ .../MockPlatformPKProtectionLib.cpp | 11 ++ .../MockPlatformPKProtectionLib.inf | 34 ++++ SecurityPkg/Test/SecurityPkgHostTest.dsc | 8 + 11 files changed, 295 insertions(+), 7 deletions(-) create mode 100644 SecurityPkg/Library/SecureBootVariableLib/GoogleTest/Se= cureBootVariableLibGoogleTest.cpp create mode 100644 SecurityPkg/Library/SecureBootVariableLib/GoogleTest/Se= cureBootVariableLibGoogleTest.inf create mode 100644 SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockPl= atformPKProtectionLib.h create mode 100644 SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPK= ProtectionLib/MockPlatformPKProtectionLib.cpp create mode 100644 SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPK= ProtectionLib/MockPlatformPKProtectionLib.inf diff --git a/SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBoo= tVariableLibGoogleTest.cpp b/SecurityPkg/Library/SecureBootVariableLib/Goog= leTest/SecureBootVariableLibGoogleTest.cpp new file mode 100644 index 000000000000..c9190c8ffd61 --- /dev/null +++ b/SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariab= leLibGoogleTest.cpp @@ -0,0 +1,174 @@ +/** @file + Unit tests for the implementation of SecureBootVariableLib. + + Copyright (c) 2022, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +#include +#include +#include + +extern "C" { + #include + #include + #include + #include + #include + #include +} + +using namespace testing; + +//////////////////////////////////////////////////////////////////////////= //// +class SetSecureBootModeTest : public Test { + protected: + MockUefiRuntimeServicesTableLib RtServicesMock; + UINT8 SecureBootMode; + EFI_STATUS Status; + + void SetUp() override { + // Any random magic number can be used for these tests + SecureBootMode =3D 0xAB; + } +}; + +// Test SetSecureBootMode() API from SecureBootVariableLib to verify the +// expected error is returned when the call to gRT->SetVariable() fails. +TEST_F(SetSecureBootModeTest, SetVarError) { + EXPECT_CALL(RtServicesMock, gRT_SetVariable) + .WillOnce(Return(EFI_INVALID_PARAMETER)); + + Status =3D SetSecureBootMode(SecureBootMode); + EXPECT_EQ(Status, EFI_INVALID_PARAMETER); +} + +// Test SetSecureBootMode() API from SecureBootVariableLib to verify the +// expected secure boot mode is written to the correct variable in the call +// to gRT->SetVariable(). +TEST_F(SetSecureBootModeTest, PropogateModeToSetVar) { + EXPECT_CALL(RtServicesMock, + gRT_SetVariable( + Char16StrEq(EFI_CUSTOM_MODE_NAME), + BufferEq(&gEfiCustomModeEnableGuid, sizeof(EFI_GUID)), + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof(SecureBootMode), + BufferEq(&SecureBootMode, sizeof(SecureBootMode)))) + .WillOnce(Return(EFI_SUCCESS)); + + Status =3D SetSecureBootMode(SecureBootMode); + EXPECT_EQ(Status, EFI_SUCCESS); +} + +//////////////////////////////////////////////////////////////////////////= //// +class GetSetupModeTest : public Test { + protected: + MockUefiRuntimeServicesTableLib RtServicesMock; + UINT8 SetupMode; + EFI_STATUS Status; + UINT8 ExpSetupMode; + + void SetUp() override { + // Any random magic number can be used for these tests + ExpSetupMode =3D 0xAB; + } +}; + +// Test GetSetupMode() API from SecureBootVariableLib to verify the expect= ed +// error is returned when the call to gRT->GetVariable() fails. +TEST_F(GetSetupModeTest, GetVarError) { + EXPECT_CALL(RtServicesMock, gRT_GetVariable) + .WillOnce(Return(EFI_INVALID_PARAMETER)); + + Status =3D GetSetupMode (&SetupMode); + EXPECT_EQ(Status, EFI_INVALID_PARAMETER); +} + +// Test GetSetupMode() API from SecureBootVariableLib to verify the expect= ed +// setup mode is returned (and with a success return code) when the mode is +// successfully read from the call to gRT->GetVariable(). +TEST_F(GetSetupModeTest, FetchModeFromGetVar) { + EXPECT_CALL(RtServicesMock, + gRT_GetVariable( + Char16StrEq(EFI_SETUP_MODE_NAME), + BufferEq(&gEfiGlobalVariableGuid, sizeof(EFI_GUID)), + _, + Pointee(Eq(sizeof(SetupMode))), + NotNull())) + .WillOnce(DoAll( + SetArgPointee<3>(sizeof(ExpSetupMode)), + SetArgBuffer<4>(&ExpSetupMode, sizeof(ExpSetupMode)), + Return(EFI_SUCCESS))); + + Status =3D GetSetupMode (&SetupMode); + ASSERT_EQ(Status, EFI_SUCCESS); + EXPECT_EQ(SetupMode, ExpSetupMode); +} + +//////////////////////////////////////////////////////////////////////////= //// +class IsSecureBootEnabledTest : public Test { + protected: + MockUefiLib UefiLibMock; + BOOLEAN Enabled; +}; + +// Test IsSecureBootEnabled() API from SecureBootVariableLib to verify FAL= SE +// is returned when the call to GetEfiGlobalVariable2() fails. +TEST_F(IsSecureBootEnabledTest, GetVarError) { + EXPECT_CALL(UefiLibMock, GetEfiGlobalVariable2) + .WillOnce(Return(EFI_ABORTED)); + + Enabled =3D IsSecureBootEnabled (); + EXPECT_EQ(Enabled, FALSE); +} + +//////////////////////////////////////////////////////////////////////////= //// +class IsSecureBootEnabledAllocTest : public IsSecureBootEnabledTest { + protected: + UINT8 *BootEnabledBuffer; + + void SetUp() override { + BootEnabledBuffer =3D (UINT8*) AllocatePool(1); + ASSERT_NE(BootEnabledBuffer, nullptr); + } +}; + +// Test IsSecureBootEnabled() API from SecureBootVariableLib to verify TRUE +// is returned when the call to GetEfiGlobalVariable2() is successful and +// returns SECURE_BOOT_MODE_ENABLE. +TEST_F(IsSecureBootEnabledAllocTest, IsEnabled) { + *BootEnabledBuffer =3D SECURE_BOOT_MODE_ENABLE; + EXPECT_CALL(UefiLibMock, + GetEfiGlobalVariable2( + Char16StrEq(EFI_SECURE_BOOT_MODE_NAME), + NotNull(), + _)) + .WillOnce(DoAll( + SetArgBuffer<1>(&BootEnabledBuffer, sizeof(VOID*)), + Return(EFI_SUCCESS))); + + Enabled =3D IsSecureBootEnabled (); + EXPECT_EQ(Enabled, TRUE); +} + +// Test IsSecureBootEnabled() API from SecureBootVariableLib to verify FAL= SE +// is returned when the call to GetEfiGlobalVariable2() is successful and +// returns SECURE_BOOT_MODE_DISABLE. +TEST_F(IsSecureBootEnabledAllocTest, IsDisabled) { + *BootEnabledBuffer =3D SECURE_BOOT_MODE_DISABLE; + EXPECT_CALL(UefiLibMock, + GetEfiGlobalVariable2( + Char16StrEq(EFI_SECURE_BOOT_MODE_NAME), + NotNull(), + _)) + .WillOnce(DoAll( + SetArgBuffer<1>(&BootEnabledBuffer, sizeof(VOID*)), + Return(EFI_SUCCESS))); + + Enabled =3D IsSecureBootEnabled (); + EXPECT_EQ(Enabled, FALSE); +} + +int main(int argc, char* argv[]) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBoo= tVariableLibGoogleTest.inf b/SecurityPkg/Library/SecureBootVariableLib/Goog= leTest/SecureBootVariableLibGoogleTest.inf new file mode 100644 index 000000000000..5503dcfa32d1 --- /dev/null +++ b/SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariab= leLibGoogleTest.inf @@ -0,0 +1,32 @@ +## @file +# Unit test suite for the SecureBootVariableLib using Google Test +# +# Copyright (c) 2022, Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D SecureBootVariableLibGoogleTest + FILE_GUID =3D C88372AB-726B-4344-A250-6C7F826C874E + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D HOST_APPLICATION + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + SecureBootVariableLibGoogleTest.cpp + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + GoogleTestLib + SecureBootVariableLib diff --git a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockPlatfor= mPKProtectionLib.inf b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/M= ockPlatformPKProtectionLib.inf index 1e19033c5a91..c927ef709958 100644 --- a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockPlatformPKProt= ectionLib.inf +++ b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockPlatformPKProt= ectionLib.inf @@ -10,9 +10,9 @@ [Defines] INF_VERSION =3D 0x00010005 BASE_NAME =3D MockPlatformPKProtectionLib FILE_GUID =3D 5FCD74D3-3965-4D56-AB83-000B9B4806A0 - MODULE_TYPE =3D DXE_DRIVER + MODULE_TYPE =3D HOST_APPLICATION VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D PlatformPKProtectionLib|HOST_APPLICAT= ION + LIBRARY_CLASS =3D PlatformPKProtectionLib =20 # # The following information is for reference only and not required by the = build tools. diff --git a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib= .inf b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib.inf index a84242ac7205..fecf46841131 100644 --- a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib.inf +++ b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib.inf @@ -18,9 +18,9 @@ [Defines] INF_VERSION =3D 0x00010005 BASE_NAME =3D MockUefiLib FILE_GUID =3D E3B7AEF9-4E55-49AF-B035-ED776C928EC6 - MODULE_TYPE =3D UEFI_DRIVER + MODULE_TYPE =3D HOST_APPLICATION VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D UefiLib|HOST_APPLICATION + LIBRARY_CLASS =3D UefiLib =20 # # VALID_ARCHITECTURES =3D IA32 X64 EBC diff --git a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiRun= timeServicesTableLib.inf b/SecurityPkg/Library/SecureBootVariableLib/UnitTe= st/MockUefiRuntimeServicesTableLib.inf index f832a93e2254..6fe04189606e 100644 --- a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiRuntimeSer= vicesTableLib.inf +++ b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiRuntimeSer= vicesTableLib.inf @@ -10,9 +10,9 @@ [Defines] INF_VERSION =3D 0x00010005 BASE_NAME =3D MockUefiRuntimeServicesTableLib FILE_GUID =3D 84CE0021-ABEE-403C-9A1B-763CCF2D40F1 - MODULE_TYPE =3D UEFI_DRIVER + MODULE_TYPE =3D HOST_APPLICATION VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D UefiRuntimeServicesTableLib|HOST_APPL= ICATION + LIBRARY_CLASS =3D UefiRuntimeServicesTableLib =20 # # VALID_ARCHITECTURES =3D IA32 X64 EBC diff --git a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootV= ariableLibUnitTest.c b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/S= ecureBootVariableLibUnitTest.c index a23135dfb016..3a92d5d83457 100644 --- a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariable= LibUnitTest.c +++ b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariable= LibUnitTest.c @@ -163,7 +163,7 @@ MockGetVariable ( return EFI_BUFFER_TOO_SMALL; } else { assert_non_null (Data); - CopyMem (Data, (VOID *)mock (), TargetSize); + CopyMem (Data, (VOID *)(UINTN)mock (), TargetSize); } =20 return EFI_SUCCESS; diff --git a/SecurityPkg/SecurityPkg.dec b/SecurityPkg/SecurityPkg.dec index 0382090f4e75..0a8042d63fe1 100644 --- a/SecurityPkg/SecurityPkg.dec +++ b/SecurityPkg/SecurityPkg.dec @@ -21,6 +21,7 @@ [Defines] =20 [Includes] Include + Test/Mock/Include =20 [LibraryClasses] ## @libraryclass Provides hash interfaces from different implementatio= ns. diff --git a/SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockPlatformP= KProtectionLib.h b/SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockPla= tformPKProtectionLib.h new file mode 100644 index 000000000000..8024f4be2975 --- /dev/null +++ b/SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockPlatformPKProtec= tionLib.h @@ -0,0 +1,28 @@ +/** @file + Google Test mocks for PlatformPKProtectionLib + + Copyright (c) 2022, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MOCK_PLATFORM_PK_PROTECTION_LIB_H_ +#define MOCK_PLATFORM_PK_PROTECTION_LIB_H_ + +#include +#include +extern "C" { +#include +#include +} + +struct MockPlatformPKProtectionLib { + MOCK_INTERFACE_DECLARATION (MockPlatformPKProtectionLib); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + DisablePKProtection, + () + ); +}; + +#endif diff --git a/SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPKProtect= ionLib/MockPlatformPKProtectionLib.cpp b/SecurityPkg/Test/Mock/Library/Goog= leTest/MockPlatformPKProtectionLib/MockPlatformPKProtectionLib.cpp new file mode 100644 index 000000000000..5ea030f6dfcf --- /dev/null +++ b/SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPKProtectionLib/= MockPlatformPKProtectionLib.cpp @@ -0,0 +1,11 @@ +/** @file + Google Test mocks for PlatformPKProtectionLib + + Copyright (c) 2022, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +#include + +MOCK_INTERFACE_DEFINITION(MockPlatformPKProtectionLib); + +MOCK_FUNCTION_DEFINITION(MockPlatformPKProtectionLib, DisablePKProtection,= 0, EFIAPI); diff --git a/SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPKProtect= ionLib/MockPlatformPKProtectionLib.inf b/SecurityPkg/Test/Mock/Library/Goog= leTest/MockPlatformPKProtectionLib/MockPlatformPKProtectionLib.inf new file mode 100644 index 000000000000..3ed638eaf74c --- /dev/null +++ b/SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPKProtectionLib/= MockPlatformPKProtectionLib.inf @@ -0,0 +1,34 @@ +## @file +# Google Test mocks for PlatformPKProtectionLib +# +# Copyright (c) 2022, Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D MockPlatformPKProtectionLib + FILE_GUID =3D C1383D85-E0ED-44E0-A0A6-125F1D78B6E9 + MODULE_TYPE =3D HOST_APPLICATION + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PlatformPKProtectionLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + MockPlatformPKProtectionLib.cpp + +[Packages] + MdePkg/MdePkg.dec + SecurityPkg/SecurityPkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + GoogleTestLib + +[BuildOptions] + MSFT:*_*_*_CC_FLAGS =3D /EHsc diff --git a/SecurityPkg/Test/SecurityPkgHostTest.dsc b/SecurityPkg/Test/Se= curityPkgHostTest.dsc index c4df01fe1b73..ad5b4fc350ea 100644 --- a/SecurityPkg/Test/SecurityPkgHostTest.dsc +++ b/SecurityPkg/Test/SecurityPkgHostTest.dsc @@ -25,6 +25,7 @@ [Components] SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiRuntimeServic= esTableLib.inf SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockPlatformPKProtect= ionLib.inf SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib.inf + SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPKProtectionLib/Moc= kPlatformPKProtectionLib.inf =20 # # Build SecurityPkg HOST_APPLICATION Tests @@ -36,3 +37,10 @@ [Components] PlatformPKProtectionLib|SecurityPkg/Library/SecureBootVariableLib/Un= itTest/MockPlatformPKProtectionLib.inf UefiLib|SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiL= ib.inf } + SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariableL= ibGoogleTest.inf { + + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/Secu= reBootVariableLib.inf + UefiRuntimeServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/Mock= UefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf + PlatformPKProtectionLib|SecurityPkg/Test/Mock/Library/GoogleTest/Moc= kPlatformPKProtectionLib/MockPlatformPKProtectionLib.inf + UefiLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.= inf + } --=20 2.39.1.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 (#102731): https://edk2.groups.io/g/devel/message/102731 Mute This Topic: https://groups.io/mt/98134499/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102732+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+102732+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906064; cv=none; d=zohomail.com; s=zohoarc; b=PLKfwyWenuCcpn69Rli/oqSUMrRkQ9vUGK6pLFLC8mXld0A5ecGAKfxUB2nYzeKjpmktMqOP9S8nT6UqquzaZsF24fw0b02Yde+CCipv8FdsCjO7M5hOSUiQ2u65+W8fRBGrhp8lKc1+p7mgYo29rC7pjQ2sEGEwN3JtFG1KY6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906064; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=PtUNjCS4v1LOn9luPey6Xhn2Nxw9/Fvs5DVhOAqUw/E=; b=NeqkTxio58jk97CFZILXKtNqmpt4QUqfczuhdZH4mkrgoasOmTim2FLwPZJd/CSQal+WWSUNn0/8jISxlZf9PQhbP8iZDveN7QcQH7I0ThpdAiMjl9MpLd+l/xXZ9rzSly+mmupLc6n8nOQj0iyC/CVcvxPNh7cMsZe0WH7cPm4= 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+102732+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 1680906064194272.4046211693327; Fri, 7 Apr 2023 15:21:04 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2oVHYY1788612xUvbt4GFiOS; Fri, 07 Apr 2023 15:21:03 -0700 X-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:03 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085665" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085665" X-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:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177480" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177480" X-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:02 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 08/12] SecurityPkg/Library/SecureBootVariableLib: Fix VS20xx 4122 errors Date: Fri, 7 Apr 2023 15:20:46 -0700 Message-Id: <20230407222051.1095-9-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: OacCvAlVIYb7af14xqqJe6Ntx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906063; bh=PpICG9Ezr+1diMph+lC76gj2EX30komAH2gWIwWwxmw=; h=Cc:Date:From:Reply-To:Subject:To; b=NDrPIZmolLTosoh6O3sUJxFL2QMkZMpSiuxGRwjRz+IC5LgE2vpCTaYp2pm/jPHC7u2 DOonZnZwMeUc+SzKdLVAV4mHdtdMaOwDLqIOliJgsN+E5+8K+evxOeLSsrPx2yadRFWMq Mrp0KCf7Gj3eU5DhlxYm7f2WBM9wXdc3nfM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906065457100032 Content-Type: text/plain; charset="utf-8" The unit test code for the SecureBootVariableLib is initializing local variable structures in their declaration from other local variables that are also initialized in their declaration. ANSI C does not allow this and error 4122 is generated on VS20xx compilers. The test cases are updated to initialize the local structure fields in C statements instead of their local variable declaration. Cc: Jiewen Yao Cc: Jian J Wang Signed-off-by: Michael D Kinney Reviewed-by: Jiewen Yao Reviewed-by: Oliver Smith-Denny --- .../UnitTest/SecureBootVariableLibUnitTest.c | 170 +++++++++--------- 1 file changed, 83 insertions(+), 87 deletions(-) diff --git a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootV= ariableLibUnitTest.c b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/S= ecureBootVariableLibUnitTest.c index 3a92d5d83457..e4cdc68bbb35 100644 --- a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariable= LibUnitTest.c +++ b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariable= LibUnitTest.c @@ -351,10 +351,10 @@ SecureBootCreateDataFromInputSimple ( UINTN SigListSize =3D 0; EFI_STATUS Status; UINT8 TestData[] =3D { 0 }; - SECURE_BOOT_CERTIFICATE_INFO KeyInfo =3D { - .Data =3D TestData, - .DataSize =3D sizeof (TestData) - }; + SECURE_BOOT_CERTIFICATE_INFO KeyInfo; + + KeyInfo.Data =3D TestData; + KeyInfo.DataSize =3D sizeof (TestData); =20 Status =3D SecureBootCreateDataFromInput (&SigListSize, &SigList, 1, &Ke= yInfo); =20 @@ -441,16 +441,12 @@ SecureBootCreateDataFromInputMultiple ( UINT8 TestData1[] =3D { 0 }; UINT8 TestData2[] =3D { 1, 2 }; EFI_STATUS Status; - SECURE_BOOT_CERTIFICATE_INFO KeyInfo[2] =3D { - { - .Data =3D TestData1, - .DataSize =3D sizeof (TestData1) - }, - { - .Data =3D TestData2, - .DataSize =3D sizeof (TestData2) - } - }; + SECURE_BOOT_CERTIFICATE_INFO KeyInfo[2]; + + KeyInfo[0].Data =3D TestData1; + KeyInfo[0].DataSize =3D sizeof (TestData1); + KeyInfo[1].Data =3D TestData2; + KeyInfo[1].DataSize =3D sizeof (TestData2); =20 Status =3D SecureBootCreateDataFromInput (&SigListSize, &SigList, 2, Key= Info); UT_ASSERT_NOT_EFI_ERROR (Status); @@ -1219,19 +1215,19 @@ SetSecureBootVariablesShouldComplete ( UINT8 PkDummy =3D 0xFE; UINT8 *Payload =3D NULL; UINTN PayloadSize =3D sizeof (DbDummy); - SECURE_BOOT_PAYLOAD_INFO PayloadInfo =3D { - .DbPtr =3D &DbDummy, - .DbSize =3D sizeof (DbDummy), - .DbxPtr =3D &DbxDummy, - .DbxSize =3D sizeof (DbxDummy), - .DbtPtr =3D &DbtDummy, - .DbtSize =3D sizeof (DbtDummy), - .KekPtr =3D &KekDummy, - .KekSize =3D sizeof (KekDummy), - .PkPtr =3D &PkDummy, - .PkSize =3D sizeof (PkDummy), - .SecureBootKeyName =3D L"Food" - }; + SECURE_BOOT_PAYLOAD_INFO PayloadInfo; + + PayloadInfo.DbPtr =3D &DbDummy; + PayloadInfo.DbSize =3D sizeof (DbDummy); + PayloadInfo.DbxPtr =3D &DbxDummy; + PayloadInfo.DbxSize =3D sizeof (DbxDummy); + PayloadInfo.DbtPtr =3D &DbtDummy; + PayloadInfo.DbtSize =3D sizeof (DbtDummy); + PayloadInfo.KekPtr =3D &KekDummy; + PayloadInfo.KekSize =3D sizeof (KekDummy); + PayloadInfo.PkPtr =3D &PkDummy; + PayloadInfo.PkSize =3D sizeof (PkDummy); + PayloadInfo.SecureBootKeyName =3D L"Food"; =20 expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME,= sizeof (EFI_SECURE_BOOT_MODE_NAME)); expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid); @@ -1385,11 +1381,11 @@ SetSecureBootVariablesShouldStopFailDBX ( UINT8 DbxDummy =3D 0xBE; UINT8 *Payload =3D NULL; UINTN PayloadSize =3D sizeof (DbxDummy); - SECURE_BOOT_PAYLOAD_INFO PayloadInfo =3D { - .DbxPtr =3D &DbxDummy, - .DbxSize =3D sizeof (DbxDummy), - .SecureBootKeyName =3D L"Fail DBX" - }; + SECURE_BOOT_PAYLOAD_INFO PayloadInfo; + + PayloadInfo.DbxPtr =3D &DbxDummy; + PayloadInfo.DbxSize =3D sizeof (DbxDummy); + PayloadInfo.SecureBootKeyName =3D L"Fail DBX"; =20 expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME,= sizeof (EFI_SECURE_BOOT_MODE_NAME)); expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid); @@ -1442,13 +1438,13 @@ SetSecureBootVariablesShouldStopFailDB ( UINT8 DbxDummy =3D 0xBE; UINT8 *Payload =3D NULL; UINTN PayloadSize =3D sizeof (DbDummy); - SECURE_BOOT_PAYLOAD_INFO PayloadInfo =3D { - .DbPtr =3D &DbDummy, - .DbSize =3D sizeof (DbDummy), - .DbxPtr =3D &DbxDummy, - .DbxSize =3D sizeof (DbxDummy), - .SecureBootKeyName =3D L"Fail DB" - }; + SECURE_BOOT_PAYLOAD_INFO PayloadInfo; + + PayloadInfo.DbPtr =3D &DbDummy; + PayloadInfo.DbSize =3D sizeof (DbDummy); + PayloadInfo.DbxPtr =3D &DbxDummy; + PayloadInfo.DbxSize =3D sizeof (DbxDummy); + PayloadInfo.SecureBootKeyName =3D L"Fail DB"; =20 expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME,= sizeof (EFI_SECURE_BOOT_MODE_NAME)); expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid); @@ -1516,15 +1512,15 @@ SetSecureBootVariablesShouldStopFailDBT ( UINT8 DbxDummy =3D 0xBE; UINT8 *Payload =3D NULL; UINTN PayloadSize =3D sizeof (DbDummy); - SECURE_BOOT_PAYLOAD_INFO PayloadInfo =3D { - .DbPtr =3D &DbDummy, - .DbSize =3D sizeof (DbDummy), - .DbxPtr =3D &DbxDummy, - .DbxSize =3D sizeof (DbxDummy), - .DbtPtr =3D &DbtDummy, - .DbtSize =3D sizeof (DbtDummy), - .SecureBootKeyName =3D L"Fail DBT" - }; + SECURE_BOOT_PAYLOAD_INFO PayloadInfo; + + PayloadInfo.DbPtr =3D &DbDummy; + PayloadInfo.DbSize =3D sizeof (DbDummy); + PayloadInfo.DbxPtr =3D &DbxDummy; + PayloadInfo.DbxSize =3D sizeof (DbxDummy); + PayloadInfo.DbtPtr =3D &DbtDummy; + PayloadInfo.DbtSize =3D sizeof (DbtDummy); + PayloadInfo.SecureBootKeyName =3D L"Fail DBT"; =20 expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME,= sizeof (EFI_SECURE_BOOT_MODE_NAME)); expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid); @@ -1608,19 +1604,19 @@ SetSecureBootVariablesShouldStopFailKEK ( UINT8 PkDummy =3D 0xFE; UINT8 *Payload =3D NULL; UINTN PayloadSize =3D sizeof (DbDummy); - SECURE_BOOT_PAYLOAD_INFO PayloadInfo =3D { - .DbPtr =3D &DbDummy, - .DbSize =3D sizeof (DbDummy), - .DbxPtr =3D &DbxDummy, - .DbxSize =3D sizeof (DbxDummy), - .DbtPtr =3D &DbtDummy, - .DbtSize =3D sizeof (DbtDummy), - .KekPtr =3D &KekDummy, - .KekSize =3D sizeof (KekDummy), - .PkPtr =3D &PkDummy, - .PkSize =3D sizeof (PkDummy), - .SecureBootKeyName =3D L"Food" - }; + SECURE_BOOT_PAYLOAD_INFO PayloadInfo; + + PayloadInfo.DbPtr =3D &DbDummy; + PayloadInfo.DbSize =3D sizeof (DbDummy); + PayloadInfo.DbxPtr =3D &DbxDummy; + PayloadInfo.DbxSize =3D sizeof (DbxDummy); + PayloadInfo.DbtPtr =3D &DbtDummy; + PayloadInfo.DbtSize =3D sizeof (DbtDummy); + PayloadInfo.KekPtr =3D &KekDummy; + PayloadInfo.KekSize =3D sizeof (KekDummy); + PayloadInfo.PkPtr =3D &PkDummy; + PayloadInfo.PkSize =3D sizeof (PkDummy); + PayloadInfo.SecureBootKeyName =3D L"Food"; =20 expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME,= sizeof (EFI_SECURE_BOOT_MODE_NAME)); expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid); @@ -1718,19 +1714,19 @@ SetSecureBootVariablesShouldStopFailPK ( UINT8 PkDummy =3D 0xFE; UINT8 *Payload =3D NULL; UINTN PayloadSize =3D sizeof (DbDummy); - SECURE_BOOT_PAYLOAD_INFO PayloadInfo =3D { - .DbPtr =3D &DbDummy, - .DbSize =3D sizeof (DbDummy), - .DbxPtr =3D &DbxDummy, - .DbxSize =3D sizeof (DbxDummy), - .DbtPtr =3D &DbtDummy, - .DbtSize =3D sizeof (DbtDummy), - .KekPtr =3D &KekDummy, - .KekSize =3D sizeof (KekDummy), - .PkPtr =3D &PkDummy, - .PkSize =3D sizeof (PkDummy), - .SecureBootKeyName =3D L"Food" - }; + SECURE_BOOT_PAYLOAD_INFO PayloadInfo; + + PayloadInfo.DbPtr =3D &DbDummy; + PayloadInfo.DbSize =3D sizeof (DbDummy); + PayloadInfo.DbxPtr =3D &DbxDummy; + PayloadInfo.DbxSize =3D sizeof (DbxDummy); + PayloadInfo.DbtPtr =3D &DbtDummy; + PayloadInfo.DbtSize =3D sizeof (DbtDummy); + PayloadInfo.KekPtr =3D &KekDummy; + PayloadInfo.KekSize =3D sizeof (KekDummy); + PayloadInfo.PkPtr =3D &PkDummy; + PayloadInfo.PkSize =3D sizeof (PkDummy); + PayloadInfo.SecureBootKeyName =3D L"Food"; =20 expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME,= sizeof (EFI_SECURE_BOOT_MODE_NAME)); expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid); @@ -1841,19 +1837,19 @@ SetSecureBootVariablesDBTOptional ( UINT8 PkDummy =3D 0xFE; UINT8 *Payload =3D NULL; UINTN PayloadSize =3D sizeof (DbDummy); - SECURE_BOOT_PAYLOAD_INFO PayloadInfo =3D { - .DbPtr =3D &DbDummy, - .DbSize =3D sizeof (DbDummy), - .DbxPtr =3D &DbxDummy, - .DbxSize =3D sizeof (DbxDummy), - .DbtPtr =3D NULL, - .DbtSize =3D 0, - .KekPtr =3D &KekDummy, - .KekSize =3D sizeof (KekDummy), - .PkPtr =3D &PkDummy, - .PkSize =3D sizeof (PkDummy), - .SecureBootKeyName =3D L"Food" - }; + SECURE_BOOT_PAYLOAD_INFO PayloadInfo; + + PayloadInfo.DbPtr =3D &DbDummy; + PayloadInfo.DbSize =3D sizeof (DbDummy); + PayloadInfo.DbxPtr =3D &DbxDummy; + PayloadInfo.DbxSize =3D sizeof (DbxDummy); + PayloadInfo.DbtPtr =3D NULL; + PayloadInfo.DbtSize =3D 0; + PayloadInfo.KekPtr =3D &KekDummy; + PayloadInfo.KekSize =3D sizeof (KekDummy); + PayloadInfo.PkPtr =3D &PkDummy; + PayloadInfo.PkSize =3D sizeof (PkDummy); + PayloadInfo.SecureBootKeyName =3D L"Food"; =20 expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME,= sizeof (EFI_SECURE_BOOT_MODE_NAME)); expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid); --=20 2.39.1.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 (#102732): https://edk2.groups.io/g/devel/message/102732 Mute This Topic: https://groups.io/mt/98134500/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102733+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+102733+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906065; cv=none; d=zohomail.com; s=zohoarc; b=f4JWaLUSfdbUvb8k+bV3SCUfq/UTAa9viBmw+cylCh7LCkksPlTKu4A1+uzTEy7+n3R+fImfLFMP8dtYWzAjsvOMaS+5oCQPyb6dK0XACrAIri/KA7b5kk/he5oqoVwSaVR3sV8TiLtcR2fR2RfRvNk6iCsbLmmIuoxoAnxfuWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906065; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=daqOMMrQDfVmZTLuVaCr7whepuTTdD18GGR7U9Slgko=; b=dow1husBT5K+JvWZhSrAYiR5E2F0qfAUSwuog+/2ArHu9/TGeqVd+ZQZCEUdpj/Qtv/HgM/jTF5f0YcxPUF9gWrMlci2QAhTuxu3DVgSeloywuEUI0UZD1P4KRLSfkG2SsGgq3g9eA0pNR76ETDWOweeINXqcktlT2WDIrbQ8ow= 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+102733+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 1680906065318912.8399196165643; Fri, 7 Apr 2023 15:21:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DOBAYY1788612x68ACjTLEWS; Fri, 07 Apr 2023 15:21:04 -0700 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.2858.1680906063445317064 for ; Fri, 07 Apr 2023 15:21:03 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085667" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085667" X-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:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177483" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177483" X-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:03 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 09/12] SecurityPkg/Library/SecureBootVariableLib: HOST_APPLICATION IA32/X64 only Date: Fri, 7 Apr 2023 15:20:47 -0700 Message-Id: <20230407222051.1095-10-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: hheGBusRMsyyyiV9U2A6wKl7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906064; bh=vqxen5sNpx8pUWW+53G1gbaHVJcfANxvvqkufFQ9cvI=; h=Cc:Date:From:Reply-To:Subject:To; b=PHZ4NFGA1y5I/YF0oRyrk9hch/hVf18L5VTA2JkzhZ+oB1rutsD49XX24Tf3RwBG4dY ZYdlAE+W8EHZ7VsLCAEMjEV38Gb9tp34pPz/tkg5auXCwxy0iSreiqljaxPVwz/SlqfpX NzgtyZxeTH+uxTMGMUvOgjOqKLkg+1iuDWk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906067308100039 Content-Type: text/plain; charset="utf-8" Update SecureBootVariableLib host-based unit test INF file to only list VALID_ARCHITECTURES of IA32 and X64 to align with all other host-based unit test INF files. The UnitTestFrameworkPkg only provides build support of host-based unit tests to OS applications for IA32 and X64. Cc: Jiewen Yao Cc: Jian J Wang Signed-off-by: Michael D Kinney Reviewed-by: Jiewen Yao Reviewed-by: Oliver Smith-Denny --- .../UnitTest/MockPlatformPKProtectionLib.inf | 2 +- .../Library/SecureBootVariableLib/UnitTest/MockUefiLib.inf | 2 +- .../UnitTest/MockUefiRuntimeServicesTableLib.inf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockPlatfor= mPKProtectionLib.inf b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/M= ockPlatformPKProtectionLib.inf index c927ef709958..3698e4fad059 100644 --- a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockPlatformPKProt= ectionLib.inf +++ b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockPlatformPKProt= ectionLib.inf @@ -17,7 +17,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] diff --git a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib= .inf b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib.inf index fecf46841131..e02d04f376da 100644 --- a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib.inf +++ b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib.inf @@ -23,7 +23,7 @@ [Defines] LIBRARY_CLASS =3D UefiLib =20 # -# VALID_ARCHITECTURES =3D IA32 X64 EBC +# VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] diff --git a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiRun= timeServicesTableLib.inf b/SecurityPkg/Library/SecureBootVariableLib/UnitTe= st/MockUefiRuntimeServicesTableLib.inf index 6fe04189606e..e59a3394d58f 100644 --- a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiRuntimeSer= vicesTableLib.inf +++ b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiRuntimeSer= vicesTableLib.inf @@ -15,7 +15,7 @@ [Defines] LIBRARY_CLASS =3D UefiRuntimeServicesTableLib =20 # -# VALID_ARCHITECTURES =3D IA32 X64 EBC +# VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] --=20 2.39.1.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 (#102733): https://edk2.groups.io/g/devel/message/102733 Mute This Topic: https://groups.io/mt/98134501/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102734+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+102734+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906065; cv=none; d=zohomail.com; s=zohoarc; b=B3ZcPKuyHM0+b+t5WR1D0q2uUTRhWr5vconjkgt2DLl9XgKIgQNaLfPOXLdwpNikGOr6czmSKEk4t5lf4x49FZcPz9k6UNGxpMS+PcI5pnGeJauvlMNRnhY04TH5iZtLzbAWF9cN7ywLndSGAwgVaR+m4TRgjB5cY3C++V5kFAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906065; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zCJ1QAVdDDKl99ufySrHwNny7RRraoBhbni4MOwRDlU=; b=WryTm3uTzXQx/mMp/96fsbOEVXW0FuWzdUI5Q6Guo1adzwPjAVeRE+2C7EidcAlTR03mva4HZdvUNt27WAdyQxXL4Lm0TV9wD2AmZywvhVLlWhYfSvmKRQ+oJPUPw+tEM9hLOkb+OS4QNnrPxVqHddgJhfkmyDL12ejChtJ8JBg= 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+102734+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 1680906065899191.34483305836523; Fri, 7 Apr 2023 15:21:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mOvZYY1788612xF8Mmnh9qC7; Fri, 07 Apr 2023 15:21:05 -0700 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.2859.1680906064108721671 for ; Fri, 07 Apr 2023 15:21:04 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085669" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085669" X-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:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177486" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177486" X-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:03 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Liming Gao , Zhiguang Liu , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 10/12] MdePkg/Library/BaseLib: HOST_APPLICATION IA32/X64 only Date: Fri, 7 Apr 2023 15:20:48 -0700 Message-Id: <20230407222051.1095-11-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: d6r8VWMn2TH3dBTXuZOBFNWqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906065; bh=hQBmpDJkoeQ2eTRV+euJIW7X2m623duL4KrLrJbm+wg=; h=Cc:Date:From:Reply-To:Subject:To; b=UE5yjbcc9acgkwkBTHozcAlPJhZVeIFnN/IYKZU5IWJhh9WpwRiLvTzsqbKOG/9GSZc pQZkHY2xCyK/nyUdJ320pFZtp/wqMDPSt28lsu/0bWYe8Ekz+WY3bYxXu6kuIppbrYjOC 9jsNOeCN2NORqyqRFeC4NQifFErYMh3fe2o= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906067992100043 Content-Type: text/plain; charset="utf-8" Update BaseLib host-based unit test INF file to only list VALID_ARCHITECTURES of IA32 and X64 to align with all other host-based unit test INF files. The UnitTestFrameworkPkg only provides build support of host-based unit tests to OS applications for IA32 and X64. Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Michael D Kinney Reviewed-by: Liming Gao Reviewed-by: Oliver Smith-Denny --- MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf b/MdePkg/Librar= y/BaseLib/UnitTestHostBaseLib.inf index 12a5cdcc0a9e..1d53f940f5d0 100644 --- a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf +++ b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf @@ -23,7 +23,7 @@ [Defines] LIBRARY_CLASS =3D UnitTestHostBaseLib|HOST_APPLICATION =20 # -# VALID_ARCHITECTURES =3D IA32 X64 EBC ARM AARCH64 RISCV64 +# VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] --=20 2.39.1.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 (#102734): https://edk2.groups.io/g/devel/message/102734 Mute This Topic: https://groups.io/mt/98134502/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102735+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+102735+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906066; cv=none; d=zohomail.com; s=zohoarc; b=Z4r6oURot9St4hvpcp76qbQKj5L7JQKzTFtyQKkQKtLtrvxWdQsrbwURim8IYp/XEVs1dZzL05Q/y2xuiO3JNGEz1GEBTlM5hOQgvLJfSmtjULNIh2LwleOjT34LK2xa+GNee9u+5vs1VXWcjgI7lxUvgO35mjNhUnfqZmNycyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906066; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=T5QGRlIXcWnj1qNJXkoToMWChYraO6CtfJv4cpJXF38=; b=jgygKIvgyR9tQmpMCWQ0ikK6Y6gLogoIRlbmLwHLGCPppR6ejqYgRacHiuIjcO7UPvQmy2gK5WMYEyGGFTvBNOo4Dfri0/8Ogi4oHl8W2iV105xvks8XbXFtFnO18dDpHAwuLO30OXGdUhvWiJ6NynH6xV1CyTj5t0bCICo9ol8= 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+102735+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 1680906066605241.7853740047084; Fri, 7 Apr 2023 15:21:06 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id j4MRYY1788612xlXVxu6d70k; Fri, 07 Apr 2023 15:21:06 -0700 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.2859.1680906064108721671 for ; Fri, 07 Apr 2023 15:21:04 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085673" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085673" X-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:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177489" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177489" X-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:03 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 11/12] MdeModulePkg: HOST_APPLICATION IA32/X64 only Date: Fri, 7 Apr 2023 15:20:49 -0700 Message-Id: <20230407222051.1095-12-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: YShmrn0RIVDUBmcw4ZgS1ebHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906066; bh=sdUTtLc6Gd6TBPNaYX4MDh1HiawS3xxMxiebWAhlq5A=; h=Cc:Date:From:Reply-To:Subject:To; b=MAUP+rVJaiXHX7PCr618f3rDkB+cyfJa9s6YFrW/iLPZOuqqRImZYt/Qrl6/UlIEvcK z5MgPl4dlmkp7kaARYZcssYaAk8Yz7PJ8Uga3T3ovi0WHCUAkAok67OJBtORlYX1F2FWJ MPjzL6KV96dTq0oTBfzOeAR0NQkn9N2oShs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906069569100049 Content-Type: text/plain; charset="utf-8" Update MdeModulePkg host-based unit test INF files to only list VALID_ARCHITECTURES of IA32 and X64 to align with all other host-based unit test INF files. The UnitTestFrameworkPkg only provides build support of host-based unit tests to OS applications for IA32 and X64. Cc: Jian J Wang Cc: Liming Gao Signed-off-by: Michael D Kinney Reviewed-by: Oliver Smith-Denny --- .../UnitTest/MockUefiRuntimeServicesTableLib.inf | 2 +- .../RuntimeDxeUnitTest/VariableLockRequestToLockUnitTest.inf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntim= eServicesTableLib.inf b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/Moc= kUefiRuntimeServicesTableLib.inf index 15eb646d7c38..24dc934f8d25 100644 --- a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServic= esTableLib.inf +++ b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServic= esTableLib.inf @@ -15,7 +15,7 @@ [Defines] LIBRARY_CLASS =3D UefiRuntimeServicesTableLib =20 # -# VALID_ARCHITECTURES =3D IA32 X64 EBC +# VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/= VariableLockRequestToLockUnitTest.inf b/MdeModulePkg/Universal/Variable/Run= timeDxe/RuntimeDxeUnitTest/VariableLockRequestToLockUnitTest.inf index 2a659d7e1370..59c743ad1fa6 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Variabl= eLockRequestToLockUnitTest.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Variabl= eLockRequestToLockUnitTest.inf @@ -15,7 +15,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] --=20 2.39.1.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 (#102735): https://edk2.groups.io/g/devel/message/102735 Mute This Topic: https://groups.io/mt/98134503/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 2 23:04:55 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+102736+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+102736+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906066; cv=none; d=zohomail.com; s=zohoarc; b=G3ZikwRZRuH9M1vdkQNbHZN7fGS8/9eEBQ6lc3wc1hwGMcxLqM/yMhG//AFiGxxfwurqqqnwx4CQCbwBFPPVTW2HUU8tZlVsTJIj2H4o1Pcv48XNKlpnPV2AqT6eDfCiarTAr0TGQcFDHukIMG8plYtaAZMfMdg6s72UqA2ABAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906066; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=WrMihjDBB6pbya04LaKmkQbJAuHtnmo440BkYpos1MU=; b=FYfXzGwHQo9+aNjSEUyjVTv1Ak8UbWdF7pD9QLbqPr+C1tPCJbIaJ2O91jwjRXrND/bH/B6SB8z9+W5XyDrUeGQ54GfZWCTgseXFZkbGhBnfrmazCp0wfM+SgEvlAWISt6QjocDxSnj8p1o94tUUDQGsAoedtWSIV1UrsE/FQxc= 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+102736+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 1680906066717679.0384361861395; Fri, 7 Apr 2023 15:21:06 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id LUO1YY1788612xez43Kz0jo1; Fri, 07 Apr 2023 15:21:06 -0700 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.2859.1680906064108721671 for ; Fri, 07 Apr 2023 15:21:04 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085676" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085676" X-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:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177492" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177492" X-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:03 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Michael Kubacki , Nate DeSimone , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 12/12] PrmPkg/Library: HOST_APPLICATION IA32/X64 only Date: Fri, 7 Apr 2023 15:20:50 -0700 Message-Id: <20230407222051.1095-13-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@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,michael.d.kinney@intel.com X-Gm-Message-State: qBd3lZL8xts0FNdeZU877IE0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906066; bh=6A7706jDbciMW05nqLpog/rLx5PE2o6iuvh3hyRSCuc=; h=Cc:Date:From:Reply-To:Subject:To; b=RC79qMHpI/ujc8W52TCj2lEuoVN2miBGY9AuO8165qY2XMQl+hx7ACexv+m3+6yR6Ge aawmTaDNo+OL5XyTbEq743u262j6BLiMwbWlLc+tm0dCb4xfacHholhNglxxeJ8AaA4IL XiYbW7X9m9xxgvvMddm+NjxouRsCQQx0akM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906067441100041 Content-Type: text/plain; charset="utf-8" Update PrmPkg host-based unit test INF files to only list VALID_ARCHITECTURES of IA32 and X64 to align with all other host-based unit test INF files. The UnitTestFrameworkPkg only provides build support of host-based unit tests to OS applications for IA32 and X64. Cc: Michael Kubacki Cc: Nate DeSimone Signed-off-by: Michael D Kinney Reviewed-by: Oliver Smith-Denny --- .../UnitTest/DxePrmContextBufferLibUnitTestHost.inf | 2 +- .../UnitTest/DxePrmModuleDiscoveryLibUnitTestHost.inf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PrmPkg/Library/DxePrmContextBufferLib/UnitTest/DxePrmContextBu= fferLibUnitTestHost.inf b/PrmPkg/Library/DxePrmContextBufferLib/UnitTest/Dx= ePrmContextBufferLibUnitTestHost.inf index 7cf6a16867d4..eefaddb10aaf 100644 --- a/PrmPkg/Library/DxePrmContextBufferLib/UnitTest/DxePrmContextBufferLib= UnitTestHost.inf +++ b/PrmPkg/Library/DxePrmContextBufferLib/UnitTest/DxePrmContextBufferLib= UnitTestHost.inf @@ -17,7 +17,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] diff --git a/PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModuleD= iscoveryLibUnitTestHost.inf b/PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitT= est/DxePrmModuleDiscoveryLibUnitTestHost.inf index 8aae1f7cd78a..fd4b44a9bf85 100644 --- a/PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModuleDiscover= yLibUnitTestHost.inf +++ b/PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModuleDiscover= yLibUnitTestHost.inf @@ -17,7 +17,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] --=20 2.39.1.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 (#102736): https://edk2.groups.io/g/devel/message/102736 Mute This Topic: https://groups.io/mt/98134504/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-