From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web10.3152.1679799080009349675 for ; Sat, 25 Mar 2023 19:51:20 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=GhU1s9II; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: jiewen.yao@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679799080; x=1711335080; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=it4AZxLGXg3lzJSwQFTzFAv3Lbf6c2Hlewe4kEAzKjY=; b=GhU1s9IIt64QtnlLiXKpDiQZSlW1uNWT31dv239/Ky+hwIGR29SF3oba THRvu3erIe95xKvExSJ0Pe7ngpgw+D6O8BSZasGb45Dp4kR4h3AViV+/G x8Dfz9u6ZYWxs8NLSv15rJlY7urUncjCyKVaH8pEEem9HJFXghmLAAw52 +0dYjvY4Xhu/b8bsmK930eW9PzjB0H3u+y0TX30vlljADAWxJC01KpUpU LIALPCTUvhQPS7RULI48QnO4w0K7DQPAOQyoIxdNWUFtIOjMPzIrb2rWt SbHq4qa7+eGt3wXhtyvUabLwL+YPC+UOPHz/M8k3IptHzrcZnK79C7mWu g==; X-IronPort-AV: E=McAfee;i="6600,9927,10660"; a="337544903" X-IronPort-AV: E=Sophos;i="5.98,291,1673942400"; d="scan'208";a="337544903" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2023 19:51:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10660"; a="683069795" X-IronPort-AV: E=Sophos;i="5.98,291,1673942400"; d="scan'208";a="683069795" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga002.jf.intel.com with ESMTP; 25 Mar 2023 19:51:19 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Sat, 25 Mar 2023 19:51:18 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21 via Frontend Transport; Sat, 25 Mar 2023 19:51:18 -0700 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (104.47.51.44) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.21; Sat, 25 Mar 2023 19:51:18 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UAbe7DKhPo9sR5kZTlgd3scr+Z3LcrjU+BArWp25Fpxo7LtSq1GD6yo+RvbZMVSOLEYokLuLEL0nkfLI2lXRox0nTaZ9ZIdKCQQ5X1keuCmez6gKuoLMnYJPfm25d3xuAjNIf5dcnKlKgGU2nocOiT6dovZ/pgH8ao6hMxIIKGZ2pYtaVPwaTKNNeNwShAvAQF1NEzOAqPLw4DWnhjTI5VfeZKjvzZ0kEvzW+QwLluuu860bTP9cLwlFPOuo0lCN25FJOOCYybTcdoCbBW7yYIiAO/8U+g1TLX71Mg+raZZmTY7ugD08PdhbyiH/4Wbx9C/QNPFQ8L5JtMLbX7BTNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ElQwHSbYiGjDQOoybfJexVJWDbH5dXTaAuJh4LS6h+k=; b=NgyE9ABSU+7fXP+TO6QmyC5591YC2q5gXoB5MjDGe91kexe2PJNVTf6Sw1oLmIhX7vERokMYWLKeX8V9oGtddgU7CkJANbtZk0B4rxCd5EldZT6EM+T2f+gxEt18UYqpksVu0B9oB+lcSbWwe7Y/NgU426iq5GpNMWvAoUyF+h9e0Cyhpk9evejMLh+NHpy807Sj0aJOd8JSghENbJuDvc7k4/C1uQV/+qomQYyBwJrhDjOr41hNjn5wv0ntt9gdC+ZFeaujlh/O2y+3/VCyxrqYdMboYwwmTCTdRq3OSEV/vZ3NdQTAOC14nu0sYASnI5PJmoGrto373j/StxU4jw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MW4PR11MB5872.namprd11.prod.outlook.com (2603:10b6:303:169::14) by CO6PR11MB5571.namprd11.prod.outlook.com (2603:10b6:5:35f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Sun, 26 Mar 2023 02:51:16 +0000 Received: from MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::c0c0:4b46:1dd4:80d6]) by MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::c0c0:4b46:1dd4:80d6%7]) with mapi id 15.20.6178.041; Sun, 26 Mar 2023 02:51:16 +0000 From: "Yao, Jiewen" To: "Kinney, Michael D" , "devel@edk2.groups.io" CC: "Johnson, Chris N" , "Wang, Jian J" Subject: Re: [Patch 07/12] SecurityPkg: Add gmock example Thread-Topic: [Patch 07/12] SecurityPkg: Add gmock example Thread-Index: AQHZX0oLNlvl+HPcFUWpyvyxNIKltK8MXQUw Date: Sun, 26 Mar 2023 02:51:16 +0000 Message-ID: References: <20230325184541.596-1-michael.d.kinney@intel.com> <20230325184541.596-8-michael.d.kinney@intel.com> In-Reply-To: <20230325184541.596-8-michael.d.kinney@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR11MB5872:EE_|CO6PR11MB5571:EE_ x-ms-office365-filtering-correlation-id: 312d6937-4394-420b-bca1-08db2da4f814 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3wLG84uRe494van+mqKDTV3HDuj6eeXo/HonLc3qJx42SI0v17Hbfx2+U123DzD6+KtusggU1IKZMJ9XW6cycV0Ro03hurHDdr70Bd5/GY2CLu54Eoi8nh3c16mVkSJkro/VwvTLcraRiozrCU3KYJGqv8/1boWSsULXgFFAmwC5YrGf34T9wFYUCQOin+/mcJq5t5wBZHrWcd0GPYRMPbygRmaZ192Lp93yRMDkSQWfNPFDMwTOEflTL2SkKCfV9gytdDWzR2402sA1/XhI7rQAlU/Abss51JPTtT3VmA/e9cNu0YSiX35IrB93iYKf98d1d7eqiwhqwQQ/FXq/vuDG2ZnE5iOD5+ibra+nqAo95eGoUv2ROdoQ/1K33Bf7glj+UP6JvdhQD2jQCEwluLiQWr8N/c7GbTYXKNvrr+a/FMVrjDkbZs2MqaK3H5oYuJosf50ZiIeUjzNPnWn93s3dXWRtRfyeLKj+BsL5o+IWrDBdG5j2ckkCW/ngchW9IOIwwX1hEhTvic5lyFn56Ry8hN8OfjdZ/xVKwKbQXC1tItXQF5il7hccbZXkGlkeVqVg9zWu4TLMdSIfDPlOs6aC3kEmca36u8MIqjMlEgA= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR11MB5872.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(366004)(136003)(376002)(39860400002)(396003)(346002)(451199021)(15650500001)(2906002)(86362001)(83380400001)(186003)(122000001)(38100700002)(38070700005)(55016003)(8936002)(52536014)(82960400001)(53546011)(5660300002)(4326008)(8676002)(64756008)(66446008)(41300700001)(76116006)(66556008)(66946007)(66476007)(30864003)(966005)(33656002)(26005)(6506007)(9686003)(316002)(110136005)(107886003)(71200400001)(478600001)(54906003)(7696005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?ttXK2r7DRlB2Vb4CP74XK2TWQfL6Lq/gUzTF2M7v1RnIx9DRh8gZWru0Or8K?= =?us-ascii?Q?lvTi/W203zjwHxM9L5JMgI6cUfGHfseDyYxpJHkKFIybCOTycQIzKEkGIfPD?= =?us-ascii?Q?AutkmJX6q1Qd6T9N6y6FDUdSSg1snhDBNrdHWx8dNHcLJ7wD2XoKNsC0tUIa?= =?us-ascii?Q?ZLS6zx9Y/2qAUcvt/cL3sqREnyLzz4kBPJoDlRHnDoX0h6npCaG026pJDI1S?= =?us-ascii?Q?V9iuZRzDtpscxY6hg+tZsKUvxA80ulqD3f3sTVkRpAcw5J1PhenIetiVY7aM?= =?us-ascii?Q?DcrxQzNQGcgQOtBt9M56XDlM2PoEk+LOf/3VZPVHnyKLY+ZluGXiaS9XxdbB?= =?us-ascii?Q?qIKtfg8YxRcR4/c+jEbfMqbv6TjFSJmz5M5VAHsapj1lKDAYiZcVcwF8QhZB?= =?us-ascii?Q?FoGjg5M+ZDmtQX9N40GCQcVkv+B8owTFYqBDgl0PztA8bcRbFh0ur4AokrT4?= =?us-ascii?Q?fseS4uRjHj43b+2B3ymIAl0gcqyOqZ9+/Oyx27+v2lsWSaktb4KoItjPvDmK?= =?us-ascii?Q?4XVSk2TsxJ4EeV4CHjyqsAndmZMk/2Hxm31sAytDD60SeA1trj7GZDL2rTI9?= =?us-ascii?Q?7uOvobAdj82kcFR9wvcpSSViHnt4RJpG8ETTbmGhlrz/u1/GjQBkMDYaKzLF?= =?us-ascii?Q?z0rmKFmV0sYPa3rb48UCrpVEs63VACV/M2SPK/NCtb/Bcb2ramTvzmNji1HL?= =?us-ascii?Q?hva6kXFyB7yg8a7UlPWvZXSD/TnUbZcE6Y35e9YrsbZq9P/qoxTxOpWWUXns?= =?us-ascii?Q?FC59aSy4IGdfu/mUG2fIKYio627JZ67VEqp9KTJ8BO8+aMKdcbQOsVzawRP0?= =?us-ascii?Q?929eGELj7JETMNXzGigXUlapwQgObm4OVyqq+9SWDMaaQwtCKooRSXG9eu31?= =?us-ascii?Q?IztHrJopt9P/m9Bkn8du8eB+l6AXTc4tek4MvhRXli/wxy2rZJYv69KGEqD/?= =?us-ascii?Q?FqQ1Jxvdlj401/USehOApq3oVPaF1SufWDO+I+m4IZEaULxhzGo1fJ6BIBAX?= =?us-ascii?Q?PhNvhKUQeYfG6rwvrxSuJ9grFMOwLKACqMw5OWWkbbDxTEmG3GY7dUq7MMXW?= =?us-ascii?Q?8LjTK9Pd3nX8yCxaa3L6yWnTFG0S5UptTR/dK11FShjFEkCflqHLG8DGROSU?= =?us-ascii?Q?2J9OFpz2yqdeAUSsYmY6Ip0XITPy1k4v2spJr3fJZlxpXqiuzvNWx8yVDQOn?= =?us-ascii?Q?U8L/ymUQZ2dK4RMNjJczN6lMk6Y2onKXkVN17lpdsry1dV/0dgDTr8+93Fkb?= =?us-ascii?Q?aZbmZEn7l0fteLhdmOZfhqWOt25/9BVXtje03KXXvMhZ12fHaXFcfJNauaWw?= =?us-ascii?Q?MNZ7A4DToVLbwtXu2m6zHqBCW+BVDBaWrJBmiF3zSh7DSoF6fZKaP5m/isgG?= =?us-ascii?Q?+BKSQ5TxwOkS//FF3rSSTd080cwlVyrgd7XxkB7KVfmRMVz1pHdP7ZXhqDFn?= =?us-ascii?Q?qyafKumDizjS8idLCR3m9gwgsX82Ilp4Vpgr5F9Ci+xWYUMClHfD/INnmD0G?= =?us-ascii?Q?KPPfPmLFZjCq8ardePnTCMrNMn3uI7jdU8g8c7tj/pe2VucZ3bGFHtaxKmVT?= =?us-ascii?Q?LiaEe77uFmd2OR4nRZvSKigf9OFkW4UJVNsocdgP?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR11MB5872.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 312d6937-4394-420b-bca1-08db2da4f814 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Mar 2023 02:51:16.2739 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: TB5Ezp0LdIg08zu3TtJz5td+itfpXmlUq68CfTXWQqrsmf+9b98Ov/r/5SUMeA4wmDNUVZzO1oZcx6+DblvUyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR11MB5571 Return-Path: jiewen.yao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Acked-by: Jiewen Yao > -----Original Message----- > From: Kinney, Michael D > Sent: Sunday, March 26, 2023 2:46 AM > To: devel@edk2.groups.io > Cc: Johnson, Chris N ; Yao, Jiewen > ; Wang, Jian J > Subject: [Patch 07/12] SecurityPkg: Add gmock example >=20 > From: Chris Johnson >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4389 >=20 > Cc: Jiewen Yao > Cc: Jian J Wang > Signed-off-by: Chris Johnson > --- > .../SecureBootVariableLibGoogleTest.cpp | 156 ++++++++++++++++++ > .../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, 277 insertions(+), 7 deletions(-) > create mode 100644 > SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariable > LibGoogleTest.cpp > create mode 100644 > SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariable > LibGoogleTest.inf > create mode 100644 > SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockPlatformPKProtect > ionLib.h > create mode 100644 > SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPKProtectionLib/ > MockPlatformPKProtectionLib.cpp > create mode 100644 > SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPKProtectionLib/ > MockPlatformPKProtectionLib.inf >=20 > diff --git > a/SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariab > leLibGoogleTest.cpp > b/SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariab > leLibGoogleTest.cpp > new file mode 100644 > index 000000000000..f9a0ab35e4da > --- /dev/null > +++ > b/SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariab > leLibGoogleTest.cpp > @@ -0,0 +1,156 @@ > +/** @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_F(SetSecureBootModeTest, SetVarError) { > + EXPECT_CALL(RtServicesMock, gRT_SetVariable) > + .WillOnce(Return(EFI_INVALID_PARAMETER)); > + > + Status =3D SetSecureBootMode(SecureBootMode); > + EXPECT_EQ(Status, EFI_INVALID_PARAMETER); > +} > + > +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_F(GetSetupModeTest, GetVarError) { > + EXPECT_CALL(RtServicesMock, gRT_GetVariable) > + .WillOnce(Return(EFI_INVALID_PARAMETER)); > + > + Status =3D GetSetupMode (&SetupMode); > + EXPECT_EQ(Status, EFI_INVALID_PARAMETER); > +} > + > +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_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_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_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/SecureBootVariab > leLibGoogleTest.inf > b/SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariab > leLibGoogleTest.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 th= e > 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/MockPlatformPKProt > ectionLib.inf > b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockPlatformPKProt > ectionLib.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-000B9B4806A= 0 > - MODULE_TYPE =3D DXE_DRIVER > + MODULE_TYPE =3D HOST_APPLICATION > VERSION_STRING =3D 1.0 > - LIBRARY_CLASS =3D PlatformPKProtectionLib|HOST_APPLIC= ATION > + LIBRARY_CLASS =3D PlatformPKProtectionLib >=20 > # > # The following information is for reference only and not required by th= e > 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-ED776C928EC= 6 > - 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/MockUefiRuntimeSer > vicesTableLib.inf > b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiRuntimeSer > vicesTableLib.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-763CCF2D40F= 1 > - MODULE_TYPE =3D UEFI_DRIVER > + MODULE_TYPE =3D HOST_APPLICATION > VERSION_STRING =3D 1.0 > - LIBRARY_CLASS =3D > UefiRuntimeServicesTableLib|HOST_APPLICATION > + LIBRARY_CLASS =3D UefiRuntimeServicesTableLib >=20 > # > # VALID_ARCHITECTURES =3D IA32 X64 EBC > diff --git > a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariableLi > bUnitTest.c > b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariableLi > bUnitTest.c > index a23135dfb016..3a92d5d83457 100644 > --- > a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariableLi > bUnitTest.c > +++ > b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariableLi > bUnitTest.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 implementat= ions. > diff --git > a/SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockPlatformPKProt > ectionLib.h > b/SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockPlatformPKProt > ectionLib.h > new file mode 100644 > index 000000000000..8024f4be2975 > --- /dev/null > +++ > b/SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockPlatformPKProt > ectionLib.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/MockPlatformPKProtectionLib > /MockPlatformPKProtectionLib.cpp > b/SecurityPkg/Test/Mock/Library/GoogleTest/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/MockPlatformPKProtectionLib > /MockPlatformPKProtectionLib.inf > b/SecurityPkg/Test/Mock/Library/GoogleTest/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-125F1D78B6E= 9 > + 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 th= e > 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/SecurityPkgHostTest.dsc > index c4df01fe1b73..ad5b4fc350ea 100644 > --- a/SecurityPkg/Test/SecurityPkgHostTest.dsc > +++ b/SecurityPkg/Test/SecurityPkgHostTest.dsc > @@ -25,6 +25,7 @@ [Components] >=20 > SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiRuntimeServi > cesTableLib.inf >=20 > SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockPlatformPKProtec > tionLib.inf > SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib.inf > + > SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPKProtectionLib/ > MockPlatformPKProtectionLib.inf >=20 > # > # Build SecurityPkg HOST_APPLICATION Tests > @@ -36,3 +37,10 @@ [Components] >=20 > PlatformPKProtectionLib|SecurityPkg/Library/SecureBootVariableLib/UnitTe > st/MockPlatformPKProtectionLib.inf >=20 > UefiLib|SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib.in > f > } > + > SecurityPkg/Library/SecureBootVariableLib/GoogleTest/SecureBootVariable > LibGoogleTest.inf { > + > + > SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureB > ootVariableLib.inf > + > UefiRuntimeServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/Mock > UefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf > + > PlatformPKProtectionLib|SecurityPkg/Test/Mock/Library/GoogleTest/MockP > latformPKProtectionLib/MockPlatformPKProtectionLib.inf > + > UefiLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.i > nf > + } > -- > 2.39.1.windows.1