From nobody Sat May 18 18:58:12 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+105514+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+105514+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1685560445; cv=none; d=zohomail.com; s=zohoarc; b=Snpa3YTXYEt19QUa66LyOUQ64VY63BeezYNWNHz9GrPp2dlEGpbY5x4WZ1ccap4X5NFsPY6KaZy6P8BpltrfsJWKiUgWzngmrICEkueaDOobuNOWZKB0/fwddOv7eOMuQXTZS6Rl4OS1DRcp+5a0aVJ8gRfAgpvOYZYok8l5U7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685560445; 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=ACsZZD5YHqr96OAYeTgu5tzzgDfhr566eRo85L8UR4Y=; b=Qp4N7GKz1lDl/twhSJCVcRPkO/hrdtQ+ZeI34nmbraTWRzaySkrc36mz9ZOwJziE1Qwoc2WPKRxdW8gscfheEUDFIZ1AGmWzq4HB4krM8dm6Q8miHMMM+nyN0cN03rl2Iw+7IHc4R0siOoIqr3m+F08OmgL+bDjfBlqJpmEjoPg= 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+105514+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 168556044499259.408470701322244; Wed, 31 May 2023 12:14:04 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MQ9PYY1788612xKMpfImfKtm; Wed, 31 May 2023 12:14:04 -0700 X-Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mx.groups.io with SMTP id smtpd.web10.3258.1685560443994321789 for ; Wed, 31 May 2023 12:14:04 -0700 X-Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-64d2c865e4eso105402b3a.0 for ; Wed, 31 May 2023 12:14:03 -0700 (PDT) X-Gm-Message-State: 3BXwNRHfsGOXlK54T9Lihszpx1787277AA= X-Google-Smtp-Source: ACHHUZ6KmhjCumyV0IHLMghbWTG1kve7PYqzUSAnBxT7Q5J70Jas+UN9Lw4MqCAy0yBjYAOuqqVXnA== X-Received: by 2002:a05:6a00:9a4:b0:643:b263:404 with SMTP id u36-20020a056a0009a400b00643b2630404mr6420645pfg.33.1685560443146; Wed, 31 May 2023 12:14:03 -0700 (PDT) X-Received: from MININT-0U7P5GU.redmond.corp.microsoft.com ([2001:4898:80e8:2:2436:c26b:8629:f4ff]) by smtp.gmail.com with ESMTPSA id d2-20020aa78682000000b005d72e54a7e1sm3621371pfo.215.2023.05.31.12.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 12:14:02 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Sean Brogan , Michael Kubacki , Michael D Kinney Subject: [edk2-devel] [PATCH v1 1/1] UnitTestFrameworkPkg: UnitTestPersistenceLib: Save Unit Test Cache to Drive Date: Wed, 31 May 2023 12:13:58 -0700 Message-Id: <20230531191358.587-2-kuqin12@gmail.com> In-Reply-To: <20230531191358.587-1-kuqin12@gmail.com> References: <20230531191358.587-1-kuqin12@gmail.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,kuqin12@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685560444; bh=huSd+rYqdYA6XHXyTuiKQ0/wHsAsQ4VKGVgu/DeRSE0=; h=Cc:Date:From:Reply-To:Subject:To; b=LBEi7zvxZzh0T00cxgV/L9JM6Yv4OI4qT7JXiNoYi7ad8HMhusjtk0xFNX05J1R4MYk eei9Y5cJtJVHXFmw/X+Um9JzCXDs4vMuIgGi3ee0j3EljxnOEQuq5JNlMpvsmUGaii1bF NQ25uZpo2sHowF8X/kobojGFkMATqrIrsPs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685560445704100005 Content-Type: text/plain; charset="utf-8" From: kuqin12 <42554914+kuqin12@users.noreply.github.com> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4467 Current implementation of UnitTestFrameworkPkg for shell-based unit test will save the unit test cache to the same volume as the test application itself. This works as long as the test application is on a writable volume, such as USB or EFI partition. Instead of saving the files to the same file system of unit test application, this change will save the cache file to the path where the user ran this test application. This change was tested on proprietary physical hardware platforms and QEMU based virtual platform. Cc: Sean Brogan Cc: Michael Kubacki Cc: Michael D Kinney Signed-off-by: Kun Qin --- UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTe= stPersistenceLibSimpleFileSystem.c | 81 +++++++++++--------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileS= ystem/UnitTestPersistenceLibSimpleFileSystem.c b/UnitTestFrameworkPkg/Libra= ry/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileS= ystem.c index b59991683f48..d4181808b2be 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/U= nitTestPersistenceLibSimpleFileSystem.c +++ b/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/U= nitTestPersistenceLibSimpleFileSystem.c @@ -22,7 +22,7 @@ #define CACHE_FILE_SUFFIX L"_Cache.dat" =20 /** - Generate the device path to the cache file. + Generate the file name and path to the cache file. =20 @param[in] FrameworkHandle A pointer to the framework that is being pe= rsisted. =20 @@ -31,8 +31,8 @@ =20 **/ STATIC -EFI_DEVICE_PATH_PROTOCOL * -GetCacheFileDevicePath ( +CHAR16 * +GetCacheFileName ( IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle ) { @@ -85,7 +85,12 @@ GetCacheFileDevicePath ( // PathCleanUpDirectories (FileNameCopy); // if (PathRemoveLastItem (FileNameCopy)) { // - AppPath =3D ConvertDevicePathToText (LoadedImage->FilePath,= TRUE, TRUE); // NOTE: This must be freed. + AppPath =3D ConvertDevicePathToText (LoadedImage->FilePath, TRUE, TRUE);= // NOTE: This must be freed. + if (AppPath =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a - Failed to convert device path to text.\n", = __func__)); + goto Exit; + } + DirectorySlashOffset =3D StrLen (AppPath); // // Make sure we didn't get any weird data. @@ -148,15 +153,15 @@ Exit: FreePool (AppPath); } =20 - if (CacheFilePath !=3D NULL) { - FreePool (CacheFilePath); + if (CacheFileDevicePath !=3D NULL) { + FreePool (CacheFileDevicePath); } =20 if (TestName !=3D NULL) { FreePool (TestName); } =20 - return CacheFileDevicePath; + return CacheFilePath; } =20 /** @@ -175,21 +180,21 @@ DoesCacheExist ( IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle ) { - EFI_DEVICE_PATH_PROTOCOL *FileDevicePath; - EFI_STATUS Status; - SHELL_FILE_HANDLE FileHandle; + CHAR16 *FileName; + EFI_STATUS Status; + SHELL_FILE_HANDLE FileHandle; =20 // // NOTE: This devpath is allocated and must be freed. // - FileDevicePath =3D GetCacheFileDevicePath (FrameworkHandle); + FileName =3D GetCacheFileName (FrameworkHandle); =20 // // Check to see whether the file exists. If the file can be opened for // reading, it exists. Otherwise, probably not. // - Status =3D ShellOpenFileByDevicePath ( - &FileDevicePath, + Status =3D ShellOpenFileByName ( + FileName, &FileHandle, EFI_FILE_MODE_READ, 0 @@ -198,8 +203,8 @@ DoesCacheExist ( ShellCloseFile (&FileHandle); } =20 - if (FileDevicePath !=3D NULL) { - FreePool (FileDevicePath); + if (FileName !=3D NULL) { + FreePool (FileName); } =20 DEBUG ((DEBUG_VERBOSE, "%a - Returning %d\n", __func__, !EFI_ERROR (Stat= us))); @@ -229,10 +234,10 @@ SaveUnitTestCache ( IN UINTN SaveStateSize ) { - EFI_DEVICE_PATH_PROTOCOL *FileDevicePath; - EFI_STATUS Status; - SHELL_FILE_HANDLE FileHandle; - UINTN WriteCount; + CHAR16 *FileName; + EFI_STATUS Status; + SHELL_FILE_HANDLE FileHandle; + UINTN WriteCount; =20 // // Check the inputs for sanity. @@ -245,13 +250,13 @@ SaveUnitTestCache ( // Determine the path for the cache file. // NOTE: This devpath is allocated and must be freed. // - FileDevicePath =3D GetCacheFileDevicePath (FrameworkHandle); + FileName =3D GetCacheFileName (FrameworkHandle); =20 // // First lets open the file if it exists so we can delete it...This is t= he work around for truncation // - Status =3D ShellOpenFileByDevicePath ( - &FileDevicePath, + Status =3D ShellOpenFileByName ( + FileName, &FileHandle, (EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE), 0 @@ -270,8 +275,8 @@ SaveUnitTestCache ( // // Now that we know the path to the file... let's open it for writing. // - Status =3D ShellOpenFileByDevicePath ( - &FileDevicePath, + Status =3D ShellOpenFileByName ( + FileName, &FileHandle, (EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CRE= ATE), 0 @@ -304,8 +309,8 @@ SaveUnitTestCache ( ShellCloseFile (&FileHandle); =20 Exit: - if (FileDevicePath !=3D NULL) { - FreePool (FileDevicePath); + if (FileName !=3D NULL) { + FreePool (FileName); } =20 return Status; @@ -334,13 +339,13 @@ LoadUnitTestCache ( OUT UINTN *SaveStateSize ) { - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *FileDevicePath; - SHELL_FILE_HANDLE FileHandle; - BOOLEAN IsFileOpened; - UINT64 LargeFileSize; - UINTN FileSize; - VOID *Buffer; + EFI_STATUS Status; + CHAR16 *FileName; + SHELL_FILE_HANDLE FileHandle; + BOOLEAN IsFileOpened; + UINT64 LargeFileSize; + UINTN FileSize; + VOID *Buffer; =20 IsFileOpened =3D FALSE; Buffer =3D NULL; @@ -356,13 +361,13 @@ LoadUnitTestCache ( // Determine the path for the cache file. // NOTE: This devpath is allocated and must be freed. // - FileDevicePath =3D GetCacheFileDevicePath (FrameworkHandle); + FileName =3D GetCacheFileName (FrameworkHandle); =20 // // Now that we know the path to the file... let's open it for writing. // - Status =3D ShellOpenFileByDevicePath ( - &FileDevicePath, + Status =3D ShellOpenFileByName ( + FileName, &FileHandle, EFI_FILE_MODE_READ, 0 @@ -407,8 +412,8 @@ Exit: // // Free allocated buffers // - if (FileDevicePath !=3D NULL) { - FreePool (FileDevicePath); + if (FileName !=3D NULL) { + FreePool (FileName); } =20 if (IsFileOpened) { --=20 2.40.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 (#105514): https://edk2.groups.io/g/devel/message/105514 Mute This Topic: https://groups.io/mt/99249446/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-