From nobody Sun May 5 01:22:43 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+97006+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+97006+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1670304352; cv=none; d=zohomail.com; s=zohoarc; b=CFqQg1hdOub8LV3VfvbcbJHqLOCIpxvmVA09Ee1+0aGY2xitixWHAy46ap+44xuVlNrfPpClT1XHlClGOQ10xzI8gSdD2qu7sqEKuHnjjksDRIfChDMHoEqIbp3hlYPDGZKv2XoEcMgj1s3ugQ9xAujOPFm2DAPTgC5M2DovfPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670304352; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=7aGgBuWxFsT+flzkgiqfVUhg8zsDARDGTLa2mumYd/A=; b=ZYDmouXp56lI87jKgY7GDX2OBV7lblY/Dl0SY25pfExkpuzHwnW+HqisRrp9OHWomz9xpWPA4a9XNqhvtXot/1YocwavOI7GC1+EnCEmb/7fCExqiu6O3IXHk59HhzKyOJ6M1BjMW0m/vspHZmYnlShdAWRBC4ikNiUHzDW4DCE= 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+97006+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 1670304352241382.10392757281693; Mon, 5 Dec 2022 21:25:52 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Wxu2YY1788612xS2EnGrhRkS; Mon, 05 Dec 2022 21:25:51 -0800 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web10.40389.1670304351487487317 for ; Mon, 05 Dec 2022 21:25:51 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10552"; a="296229525" X-IronPort-AV: E=Sophos;i="5.96,220,1665471600"; d="scan'208";a="296229525" X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2022 21:25:50 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10552"; a="891244531" X-IronPort-AV: E=Sophos;i="5.96,220,1665471600"; d="scan'208";a="891244531" X-Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.151]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2022 21:25:48 -0800 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Michael D Kinney , Michael Kubacki , Sean Brogan , Ray Ni Subject: [edk2-devel] [PATCH] UnitTestFrameworkPkg: Modify APIs in UnitTestPersistenceLib Date: Tue, 6 Dec 2022 13:25:43 +0800 Message-Id: <20221206052543.9794-1-zhiguang.liu@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,zhiguang.liu@intel.com X-Gm-Message-State: VPaH6J63rt3oA17oxi4SZP4cx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1670304351; bh=Y5jSuJfdk/jNF1FmIFGiPDtesatfYSPuyvFL4ycPlO8=; h=Cc:Date:From:Reply-To:Subject:To; b=AJN8Of89aBjy2AFVrsSz2UucjFh7P7f73jt2XnSeGf0Mxv8zsMheen85/3e/IKSOhss h5pVD8oGUhnbAINQHTxumf2RTgfBUS/qVoTPLmK2xjL1YZ3EBwlv4Daf1N8rvV5Upf4e9 oKWYje1G5oeM/+Rn/RzrjOahF82x+VQ6vaY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1670304353132100002 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4183 UnitTestPersistenceLib now consumes private struct definition. Modify APIs in UnitTestPersistenceLib to make it easy to become a public library. Cc: Michael D Kinney Cc: Michael Kubacki Cc: Sean Brogan Cc: Ray Ni Signed-off-by: Zhiguang Liu Reviewed-by: Ray Ni --- .../Include/Library/UnitTestPersistenceLib.h | 14 +++++++---- .../Library/UnitTestLib/UnitTestLib.c | 6 +++-- .../UnitTestPersistenceLibNull.c | 11 ++++++--- .../UnitTestPersistenceLibSimpleFileSystem.c | 23 ++++++++++++------- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/UnitTestFrameworkPkg/Include/Library/UnitTestPersistenceLib.h = b/UnitTestFrameworkPkg/Include/Library/UnitTestPersistenceLib.h index be29e079ec..5543b79a0d 100644 --- a/UnitTestFrameworkPkg/Include/Library/UnitTestPersistenceLib.h +++ b/UnitTestFrameworkPkg/Include/Library/UnitTestPersistenceLib.h @@ -4,7 +4,7 @@ (eg. a reboot-based test). =20 Copyright (c) Microsoft Corporation.
- Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
+ Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -12,7 +12,7 @@ #ifndef _UNIT_TEST_PERSISTENCE_LIB_H_ #define _UNIT_TEST_PERSISTENCE_LIB_H_ =20 -#include +#include =20 #define UNIT_TEST_PERSISTENCE_LIB_VERSION 1 =20 @@ -40,6 +40,7 @@ DoesCacheExist ( @param[in] FrameworkHandle A pointer to the framework that is being p= ersisted. @param[in] SaveData A pointer to the buffer containing the ser= ialized framework internal state. + @param[in] SaveStateSize The size of SaveData in bytes. =20 @retval EFI_SUCCESS Data is persisted and the test can be safely q= uit. @retval Others Data is not persisted and test cannot be resum= ed upon exit. @@ -49,7 +50,8 @@ EFI_STATUS EFIAPI SaveUnitTestCache ( IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, - IN UNIT_TEST_SAVE_HEADER *SaveData + IN VOID *SaveData, + IN UINTN SaveStateSize ); =20 /** @@ -57,8 +59,9 @@ SaveUnitTestCache ( Will allocate a buffer to hold the loaded data. =20 @param[in] FrameworkHandle A pointer to the framework that is being p= ersisted. - @param[in] SaveData A pointer pointer that will be updated wit= h the address + @param[out] SaveData A pointer pointer that will be updated wit= h the address of the loaded data buffer. + @param[out] SaveStateSize Return the size of SaveData in bytes. =20 @retval EFI_SUCCESS Data has been loaded successfully and Save= Data is updated with a pointer to the buffer. @@ -70,7 +73,8 @@ EFI_STATUS EFIAPI LoadUnitTestCache ( IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, - OUT UNIT_TEST_SAVE_HEADER **SaveData + OUT VOID **SaveData, + OUT UINTN *SaveStateSize ); =20 #endif diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c b/UnitT= estFrameworkPkg/Library/UnitTestLib/UnitTestLib.c index 64d5880783..5b442ed122 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c @@ -2,6 +2,7 @@ Implement UnitTestLib =20 Copyright (c) Microsoft Corporation. + Copyright (c) 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 @@ -210,6 +211,7 @@ InitUnitTestFramework ( EFI_STATUS Status; UNIT_TEST_FRAMEWORK_HANDLE NewFrameworkHandle; UNIT_TEST_FRAMEWORK *NewFramework; + UINTN SaveStateSize; =20 Status =3D EFI_SUCCESS; NewFramework =3D NULL; @@ -267,7 +269,7 @@ InitUnitTestFramework ( // If there is a persisted context, load it now. // if (DoesCacheExist (NewFrameworkHandle)) { - Status =3D LoadUnitTestCache (NewFrameworkHandle, (UNIT_TEST_SAVE_HEAD= ER **)(&NewFramework->SavedState)); + Status =3D LoadUnitTestCache (NewFrameworkHandle, (VOID **)(&NewFramew= ork->SavedState), &SaveStateSize); if (EFI_ERROR (Status)) { // // Don't actually report it as an error, but emit a warning. @@ -852,7 +854,7 @@ SaveFrameworkState ( // // All that should be left to do is save it using the associated persist= ence lib. // - Status =3D SaveUnitTestCache (FrameworkHandle, Header); + Status =3D SaveUnitTestCache (FrameworkHandle, Header, Header->SaveState= Size); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a - Could not save state! %r\n", __FUNCTION__, = Status)); Status =3D EFI_DEVICE_ERROR; diff --git a/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTe= stPersistenceLibNull.c b/UnitTestFrameworkPkg/Library/UnitTestPersistenceLi= bNull/UnitTestPersistenceLibNull.c index e28327652e..abb24cff98 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersi= stenceLibNull.c +++ b/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersi= stenceLibNull.c @@ -2,6 +2,7 @@ This is an instance of the Unit Test Persistence Lib that does nothing. =20 Copyright (c) Microsoft Corporation.
+ Copyright (c) 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 @@ -35,6 +36,7 @@ DoesCacheExist ( @param[in] FrameworkHandle A pointer to the framework that is being pe= rsisted. @param[in] SaveData A pointer to the buffer containing the seri= alized framework internal state. + @param[in] SaveStateSize The size of SaveData in bytes. =20 @retval EFI_SUCCESS Data is persisted and the test can be safely quit. @retval Others Data is not persisted and test cannot be resumed u= pon exit. @@ -44,7 +46,8 @@ EFI_STATUS EFIAPI SaveUnitTestCache ( IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, - IN UNIT_TEST_SAVE_HEADER *SaveData + IN VOID *SaveData, + IN UINTN SaveStateSize ) { return EFI_UNSUPPORTED; @@ -55,8 +58,9 @@ SaveUnitTestCache ( Will allocate a buffer to hold the loaded data. =20 @param[in] FrameworkHandle A pointer to the framework that is being pe= rsisted. - @param[in] SaveData A pointer pointer that will be updated with= the address + @param[out] SaveData A pointer pointer that will be updated with= the address of the loaded data buffer. + @param[out] SaveStateSize Return the size of SaveData in bytes. =20 @retval EFI_SUCCESS Data has been loaded successfully and SaveData is = updated with a pointer to the buffer. @@ -68,7 +72,8 @@ EFI_STATUS EFIAPI LoadUnitTestCache ( IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, - OUT UNIT_TEST_SAVE_HEADER **SaveData + OUT VOID **SaveData, + OUT UINTN *SaveStateSize ) { return EFI_UNSUPPORTED; diff --git a/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileS= ystem/UnitTestPersistenceLibSimpleFileSystem.c b/UnitTestFrameworkPkg/Libra= ry/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileS= ystem.c index ed4a7d1615..d7a62145da 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/U= nitTestPersistenceLibSimpleFileSystem.c +++ b/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/U= nitTestPersistenceLibSimpleFileSystem.c @@ -4,6 +4,7 @@ version of the internal test state in case the test needs to quit and re= store. =20 Copyright (c) Microsoft Corporation.
+ Copyright (c) 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 @@ -16,6 +17,7 @@ #include #include #include +#include =20 #define CACHE_FILE_SUFFIX L"_Cache.dat" =20 @@ -213,6 +215,7 @@ DoesCacheExist ( @param[in] FrameworkHandle A pointer to the framework that is being pe= rsisted. @param[in] SaveData A pointer to the buffer containing the seri= alized framework internal state. + @param[in] SaveStateSize The size of SaveData in bytes. =20 @retval EFI_SUCCESS Data is persisted and the test can be safely quit. @retval Others Data is not persisted and test cannot be resumed u= pon exit. @@ -222,7 +225,8 @@ EFI_STATUS EFIAPI SaveUnitTestCache ( IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, - IN UNIT_TEST_SAVE_HEADER *SaveData + IN VOID *SaveData, + IN UINTN SaveStateSize ) { EFI_DEVICE_PATH_PROTOCOL *FileDevicePath; @@ -280,7 +284,7 @@ SaveUnitTestCache ( // // Write the data to the file. // - WriteCount =3D SaveData->SaveStateSize; + WriteCount =3D SaveStateSize; DEBUG ((DEBUG_INFO, "%a - Writing %d bytes to file...\n", __FUNCTION__, = WriteCount)); Status =3D ShellWriteFile ( FileHandle, @@ -288,7 +292,7 @@ SaveUnitTestCache ( SaveData ); =20 - if (EFI_ERROR (Status) || (WriteCount !=3D SaveData->SaveStateSize)) { + if (EFI_ERROR (Status) || (WriteCount !=3D SaveStateSize)) { DEBUG ((DEBUG_ERROR, "%a - Writing to file failed! %r\n", __FUNCTION__= , Status)); } else { DEBUG ((DEBUG_INFO, "%a - SUCCESS!\n", __FUNCTION__)); @@ -312,8 +316,9 @@ Exit: Will allocate a buffer to hold the loaded data. =20 @param[in] FrameworkHandle A pointer to the framework that is being pe= rsisted. - @param[in] SaveData A pointer pointer that will be updated with= the address + @param[out] SaveData A pointer pointer that will be updated with= the address of the loaded data buffer. + @param[out] SaveStateSize Return the size of SaveData in bytes. =20 @retval EFI_SUCCESS Data has been loaded successfully and SaveData is = updated with a pointer to the buffer. @@ -325,7 +330,8 @@ EFI_STATUS EFIAPI LoadUnitTestCache ( IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, - OUT UNIT_TEST_SAVE_HEADER **SaveData + OUT VOID **SaveData, + OUT UINTN *SaveStateSize ) { EFI_STATUS Status; @@ -334,7 +340,7 @@ LoadUnitTestCache ( BOOLEAN IsFileOpened; UINT64 LargeFileSize; UINTN FileSize; - UNIT_TEST_SAVE_HEADER *Buffer; + VOID *Buffer; =20 IsFileOpened =3D FALSE; Buffer =3D NULL; @@ -380,8 +386,9 @@ LoadUnitTestCache ( // // Now that we know the size, let's allocated a buffer to hold the conte= nts. // - FileSize =3D (UINTN)LargeFileSize; // You know what... if it's too la= rge, this lib don't care. - Buffer =3D AllocatePool (FileSize); + FileSize =3D (UINTN)LargeFileSize; // You know what... if it's too= large, this lib don't care. + *SaveStateSize =3D FileSize; + Buffer =3D AllocatePool (FileSize); if (Buffer =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "%a - Failed to allocate a pool to hold the file = contents! %r\n", __FUNCTION__, Status)); Status =3D EFI_OUT_OF_RESOURCES; --=20 2.31.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 (#97006): https://edk2.groups.io/g/devel/message/97006 Mute This Topic: https://groups.io/mt/95487930/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-