From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=F0uFOKBt; spf=pass (domain: gmail.com, ip: 209.85.210.176, mailfrom: kuqin12@gmail.com) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-64d2c865e4eso105402b3a.0 for ; Wed, 31 May 2023 12:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685560443; x=1688152443; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tI01BAxxZ7WZ1T0rrxf3Il3CuRgafnJjlBHRRbsTJnQ=; b=F0uFOKBtFczkNxNpNyagCc+KDUZWqQ2icXYEJImqOtr56SDETVFPOeOnRZ3IP+Ycfa fpX4OHafAemfMfZmXRWKOABt5YSO18pEc5ZhDKKXg6JIRX7vzoLsSU26PvRM7l6zqBxq XBJX6Sig4jm7p6RJwU9OSkv5UBB1uiWFkekoCwsPzzvdxWxaWD4iq1FpXp/5vpVT8AiP 9lPaVPX2YnH6Xl21FtgdnSRKielLZniSi7TSa4fVjeDcS64j5vPHG+E9pLu7LuFxZZq+ IlCzNOeq5thwgKO/zKTQAJLMdtbwWu2KaxABSkfRJxBAr5HK2eq7/ElMYpruOakHRi3y VAQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685560443; x=1688152443; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tI01BAxxZ7WZ1T0rrxf3Il3CuRgafnJjlBHRRbsTJnQ=; b=VpYZ7BSHZsi1XE3C3p+SpihfY/Y+d0JhV3ZUbOOAPOxKkVJSUyrfuKj19PMy065qWs U6run0007tNvwujVi9/3yOVYnukhDsaiXOnYo+0Rq24aP1ilx8MNqnpmeu5Owk5pi5Ua N4BpHR6iM09wtRDT9YsFTVECL91a/VPly3l/Nneg3bYNEb3mXirVhgqL9/v9WtD3QW5M KoOlmHYhqDkuPu7XhfT5Ph3cljrBFvAhQg9BOJMuraxosClt7Xt8c5GYFdQ5BddU7lfu U1uboAd/DF713D4ke0xsmiJEhnb1DDaRo8wC2wIz586FxKPFkAbsy41gDF+ZUxwaZL+S PkyQ== X-Gm-Message-State: AC+VfDw8zR4p2wNDKLfmcE30QaGtXxrghKB4d+8KBDCmgiErYmmIfgr8 ZhxKfrQRc1nu8QyusgRfiYq3PMAooVQ= 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.40.1.windows.1 In-Reply-To: <20230531191358.587-1-kuqin12@gmail.com> References: <20230531191358.587-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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"=0D =0D /**=0D - Generate the device path to the cache file.=0D + Generate the file name and path to the cache file.=0D =0D @param[in] FrameworkHandle A pointer to the framework that is being pe= rsisted.=0D =0D @@ -31,8 +31,8 @@ =0D **/=0D STATIC=0D -EFI_DEVICE_PATH_PROTOCOL *=0D -GetCacheFileDevicePath (=0D +CHAR16 *=0D +GetCacheFileName (=0D IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle=0D )=0D {=0D @@ -85,7 +85,12 @@ GetCacheFileDevicePath ( // PathCleanUpDirectories (FileNameCopy);=0D // if (PathRemoveLastItem (FileNameCopy)) {=0D //=0D - AppPath =3D ConvertDevicePathToText (LoadedImage->FilePath,= TRUE, TRUE); // NOTE: This must be freed.=0D + AppPath =3D ConvertDevicePathToText (LoadedImage->FilePath, TRUE, TRUE);= // NOTE: This must be freed.=0D + if (AppPath =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "%a - Failed to convert device path to text.\n", = __func__));=0D + goto Exit;=0D + }=0D +=0D DirectorySlashOffset =3D StrLen (AppPath);=0D //=0D // Make sure we didn't get any weird data.=0D @@ -148,15 +153,15 @@ Exit: FreePool (AppPath);=0D }=0D =0D - if (CacheFilePath !=3D NULL) {=0D - FreePool (CacheFilePath);=0D + if (CacheFileDevicePath !=3D NULL) {=0D + FreePool (CacheFileDevicePath);=0D }=0D =0D if (TestName !=3D NULL) {=0D FreePool (TestName);=0D }=0D =0D - return CacheFileDevicePath;=0D + return CacheFilePath;=0D }=0D =0D /**=0D @@ -175,21 +180,21 @@ DoesCacheExist ( IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle=0D )=0D {=0D - EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;=0D - EFI_STATUS Status;=0D - SHELL_FILE_HANDLE FileHandle;=0D + CHAR16 *FileName;=0D + EFI_STATUS Status;=0D + SHELL_FILE_HANDLE FileHandle;=0D =0D //=0D // NOTE: This devpath is allocated and must be freed.=0D //=0D - FileDevicePath =3D GetCacheFileDevicePath (FrameworkHandle);=0D + FileName =3D GetCacheFileName (FrameworkHandle);=0D =0D //=0D // Check to see whether the file exists. If the file can be opened for= =0D // reading, it exists. Otherwise, probably not.=0D //=0D - Status =3D ShellOpenFileByDevicePath (=0D - &FileDevicePath,=0D + Status =3D ShellOpenFileByName (=0D + FileName,=0D &FileHandle,=0D EFI_FILE_MODE_READ,=0D 0=0D @@ -198,8 +203,8 @@ DoesCacheExist ( ShellCloseFile (&FileHandle);=0D }=0D =0D - if (FileDevicePath !=3D NULL) {=0D - FreePool (FileDevicePath);=0D + if (FileName !=3D NULL) {=0D + FreePool (FileName);=0D }=0D =0D DEBUG ((DEBUG_VERBOSE, "%a - Returning %d\n", __func__, !EFI_ERROR (Stat= us)));=0D @@ -229,10 +234,10 @@ SaveUnitTestCache ( IN UINTN SaveStateSize=0D )=0D {=0D - EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;=0D - EFI_STATUS Status;=0D - SHELL_FILE_HANDLE FileHandle;=0D - UINTN WriteCount;=0D + CHAR16 *FileName;=0D + EFI_STATUS Status;=0D + SHELL_FILE_HANDLE FileHandle;=0D + UINTN WriteCount;=0D =0D //=0D // Check the inputs for sanity.=0D @@ -245,13 +250,13 @@ SaveUnitTestCache ( // Determine the path for the cache file.=0D // NOTE: This devpath is allocated and must be freed.=0D //=0D - FileDevicePath =3D GetCacheFileDevicePath (FrameworkHandle);=0D + FileName =3D GetCacheFileName (FrameworkHandle);=0D =0D //=0D // First lets open the file if it exists so we can delete it...This is t= he work around for truncation=0D //=0D - Status =3D ShellOpenFileByDevicePath (=0D - &FileDevicePath,=0D + Status =3D ShellOpenFileByName (=0D + FileName,=0D &FileHandle,=0D (EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE),=0D 0=0D @@ -270,8 +275,8 @@ SaveUnitTestCache ( //=0D // Now that we know the path to the file... let's open it for writing.=0D //=0D - Status =3D ShellOpenFileByDevicePath (=0D - &FileDevicePath,=0D + Status =3D ShellOpenFileByName (=0D + FileName,=0D &FileHandle,=0D (EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CRE= ATE),=0D 0=0D @@ -304,8 +309,8 @@ SaveUnitTestCache ( ShellCloseFile (&FileHandle);=0D =0D Exit:=0D - if (FileDevicePath !=3D NULL) {=0D - FreePool (FileDevicePath);=0D + if (FileName !=3D NULL) {=0D + FreePool (FileName);=0D }=0D =0D return Status;=0D @@ -334,13 +339,13 @@ LoadUnitTestCache ( OUT UINTN *SaveStateSize=0D )=0D {=0D - EFI_STATUS Status;=0D - EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;=0D - SHELL_FILE_HANDLE FileHandle;=0D - BOOLEAN IsFileOpened;=0D - UINT64 LargeFileSize;=0D - UINTN FileSize;=0D - VOID *Buffer;=0D + EFI_STATUS Status;=0D + CHAR16 *FileName;=0D + SHELL_FILE_HANDLE FileHandle;=0D + BOOLEAN IsFileOpened;=0D + UINT64 LargeFileSize;=0D + UINTN FileSize;=0D + VOID *Buffer;=0D =0D IsFileOpened =3D FALSE;=0D Buffer =3D NULL;=0D @@ -356,13 +361,13 @@ LoadUnitTestCache ( // Determine the path for the cache file.=0D // NOTE: This devpath is allocated and must be freed.=0D //=0D - FileDevicePath =3D GetCacheFileDevicePath (FrameworkHandle);=0D + FileName =3D GetCacheFileName (FrameworkHandle);=0D =0D //=0D // Now that we know the path to the file... let's open it for writing.=0D //=0D - Status =3D ShellOpenFileByDevicePath (=0D - &FileDevicePath,=0D + Status =3D ShellOpenFileByName (=0D + FileName,=0D &FileHandle,=0D EFI_FILE_MODE_READ,=0D 0=0D @@ -407,8 +412,8 @@ Exit: //=0D // Free allocated buffers=0D //=0D - if (FileDevicePath !=3D NULL) {=0D - FreePool (FileDevicePath);=0D + if (FileName !=3D NULL) {=0D + FreePool (FileName);=0D }=0D =0D if (IsFileOpened) {=0D --=20 2.40.1.windows.1