(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
#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
@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
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
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
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
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
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
// 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
//\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
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
@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
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
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
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
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
#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
@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
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
//\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
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
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
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
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
//\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