]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UnitTestFrameworkPkg: Modify APIs in UnitTestPersistenceLib
authorLiu, Zhiguang <Zhiguang.Liu@intel.com>
Tue, 6 Dec 2022 05:25:43 +0000 (13:25 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 14 Dec 2022 13:34:33 +0000 (13:34 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4183

UnitTestPersistenceLib now consumes private struct definition.
Modify APIs in UnitTestPersistenceLib to make it easy to become
a public library.

Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
UnitTestFrameworkPkg/Include/Library/UnitTestPersistenceLib.h
UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.c
UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.c

index be29e079ec3e0b2743442c03caf95ee41f8e2bc1..5543b79a0d0ded6e65e6db0d36d15015fff24cbc 100644 (file)
@@ -4,7 +4,7 @@
   (eg. a reboot-based test).\r
 \r
   Copyright (c) Microsoft Corporation.<BR>\r
-  Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -12,7 +12,7 @@
 #ifndef _UNIT_TEST_PERSISTENCE_LIB_H_\r
 #define _UNIT_TEST_PERSISTENCE_LIB_H_\r
 \r
-#include <UnitTestFrameworkTypes.h>\r
+#include <Library/UnitTestLib.h>\r
 \r
 #define UNIT_TEST_PERSISTENCE_LIB_VERSION  1\r
 \r
@@ -40,6 +40,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
@@ -49,7 +50,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
 /**\r
@@ -57,8 +59,9 @@ SaveUnitTestCache (
   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
@@ -70,7 +73,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
 #endif\r
index 64d5880783bf8a4713a34ed2e686681f6915d5bf..5b442ed122ea1d3fc5f4a1a79829fff07f4413ab 100644 (file)
@@ -2,6 +2,7 @@
   Implement UnitTestLib\r
 \r
   Copyright (c) Microsoft Corporation.\r
+  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
@@ -210,6 +211,7 @@ InitUnitTestFramework (
   EFI_STATUS                  Status;\r
   UNIT_TEST_FRAMEWORK_HANDLE  NewFrameworkHandle;\r
   UNIT_TEST_FRAMEWORK         *NewFramework;\r
+  UINTN                       SaveStateSize;\r
 \r
   Status       = EFI_SUCCESS;\r
   NewFramework = NULL;\r
@@ -267,7 +269,7 @@ InitUnitTestFramework (
   // If there is a persisted context, load it now.\r
   //\r
   if (DoesCacheExist (NewFrameworkHandle)) {\r
-    Status = LoadUnitTestCache (NewFrameworkHandle, (UNIT_TEST_SAVE_HEADER **)(&NewFramework->SavedState));\r
+    Status = LoadUnitTestCache (NewFrameworkHandle, (VOID **)(&NewFramework->SavedState), &SaveStateSize);\r
     if (EFI_ERROR (Status)) {\r
       //\r
       // Don't actually report it as an error, but emit a warning.\r
@@ -852,7 +854,7 @@ SaveFrameworkState (
   //\r
   // All that should be left to do is save it using the associated persistence lib.\r
   //\r
-  Status = SaveUnitTestCache (FrameworkHandle, Header);\r
+  Status = SaveUnitTestCache (FrameworkHandle, Header, Header->SaveStateSize);\r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_ERROR, "%a - Could not save state! %r\n", __FUNCTION__, Status));\r
     Status = EFI_DEVICE_ERROR;\r
index e28327652eaf9ac9ed7282d73065a336094b2471..abb24cff98804d221a747f8e811c702d4217c482 100644 (file)
@@ -2,6 +2,7 @@
   This is an instance of the Unit Test Persistence Lib that does nothing.\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
@@ -35,6 +36,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
@@ -44,7 +46,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
   return EFI_UNSUPPORTED;\r
@@ -55,8 +58,9 @@ SaveUnitTestCache (
   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
@@ -68,7 +72,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
   return EFI_UNSUPPORTED;\r
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