From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web11.2841.1607665396817896455 for ; Thu, 10 Dec 2020 21:43:16 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=bDB2nvFm; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: hao.a.wu@intel.com) IronPort-SDR: 1XNNEx6TfNZ064RM8L1e1oZZNLp+aU+8oSEhM0bgO3F1zWS6len6bkaHrxl5qB3+yymvHovP/4 7NMGNiOsboxw== X-IronPort-AV: E=McAfee;i="6000,8403,9831"; a="192718698" X-IronPort-AV: E=Sophos;i="5.78,410,1599548400"; d="scan'208";a="192718698" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2020 21:43:16 -0800 IronPort-SDR: CEX2/3ul+VfB8hAsYYpy/qk0k9Lg4M9b1+oiKVndLkRf90JKEYwZmT8uj7rg6G0PX3x5v0Zuub nBMAw1s9jSag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,410,1599548400"; d="scan'208";a="370879243" Received: from orsmsx605.amr.corp.intel.com ([10.22.229.18]) by fmsmga004.fm.intel.com with ESMTP; 10 Dec 2020 21:43:16 -0800 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 10 Dec 2020 21:43:15 -0800 Received: from orsmsx602.amr.corp.intel.com (10.22.229.15) by ORSMSX607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 10 Dec 2020 21:43:15 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Thu, 10 Dec 2020 21:43:15 -0800 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.177) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Thu, 10 Dec 2020 21:43:14 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kVcrgVHYMQM3/acsohJMUWskocFHbBtGC9VYbmRRuHFDtNpb6wSST5Uj9n9Rk7cUh2FtGe320WD8Q/cjT6Mwc2b0pF/EarnT2PBzZIqdt8kGCYdDlMqsTcr+YVxbNmVLwVfRRLG1RbWW8o0WxvWJIeUPPGiM5VMoNf7DxQLrIQDk5mEXiE5WbQS/DPW0KXJKT0m2Df2rb9ZMWTtG02vijlRbaUEAk4eYFxpQXFQfeHtRFyiviv1kU2p1D13qnMJAmYxqEa4C7Ry5WBvmRhS8twXAfQgkdYf30bTPACh1osHgQBuPodccwXiZirkcz3MSkRLXSxQqli3608zcU8Oq1w== 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-SenderADCheck; bh=8Z57ckq7ri3TxGQQuwFA6Ptt30oEQPEh2jIafv7yR1w=; b=Fzc2hhvu/+qKg885XBv5lTZPzC6+/p74y1wmf7UmBTL1EV0kgSDKmeZPNq+HYiCwWJ4dFek3qW+vTVD3f56YDmbNY2m1g/8gEcvuqMg+OBBSFy/ofk+df/f/omIZLUdrIv1bFn7maTgjVgTeKep7gXow2rOTP1bydPZGWt4wz9zekiPUFYoCg45pxKmfPDmcowgW2TTHH5uRGmaVHPXW1R87N3NKfUtlzrJHVPQsiJrVrz7tjoVVsCH9zIdoUTfH1ixKdUVCRVF5Hcd+C/2OeuWtdNzuQirV/pJsJ57mZL8cL3lWBTnA9bxm0gxQEVEsX9eIqlOduFoa/59HeJ7SyQ== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8Z57ckq7ri3TxGQQuwFA6Ptt30oEQPEh2jIafv7yR1w=; b=bDB2nvFms/jz98CyeeqTONvvN5NrC43yG85QozBSnhW4znxfXPw3hUiejLYAUOl2ARLMw4MeTWytIAWPgF38/JEVqAc0gq1lRivgQF5uMAqN4zeqUNMfZ/wP3kl/xeVQjgbuteV3TAp2S91Kszix5HXFNqRC3VLU1/FMalPyIzY= Received: from BN8PR11MB3666.namprd11.prod.outlook.com (2603:10b6:408:8c::19) by BN6PR11MB1473.namprd11.prod.outlook.com (2603:10b6:405:a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.15; Fri, 11 Dec 2020 05:43:13 +0000 Received: from BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::4cda:993f:ffc1:f169]) by BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::4cda:993f:ffc1:f169%6]) with mapi id 15.20.3654.014; Fri, 11 Dec 2020 05:43:13 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "Kinney, Michael D" CC: Liming Gao , Bret Barkelew Subject: Re: [edk2-devel] [Patch v3 2/2] MdeModulePkg/Variable/RuntimeDxe: Add Variable Lock Protocol Unit Tests Thread-Topic: [edk2-devel] [Patch v3 2/2] MdeModulePkg/Variable/RuntimeDxe: Add Variable Lock Protocol Unit Tests Thread-Index: AQHWz3lq6DjZvaAG+Ui/n/bZng8H4anxYXog Date: Fri, 11 Dec 2020 05:43:13 +0000 Message-ID: References: <20201211045156.1758-1-michael.d.kinney@intel.com> <20201211045156.1758-3-michael.d.kinney@intel.com> In-Reply-To: <20201211045156.1758-3-michael.d.kinney@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.218] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1fefd528-0fa7-447f-034d-08d89d97a68a x-ms-traffictypediagnostic: BN6PR11MB1473: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: BwZHai97ZnUmLFydvRm5DIXz7XoJtljnXnZxmEyZgEjdU1w9q2xpvsqrkzyB46Zm33v9j9uvxVNbXeCwuwYKdU4cllEmKGAqIxr+EaOxem/uSk5M3MBN0HEpabN1bYoeJSN3hgXcLLInUbI8/bbnUuGkJGfIz3fag9thPiMnnOhtuEihTZ8cjW6SypDgo/UEYda/+0tprgDKrFkzPS2IE+SJVRrSqzBZj5av9+kHa9KHwOnwjH9f97pEs6hVBZ3DwvrQ5elgziWFj4oSJpVeHF76wlWczbtxDYQkBFY8Ubw2he3A6Gy4bLjUHR84HOt2+rwV1oK3VOFdvcL6LGb3sSPbju1oRMDBGG103X3RDVqLZqUR+G6c7kpTpiJyWsMLZ2c0IwgloESl6WVzaArNJg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR11MB3666.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(366004)(346002)(33656002)(9686003)(186003)(26005)(55016002)(45080400002)(53546011)(508600001)(6506007)(8676002)(30864003)(4326008)(52536014)(6636002)(8936002)(66946007)(66446008)(64756008)(66556008)(66476007)(86362001)(5660300002)(7696005)(2906002)(966005)(110136005)(83380400001)(54906003)(76116006)(71200400001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?x1zrMh2ozxWNvCLfV0kWQJH48QM8559s9MBQJyPEnFDJoWmdrSBpxQ/Q07ei?= =?us-ascii?Q?2RayK4AvushArXFqzmWFzP3gFgmKfof5jQF2H87Rz4zYdKEdwvuT3G1qEXkI?= =?us-ascii?Q?JfEKi8GCZRYzXX4SAJiELGp5HsGnvuZENfvffAb6rO/lcpkIRvn1saDQ8kR1?= =?us-ascii?Q?hUHGoeJroZ+p2onhiMLS6tX9e6o57iSX06sezuB5IwO8vrTW+iky6BWvyviO?= =?us-ascii?Q?DOsiGtkr8wZAc6UOzoJQ1KGCVYs/YmP1bx4ibGNCVF3qCoSDLQABRYGge8jl?= =?us-ascii?Q?KcH0MF3WrkMJkx9ty++aUYdapVgUNPvgKMMr3W8reeI1aFc4eQRj9XrpzASF?= =?us-ascii?Q?C7/BeUoAal6EN+apsTJIH7//xIp7wDLDdkHun/FJfAxXh6NhmAwDus5J6vvR?= =?us-ascii?Q?9KZpcF0XZVWT4T0QgvGBeU4/RcXromKJW1rTP0KNsYvwXsjflkTC5fuSACtQ?= =?us-ascii?Q?q22c62UP2ar9Vm7zDSCVYcyB9HZS5TCpAsAZm8ORHq11L9DGeLVuFht6lOf9?= =?us-ascii?Q?ATA1i9rkMv6w6IXgXM+OVgdtKOQdOu0qmrqUdooDpFFtEZDh2YY+edjaP3Qn?= =?us-ascii?Q?Wk5QNSxuZz4qfXtn6wRQC0EvLBFdjSn2M2T6QNWi3ZNLqmwKMwod/De2zrR9?= =?us-ascii?Q?fAHwM5WbQyibcGlR0XV+tK/u2MyUSgOjfhimGcdaSUvgDjfr5eaab8PG8K/m?= =?us-ascii?Q?IygTe3HudBGDj1ev9NSrKyIOCVdfoTtvJwYbr2mm8SF4qA7zqjdK+ml0Xxo/?= =?us-ascii?Q?wLQ4ioomOWZTG86f15boSx69ajsBqMjGgXCUxXw5A2mRclnRMbIECugbogdA?= =?us-ascii?Q?IlEAYKrJ62OzB80PKvAPZ7qlLH9/VRmuAO+BRW9dh+QySosJFNATVNAi/Vjn?= =?us-ascii?Q?BEIxrb3/jWD+xdkDmIohgz8j57kj8+bVUMwSz9xkp1hUWVjAeMN9rzk5g4o0?= =?us-ascii?Q?wcjMQgfiPvzMV+QubjTB191Uz6aYzfxmCM1vPk7TPQa9QdWrKiKst8SA9vW+?= =?us-ascii?Q?TZLP?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN8PR11MB3666.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1fefd528-0fa7-447f-034d-08d89d97a68a X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Dec 2020 05:43:13.1201 (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: d0NL6c9iOyjtujyfoQvr2Y10X2eB+1eXwoV3zhPnQ1CzsovmvIrLQHeWXVo5DTfu4Egm8YWr4nDNtX0AXuztfQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB1473 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable With below typos fixed: "Procol" -> "Protocol" "succced" -> "succeed" Reviewed-by: Hao A Wu Best Regards, Hao Wu > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Michael > D Kinney > Sent: Friday, December 11, 2020 12:52 PM > To: devel@edk2.groups.io > Cc: Wu, Hao A ; Liming Gao > ; Bret Barkelew > > Subject: [edk2-devel] [Patch v3 2/2] MdeModulePkg/Variable/RuntimeDxe: > Add Variable Lock Protocol Unit Tests >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D3111 >=20 > Add host based unit tests for the multiple lock case using Variable Lock > Protocol, Variable Policy Protocol, and mixes of Variable Lock Protocol = and > Variable Policy Protocol. >=20 > Cc: Michael D Kinney > Cc: Hao A Wu > Cc: Liming Gao > Signed-off-by: Bret Barkelew > --- > MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 11 + > .../VariableLockRequestToLockUnitTest.c | 565 ++++++++++++++++++ > .../VariableLockRequestToLockUnitTest.inf | 36 ++ > 3 files changed, 612 insertions(+) > create mode 100644 > MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Vari > ableLockRequestToLockUnitTest.c > create mode 100644 > MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Vari > ableLockRequestToLockUnitTest.inf >=20 > diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc > b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc > index 72a119db4568..4da4692c8451 100644 > --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc > +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc > @@ -19,6 +19,9 @@ [Defines] >=20 > !include UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc >=20 > +[LibraryClasses] > + SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf > + > [Components] >=20 > MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeSer > vicesTableLib.inf >=20 > @@ -30,3 +33,11 @@ [Components] >=20 > ResetSystemLib|MdeModulePkg/Library/DxeResetSystemLib/DxeResetSyst > emLib.inf >=20 > UefiRuntimeServicesTableLib|MdeModulePkg/Library/DxeResetSystemLib/ > UnitTest/MockUefiRuntimeServicesTableLib.inf > } > + > + > MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Vari > ableLockRequestToLockUnitTest.inf { > + > + > VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyL= i > b.inf > + > VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/Va > riablePolicyHelperLib.inf > + > + > + > gEfiMdeModulePkgTokenSpaceGuid.PcdAllowVariablePolicyEnforcementDis > abl > + e|TRUE > + } > diff --git > a/MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Va > riableLockRequestToLockUnitTest.c > b/MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Va > riableLockRequestToLockUnitTest.c > new file mode 100644 > index 000000000000..a5bf720f42e1 > --- /dev/null > +++ > b/MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Va > ri > +++ ableLockRequestToLockUnitTest.c > @@ -0,0 +1,565 @@ > +/** @file > + This is a host-based unit test for the VariableLockRequestToLock shim= . > + > + Copyright (c) Microsoft Corporation. > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include #include > + #include #include > + > + > +#include > + > +#define UNIT_TEST_NAME "VarPol/VarLock Shim Unit Test" > +#define UNIT_TEST_VERSION "1.0" > + > +///=3D=3D=3D CODE UNDER TEST > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +=3D=3D=3D=3D > + > +EFI_STATUS > +EFIAPI > +VariableLockRequestToLock ( > + IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This, > + IN CHAR16 *VariableName, > + IN EFI_GUID *VendorGuid > + ); > + > +///=3D=3D=3D TEST DATA > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > + > +// > +// Test GUID 1 {F955BA2D-4A2C-480C-BFD1-3CC522610592} > +// > +EFI_GUID mTestGuid1 =3D { > + 0xf955ba2d, 0x4a2c, 0x480c, {0xbf, 0xd1, 0x3c, 0xc5, 0x22, 0x61, 0x5, > +0x92} }; > + > +// > +// Test GUID 2 {2DEA799E-5E73-43B9-870E-C945CE82AF3A} > +// > +EFI_GUID mTestGuid2 =3D { > + 0x2dea799e, 0x5e73, 0x43b9, {0x87, 0xe, 0xc9, 0x45, 0xce, 0x82, 0xaf, > +0x3a} }; > + > +// > +// Test GUID 3 {698A2BFD-A616-482D-B88C-7100BD6682A9} > +// > +EFI_GUID mTestGuid3 =3D { > + 0x698a2bfd, 0xa616, 0x482d, {0xb8, 0x8c, 0x71, 0x0, 0xbd, 0x66, 0x82, > +0xa9} }; > + > +#define TEST_VAR_1_NAME L"TestVar1" > +#define TEST_VAR_2_NAME L"TestVar2" > +#define TEST_VAR_3_NAME L"TestVar3" > + > +#define TEST_POLICY_ATTRIBUTES_NULL 0 > +#define TEST_POLICY_MIN_SIZE_NULL 0 > +#define TEST_POLICY_MAX_SIZE_NULL MAX_UINT32 > + > +#define TEST_POLICY_MIN_SIZE_10 10 > +#define TEST_POLICY_MAX_SIZE_200 200 > + > +///=3D=3D=3D HELPER FUNCTIONS > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +=3D=3D=3D=3D > + > +/** > + Mocked version of GetVariable, for testing. > + > + @param VariableName > + @param VendorGuid > + @param Attributes > + @param DataSize > + @param Data > +**/ > +EFI_STATUS > +EFIAPI > +StubGetVariableNull ( > + IN CHAR16 *VariableName, > + IN EFI_GUID *VendorGuid, > + OUT UINT32 *Attributes, OPTIONAL > + IN OUT UINTN *DataSize, > + OUT VOID *Data OPTIONAL > + ) > +{ > + UINT32 MockedAttr; > + UINTN MockedDataSize; > + VOID *MockedData; > + EFI_STATUS MockedReturn; > + > + check_expected_ptr (VariableName); > + check_expected_ptr (VendorGuid); > + check_expected_ptr (DataSize); > + > + MockedAttr =3D (UINT32)mock(); > + MockedDataSize =3D (UINTN)mock(); > + MockedData =3D (VOID*)(UINTN)mock(); > + MockedReturn =3D (EFI_STATUS)mock(); > + > + if (Attributes !=3D NULL) { > + *Attributes =3D MockedAttr; > + } > + if (Data !=3D NULL && !EFI_ERROR (MockedReturn)) { > + CopyMem (Data, MockedData, MockedDataSize); } > + > + *DataSize =3D MockedDataSize; > + > + return MockedReturn; > +} > + > +// > +// Anything you think might be helpful that isn't a test itself. > +// > + > +/** > + This is a common setup function that will ensure the library is > +always > + initialized with the stubbed GetVariable. > + > + Not used by all test cases, but by most. > + > + @param[in] Context Unit test case context **/ STATIC > +UNIT_TEST_STATUS EFIAPI LibInitMocked ( > + IN UNIT_TEST_CONTEXT Context > + ) > +{ > + return EFI_ERROR (InitVariablePolicyLib (StubGetVariableNull)) ? > +UNIT_TEST_ERROR_PREREQUISITE_NOT_MET : UNIT_TEST_PASSED; } > + > +/** > + Common cleanup function to make sure that the library is always > +de-initialized > + prior to the next test case. > + > + @param[in] Context Unit test case context **/ STATIC VOID EFIAPI > +LibCleanup ( > + IN UNIT_TEST_CONTEXT Context > + ) > +{ > + DeinitVariablePolicyLib(); > +} > + > +///=3D=3D=3D TEST CASES > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > + > +///=3D=3D=3D=3D=3D SHIM SUITE > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D > + > +/** > + Test Case that locks a single variable using the Variable Lock Protoc= ol. > + The call is expected to succeed. > + > + @param[in] Context Unit test case context **/ UNIT_TEST_STATUS > +EFIAPI LockingWithoutAnyPoliciesShouldSucceed ( > + IN UNIT_TEST_CONTEXT Context > + ) > +{ > + EFI_STATUS Status; > + > + Status =3D VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, > + &mTestGuid1); UT_ASSERT_NOT_EFI_ERROR (Status); > + > + return UNIT_TEST_PASSED; > +} > + > +/** > + Test Case that locks the same variable twice using the Variable Lock = Procol. > + Both calls are expected to succeed. > + > + @param[in] Context Unit test case context > + **/ > +UNIT_TEST_STATUS > +EFIAPI > +LockingTwiceShouldSucceed ( > + IN UNIT_TEST_CONTEXT Context > + ) > +{ > + EFI_STATUS Status; > + > + Status =3D VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, > + &mTestGuid1); UT_ASSERT_NOT_EFI_ERROR (Status); > + > + Status =3D VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, > + &mTestGuid1); UT_ASSERT_NOT_EFI_ERROR (Status); > + > + return UNIT_TEST_PASSED; > +} > + > +/** > + Test Case that locks a variable using the Variable Policy Protocol > +then locks > + the same variable using the Variable Lock Protocol. > + Both calls are expected to succeed. > + > + @param[in] Context Unit test case context > + **/ > +UNIT_TEST_STATUS > +EFIAPI > +LockingALockedVariableShouldSucceed ( > + IN UNIT_TEST_CONTEXT Context > + ) > +{ > + EFI_STATUS Status; > + VARIABLE_POLICY_ENTRY *NewEntry; > + > + // > + // Create a variable policy that locks the variable. > + // > + Status =3D CreateBasicVariablePolicy ( > + &mTestGuid1, > + TEST_VAR_1_NAME, > + TEST_POLICY_MIN_SIZE_NULL, > + TEST_POLICY_MAX_SIZE_200, > + TEST_POLICY_ATTRIBUTES_NULL, > + TEST_POLICY_ATTRIBUTES_NULL, > + VARIABLE_POLICY_TYPE_LOCK_NOW, > + &NewEntry > + ); > + UT_ASSERT_NOT_EFI_ERROR (Status); > + > + // > + // Register the new policy. > + // > + Status =3D RegisterVariablePolicy (NewEntry); > + > + Status =3D VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, > + &mTestGuid1); UT_ASSERT_NOT_EFI_ERROR (Status); > + > + FreePool (NewEntry); > + > + return UNIT_TEST_PASSED; > +} > + > +/** > + Test Case that locks a variable using the Variable Policy Protocol > +with a > + policy other than LOCK_NOW then attempts to lock the same variable > +using the > + Variable Lock Protocol. The call to Variable Policy is expected to > +succced > + and the call to Variable Lock is expected to fail. > + > + @param[in] Context Unit test case context > + **/ > +UNIT_TEST_STATUS > +EFIAPI > +LockingAnUnlockedVariableShouldFail ( > + IN UNIT_TEST_CONTEXT Context > + ) > +{ > + EFI_STATUS Status; > + VARIABLE_POLICY_ENTRY *NewEntry; > + > + // Create a variable policy that locks the variable. > + Status =3D CreateVarStateVariablePolicy (&mTestGuid1, > + TEST_VAR_1_NAME, > + TEST_POLICY_MIN_SIZE_NULL, > + TEST_POLICY_MAX_SIZE_200, > + TEST_POLICY_ATTRIBUTES_NULL, > + TEST_POLICY_ATTRIBUTES_NULL, > + &mTestGuid2, > + 1, > + TEST_VAR_2_NAME, > + &NewEntry); > + UT_ASSERT_NOT_EFI_ERROR (Status); > + > + // Register the new policy. > + Status =3D RegisterVariablePolicy (NewEntry); > + > + // Configure the stub to not care about parameters. We're testing erro= rs. > + expect_any_always( StubGetVariableNull, VariableName ); > + expect_any_always( StubGetVariableNull, VendorGuid ); > + expect_any_always( StubGetVariableNull, DataSize ); > + > + // With a policy, make sure that writes still work, since the variabl= e doesn't > exist. > + will_return( StubGetVariableNull, TEST_POLICY_ATTRIBUTES_NULL ); /= / > Attributes > + will_return( StubGetVariableNull, 0 ); /= / Size > + will_return( StubGetVariableNull, NULL ); /= / DataPtr > + will_return( StubGetVariableNull, EFI_NOT_FOUND); /= / Status > + > + Status =3D VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, > + &mTestGuid1); UT_ASSERT_TRUE (EFI_ERROR (Status)); > + > + FreePool (NewEntry); > + > + return UNIT_TEST_PASSED; > +} > + > +/** > + Test Case that locks a variable using the Variable Policy Protocol > +with a > + policy other than LOCK_NOW, but is currently locked. Then attempts > +to lock > + the same variable using the Variable Lock Protocol. The call to > +Variable > + Policy is expected to succced and the call to Variable Lock also > +expected to > + succeed. > + > + @param[in] Context Unit test case context > + **/ > +UNIT_TEST_STATUS > +EFIAPI > +LockingALockedVariableWithMatchingDataShouldSucceed ( > + IN UNIT_TEST_CONTEXT Context > + ) > +{ > + EFI_STATUS Status; > + VARIABLE_POLICY_ENTRY *NewEntry; > + UINT8 Data; > + > + // Create a variable policy that locks the variable. > + Status =3D CreateVarStateVariablePolicy (&mTestGuid1, > + TEST_VAR_1_NAME, > + TEST_POLICY_MIN_SIZE_NULL, > + TEST_POLICY_MAX_SIZE_200, > + TEST_POLICY_ATTRIBUTES_NULL, > + TEST_POLICY_ATTRIBUTES_NULL, > + &mTestGuid2, > + 1, > + TEST_VAR_2_NAME, > + &NewEntry); > + UT_ASSERT_NOT_EFI_ERROR (Status); > + > + // Register the new policy. > + Status =3D RegisterVariablePolicy (NewEntry); > + > + // Configure the stub to not care about parameters. We're testing erro= rs. > + expect_any_always( StubGetVariableNull, VariableName ); > + expect_any_always( StubGetVariableNull, VendorGuid ); > + expect_any_always( StubGetVariableNull, DataSize ); > + > + // With a policy, make sure that writes still work, since the variabl= e doesn't > exist. > + Data =3D 1; > + will_return( StubGetVariableNull, TEST_POLICY_ATTRIBUTES_NULL ); /= / > Attributes > + will_return( StubGetVariableNull, sizeof (Data) ); /= / Size > + will_return( StubGetVariableNull, &Data ); /= / DataPtr > + will_return( StubGetVariableNull, EFI_SUCCESS); /= / Status > + > + Status =3D VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, > + &mTestGuid1); UT_ASSERT_TRUE (!EFI_ERROR (Status)); > + > + FreePool (NewEntry); > + > + return UNIT_TEST_PASSED; > +} > + > +/** > + Test Case that locks a variable using the Variable Policy Protocol > +with a > + policy other than LOCK_NOW, but variable data does not match. Then > +attempts > + to lock the same variable using the Variable Lock Protocol. The call > +to > + Variable Policy is expected to succced and the call to Variable Lock > +is > + expected to fail. > + > + @param[in] Context Unit test case context > + **/ > +UNIT_TEST_STATUS > +EFIAPI > +LockingALockedVariableWithNonMatchingDataShouldFail ( > + IN UNIT_TEST_CONTEXT Context > + ) > +{ > + EFI_STATUS Status; > + VARIABLE_POLICY_ENTRY *NewEntry; > + UINT8 Data; > + > + // Create a variable policy that locks the variable. > + Status =3D CreateVarStateVariablePolicy (&mTestGuid1, > + TEST_VAR_1_NAME, > + TEST_POLICY_MIN_SIZE_NULL, > + TEST_POLICY_MAX_SIZE_200, > + TEST_POLICY_ATTRIBUTES_NULL, > + TEST_POLICY_ATTRIBUTES_NULL, > + &mTestGuid2, > + 1, > + TEST_VAR_2_NAME, > + &NewEntry); > + UT_ASSERT_NOT_EFI_ERROR (Status); > + > + // Register the new policy. > + Status =3D RegisterVariablePolicy (NewEntry); > + > + // Configure the stub to not care about parameters. We're testing erro= rs. > + expect_any_always( StubGetVariableNull, VariableName ); > + expect_any_always( StubGetVariableNull, VendorGuid ); > + expect_any_always( StubGetVariableNull, DataSize ); > + > + // With a policy, make sure that writes still work, since the variabl= e doesn't > exist. > + Data =3D 2; > + will_return( StubGetVariableNull, TEST_POLICY_ATTRIBUTES_NULL ); /= / > Attributes > + will_return( StubGetVariableNull, sizeof (Data) ); /= / Size > + will_return( StubGetVariableNull, &Data ); /= / DataPtr > + will_return( StubGetVariableNull, EFI_SUCCESS); /= / Status > + > + Status =3D VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, > + &mTestGuid1); UT_ASSERT_TRUE (EFI_ERROR (Status)); > + > + FreePool (NewEntry); > + > + return UNIT_TEST_PASSED; > +} > + > +/** > + Test Case that locks a variable using Variable Lock Protocol Policy > +Protocol > + then and then attempts to lock the same variable using the Variable > +Policy > + Protocol. The call to Variable Lock is expected to succced and the > +call to > + Variable Policy is expected to fail. > + > + @param[in] Context Unit test case context > + **/ > +UNIT_TEST_STATUS > +EFIAPI > +SettingPolicyForALockedVariableShouldFail ( > + IN UNIT_TEST_CONTEXT Context > + ) > +{ > + EFI_STATUS Status; > + VARIABLE_POLICY_ENTRY *NewEntry; > + > + // Lock the variable. > + Status =3D VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, > + &mTestGuid1); UT_ASSERT_NOT_EFI_ERROR (Status); > + > + // Create a variable policy that locks the variable. > + Status =3D CreateVarStateVariablePolicy (&mTestGuid1, > + TEST_VAR_1_NAME, > + TEST_POLICY_MIN_SIZE_NULL, > + TEST_POLICY_MAX_SIZE_200, > + TEST_POLICY_ATTRIBUTES_NULL, > + TEST_POLICY_ATTRIBUTES_NULL, > + &mTestGuid2, > + 1, > + TEST_VAR_2_NAME, > + &NewEntry); > + UT_ASSERT_NOT_EFI_ERROR (Status); > + > + // Register the new policy. > + Status =3D RegisterVariablePolicy (NewEntry); UT_ASSERT_TRUE > + (EFI_ERROR (Status)); > + > + FreePool (NewEntry); > + > + return UNIT_TEST_PASSED; > +} > + > +/** > + Main entry point to this unit test application. > + > + Sets up and runs the test suites. > +**/ > +VOID > +EFIAPI > +UnitTestMain ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + UNIT_TEST_FRAMEWORK_HANDLE Framework; > + UNIT_TEST_SUITE_HANDLE ShimTests; > + > + Framework =3D NULL; > + > + DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_NAME, > UNIT_TEST_VERSION)); > + > + // > + // Start setting up the test framework for running the tests. > + // > + Status =3D InitUnitTestFramework (&Framework, UNIT_TEST_NAME, > + gEfiCallerBaseName, UNIT_TEST_VERSION); if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status > =3D %r\n", Status)); > + goto EXIT; > + } > + > + // > + // Add all test suites and tests. > + // > + Status =3D CreateUnitTestSuite ( > + &ShimTests, Framework, > + "Variable Lock Shim Tests", "VarPolicy.VarLockShim", NULL,= NULL > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for > ShimTests\n")); > + Status =3D EFI_OUT_OF_RESOURCES; > + goto EXIT; > + } > + AddTestCase ( > + ShimTests, > + "Locking a variable with no matching policies should always work", > "EmptyPolicies", > + LockingWithoutAnyPoliciesShouldSucceed, LibInitMocked, LibCleanup, > NULL > + ); > + AddTestCase ( > + ShimTests, > + "Locking a variable twice should always work", "DoubleLock", > + LockingTwiceShouldSucceed, LibInitMocked, LibCleanup, NULL > + ); > + AddTestCase ( > + ShimTests, > + "Locking a variable that's already locked by another policy should = work", > "LockAfterPolicy", > + LockingALockedVariableShouldSucceed, LibInitMocked, LibCleanup, NUL= L > + ); > + AddTestCase ( > + ShimTests, > + "Locking a variable that already has an unlocked policy should fail= ", > "LockAfterUnlockedPolicy", > + LockingAnUnlockedVariableShouldFail, LibInitMocked, LibCleanup, NUL= L > + ); > + AddTestCase ( > + ShimTests, > + "Locking a variable that already has an locked policy should succee= d", > "LockAfterLockedPolicyMatchingData", > + LockingALockedVariableWithMatchingDataShouldSucceed, LibInitMocked, > LibCleanup, NULL > + ); > + AddTestCase ( > + ShimTests, > + "Locking a variable that already has an locked policy with matching= data > should succeed", "LockAfterLockedPolicyNonMatchingData", > + LockingALockedVariableWithNonMatchingDataShouldFail, LibInitMocked, > LibCleanup, NULL > + ); > + AddTestCase ( > + ShimTests, > + "Adding a policy for a variable that has previously been locked sho= uld > always fail", "SetPolicyAfterLock", > + SettingPolicyForALockedVariableShouldFail, LibInitMocked, LibCleanu= p, > NULL > + ); > + > + // > + // Execute the tests. > + // > + Status =3D RunAllTestSuites (Framework); > + > +EXIT: > + if (Framework !=3D NULL) { > + FreeUnitTestFramework (Framework); > + } > + > + return; > +} > + > +/// > +/// Avoid ECC error for function name that starts with lower case > +letter /// #define Main main > + > +/** > + Standard POSIX C entry point for host based unit test execution. > + > + @param[in] Argc Number of arguments > + @param[in] Argv Array of pointers to arguments > + > + @retval 0 Success > + @retval other Error > +**/ > +INT32 > +Main ( > + IN INT32 Argc, > + IN CHAR8 *Argv[] > + ) > +{ > + UnitTestMain (); > + return 0; > +} > diff --git > a/MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Va > riableLockRequestToLockUnitTest.inf > b/MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Va > riableLockRequestToLockUnitTest.inf > new file mode 100644 > index 000000000000..2a659d7e1370 > --- /dev/null > +++ > b/MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/Va > ri > +++ ableLockRequestToLockUnitTest.inf > @@ -0,0 +1,36 @@ > +## @file > +# This is a host-based unit test for the VariableLockRequestToLock shim= . > +# > +# Copyright (c) Microsoft Corporation. > +# SPDX-License-Identifier: BSD-2-Clause-Patent ## > + > +[Defines] > + INF_VERSION =3D 0x00010017 > + BASE_NAME =3D VariableLockRequestToLockUnitTest > + FILE_GUID =3D A7388B6C-7274-4717-9649-BDC5DFD1FCBE > + VERSION_STRING =3D 1.0 > + MODULE_TYPE =3D HOST_APPLICATION > + > +# > +# The following information is for reference only and not required by t= he > build tools. > +# > +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 > +# > + > +[Sources] > + VariableLockRequestToLockUnitTest.c > + ../VariableLockRequestToLock.c > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec > + > +[LibraryClasses] > + UnitTestLib > + DebugLib > + VariablePolicyLib > + VariablePolicyHelperLib > + BaseMemoryLib > + MemoryAllocationLib > -- > 2.29.2.windows.2 >=20 >=20 >=20 >=20 >=20