]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.c
UnitTestFrameworkPkg: Modify APIs in UnitTestPersistenceLib
[mirror_edk2.git] / UnitTestFrameworkPkg / Library / UnitTestPersistenceLibSimpleFileSystem / UnitTestPersistenceLibSimpleFileSystem.c
index ed4a7d1615248a6a3cf9337d55d13ae558f6440d..d7a62145dac6ab5cd5e7aced068b9ca8337e7a94 100644 (file)
@@ -4,6 +4,7 @@
   version of the internal test state in case the test needs to quit and restore.\r
 \r
   Copyright (c) Microsoft Corporation.<BR>\r
+  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
@@ -16,6 +17,7 @@
 #include <Library/DevicePathLib.h>\r
 #include <Library/ShellLib.h>\r
 #include <Protocol/LoadedImage.h>\r
+#include <UnitTestFrameworkTypes.h>\r
 \r
 #define CACHE_FILE_SUFFIX  L"_Cache.dat"\r
 \r
@@ -213,6 +215,7 @@ DoesCacheExist (
   @param[in]  FrameworkHandle  A pointer to the framework that is being persisted.\r
   @param[in]  SaveData         A pointer to the buffer containing the serialized\r
                                framework internal state.\r
+  @param[in]  SaveStateSize    The size of SaveData in bytes.\r
 \r
   @retval  EFI_SUCCESS  Data is persisted and the test can be safely quit.\r
   @retval  Others       Data is not persisted and test cannot be resumed upon exit.\r
@@ -222,7 +225,8 @@ EFI_STATUS
 EFIAPI\r
 SaveUnitTestCache (\r
   IN UNIT_TEST_FRAMEWORK_HANDLE  FrameworkHandle,\r
-  IN UNIT_TEST_SAVE_HEADER       *SaveData\r
+  IN VOID                        *SaveData,\r
+  IN UINTN                       SaveStateSize\r
   )\r
 {\r
   EFI_DEVICE_PATH_PROTOCOL  *FileDevicePath;\r
@@ -280,7 +284,7 @@ SaveUnitTestCache (
   //\r
   // Write the data to the file.\r
   //\r
-  WriteCount = SaveData->SaveStateSize;\r
+  WriteCount = SaveStateSize;\r
   DEBUG ((DEBUG_INFO, "%a - Writing %d bytes to file...\n", __FUNCTION__, WriteCount));\r
   Status = ShellWriteFile (\r
              FileHandle,\r
@@ -288,7 +292,7 @@ SaveUnitTestCache (
              SaveData\r
              );\r
 \r
-  if (EFI_ERROR (Status) || (WriteCount != SaveData->SaveStateSize)) {\r
+  if (EFI_ERROR (Status) || (WriteCount != SaveStateSize)) {\r
     DEBUG ((DEBUG_ERROR, "%a - Writing to file failed! %r\n", __FUNCTION__, Status));\r
   } else {\r
     DEBUG ((DEBUG_INFO, "%a - SUCCESS!\n", __FUNCTION__));\r
@@ -312,8 +316,9 @@ Exit:
   Will allocate a buffer to hold the loaded data.\r
 \r
   @param[in]  FrameworkHandle  A pointer to the framework that is being persisted.\r
-  @param[in]  SaveData         A pointer pointer that will be updated with the address\r
+  @param[out] SaveData         A pointer pointer that will be updated with the address\r
                                of the loaded data buffer.\r
+  @param[out] SaveStateSize    Return the size of SaveData in bytes.\r
 \r
   @retval  EFI_SUCCESS  Data has been loaded successfully and SaveData is updated\r
                         with a pointer to the buffer.\r
@@ -325,7 +330,8 @@ EFI_STATUS
 EFIAPI\r
 LoadUnitTestCache (\r
   IN  UNIT_TEST_FRAMEWORK_HANDLE  FrameworkHandle,\r
-  OUT UNIT_TEST_SAVE_HEADER       **SaveData\r
+  OUT VOID                        **SaveData,\r
+  OUT UINTN                       *SaveStateSize\r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -334,7 +340,7 @@ LoadUnitTestCache (
   BOOLEAN                   IsFileOpened;\r
   UINT64                    LargeFileSize;\r
   UINTN                     FileSize;\r
-  UNIT_TEST_SAVE_HEADER     *Buffer;\r
+  VOID                      *Buffer;\r
 \r
   IsFileOpened = FALSE;\r
   Buffer       = NULL;\r
@@ -380,8 +386,9 @@ LoadUnitTestCache (
   //\r
   // Now that we know the size, let's allocated a buffer to hold the contents.\r
   //\r
-  FileSize = (UINTN)LargeFileSize;    // You know what... if it's too large, this lib don't care.\r
-  Buffer   = AllocatePool (FileSize);\r
+  FileSize       = (UINTN)LargeFileSize; // You know what... if it's too large, this lib don't care.\r
+  *SaveStateSize = FileSize;\r
+  Buffer         = AllocatePool (FileSize);\r
   if (Buffer == NULL) {\r
     DEBUG ((DEBUG_ERROR, "%a - Failed to allocate a pool to hold the file contents! %r\n", __FUNCTION__, Status));\r
     Status = EFI_OUT_OF_RESOURCES;\r