42IsFrameworkShortNameValid (
43 IN CHAR8 *ShortTitleString
52AllocateAndCopyString (
53 IN CHAR8 *StringToCopy
57 UINTN NewStringLength;
71SetFrameworkFingerprint (
72 OUT UINT8 *Fingerprint,
76 UINT32 NewFingerprint;
80 NewFingerprint = (NewFingerprint >> 8) ^
CalculateCrc32 (Framework->VersionString, (
AsciiStrLen (Framework->VersionString) * sizeof (CHAR8)));
89 OUT UINT8 *Fingerprint,
94 UINT32 NewFingerprint;
108 OUT UINT8 *Fingerprint,
113 UINT32 NewFingerprint;
127 IN UINT8 *FingerprintA,
128 IN UINT8 *FingerprintB
151 IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
160FreeUnitTestSuiteEntry (
170FreeUnitTestTestEntry (
205 OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle,
207 IN CHAR8 *ShortTitle,
208 IN CHAR8 *VersionString
212 UNIT_TEST_FRAMEWORK_HANDLE NewFrameworkHandle;
222 if ((FrameworkHandle ==
NULL) || (Title ==
NULL) ||
223 (ShortTitle ==
NULL) || (VersionString ==
NULL))
225 return EFI_INVALID_PARAMETER;
231 if (!IsFrameworkShortNameValid (ShortTitle)) {
232 return EFI_INVALID_PARAMETER;
239 if (NewFramework ==
NULL) {
240 return EFI_OUT_OF_RESOURCES;
246 NewFrameworkHandle = (UNIT_TEST_FRAMEWORK_HANDLE)NewFramework;
247 NewFramework->Title = AllocateAndCopyString (Title);
248 NewFramework->ShortTitle = AllocateAndCopyString (ShortTitle);
249 NewFramework->VersionString = AllocateAndCopyString (VersionString);
250 NewFramework->Log =
NULL;
251 NewFramework->CurrentTest =
NULL;
252 NewFramework->SavedState =
NULL;
253 if ((NewFramework->Title ==
NULL) ||
254 (NewFramework->ShortTitle ==
NULL) ||
255 (NewFramework->VersionString ==
NULL))
257 Status = EFI_OUT_OF_RESOURCES;
266 SetFrameworkFingerprint (&NewFramework->Fingerprint[0], NewFramework);
272 Status =
LoadUnitTestCache (NewFrameworkHandle, (VOID **)(&NewFramework->SavedState), &SaveStateSize);
273 if (EFI_ERROR (Status)) {
277 DEBUG ((DEBUG_ERROR,
"%a - Cache was detected, but failed to load.\n", __func__));
286 if (!EFI_ERROR (Status)) {
287 *FrameworkHandle = NewFrameworkHandle;
327 OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle,
328 IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
345 if ((SuiteHandle ==
NULL) || (Framework ==
NULL) || (Title ==
NULL) || (Name ==
NULL)) {
346 return EFI_INVALID_PARAMETER;
353 if (NewSuiteEntry ==
NULL) {
354 return EFI_OUT_OF_RESOURCES;
360 NewSuiteEntry->UTS.NumTests = 0;
361 NewSuiteEntry->UTS.Title = AllocateAndCopyString (Title);
362 NewSuiteEntry->UTS.Name = AllocateAndCopyString (Name);
363 NewSuiteEntry->UTS.Setup = Setup;
364 NewSuiteEntry->UTS.Teardown = Teardown;
365 NewSuiteEntry->UTS.ParentFramework = FrameworkHandle;
368 if (NewSuiteEntry->UTS.Title ==
NULL) {
369 Status = EFI_OUT_OF_RESOURCES;
373 if (NewSuiteEntry->UTS.Name ==
NULL) {
374 Status = EFI_OUT_OF_RESOURCES;
381 SetSuiteFingerprint (&NewSuiteEntry->UTS.Fingerprint[0], Framework, &NewSuiteEntry->UTS);
387 if (!EFI_ERROR (Status)) {
389 *SuiteHandle = (UNIT_TEST_SUITE_HANDLE)(&NewSuiteEntry->UTS);
394 FreeUnitTestSuiteEntry (NewSuiteEntry);
427 IN UNIT_TEST_SUITE_HANDLE SuiteHandle,
428 IN CHAR8 *Description,
447 if ((Suite ==
NULL) || (Description ==
NULL) || (Name ==
NULL) || (Function ==
NULL)) {
448 return EFI_INVALID_PARAMETER;
455 if (NewTestEntry ==
NULL) {
456 return EFI_OUT_OF_RESOURCES;
461 NewTestEntry->UT.Description = AllocateAndCopyString (Description);
462 NewTestEntry->UT.Name = AllocateAndCopyString (Name);
463 NewTestEntry->UT.FailureType = FAILURETYPE_NOFAILURE;
464 NewTestEntry->UT.FailureMessage[0] =
'\0';
465 NewTestEntry->UT.Log =
NULL;
466 NewTestEntry->UT.Prerequisite = Prerequisite;
467 NewTestEntry->UT.CleanUp = CleanUp;
468 NewTestEntry->UT.RunTest = Function;
469 NewTestEntry->UT.Context = Context;
470 NewTestEntry->UT.Result = UNIT_TEST_PENDING;
471 NewTestEntry->UT.ParentSuite = SuiteHandle;
473 if (NewTestEntry->UT.Description ==
NULL) {
474 Status = EFI_OUT_OF_RESOURCES;
478 if (NewTestEntry->UT.Name ==
NULL) {
479 Status = EFI_OUT_OF_RESOURCES;
486 SetTestFingerprint (&NewTestEntry->UT.Fingerprint[0], Suite, &NewTestEntry->UT);
493 if (ParentFramework->SavedState !=
NULL) {
494 UpdateTestFromSave (&NewTestEntry->UT, ParentFramework->SavedState);
501 if (!EFI_ERROR (Status)) {
508 FreeUnitTestTestEntry (NewTestEntry);
523 UINT8 *FloatingPointer;
534 if (SavedState->TestCount == 0) {
543 FloatingPointer = (UINT8 *)SavedState +
sizeof (*SavedState);
544 for (Index = 0; Index < SavedState->TestCount; Index++) {
546 if (CompareFingerprints (&
Test->Fingerprint[0], &CurrentTest->Fingerprint[0])) {
547 MatchingTest = CurrentTest;
551 if (!SavedState->HasSavedContext) {
559 FloatingPointer = (UINT8 *)CurrentTest + CurrentTest->Size;
569 Test->Result = MatchingTest->Result;
571 Test->FailureType = MatchingTest->FailureType;
573 &
Test->FailureMessage[0],
575 &MatchingTest->FailureMessage[0],
595 if (SavedState->HasSavedContext) {
602 CompareFingerprints (&
Test->Fingerprint[0], &SavedContext->Fingerprint[0]))
607 Test->Context = (VOID *)SavedContext->Data;
615 IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
632 UINT8 *FloatingPointer;
640 if ((Framework ==
NULL) ||
641 ((ContextToSave !=
NULL) && (ContextToSaveSize == 0)) ||
642 (ContextToSaveSize > MAX_UINT32))
660 SuiteListHead = &Framework->TestSuiteList;
661 for (Suite =
GetFirstNode (SuiteListHead); Suite != SuiteListHead; Suite =
GetNextNode (SuiteListHead, Suite)) {
675 if (UnitTest->Log !=
NULL) {
679 LogSize = (
AsciiStrLen (UnitTest->Log) + 1) *
sizeof (CHAR8);
680 ASSERT (LogSize < MAX_UINT32);
681 TotalSize += (UINT32)LogSize;
694 if (TestCount == 0) {
701 if (ContextToSave !=
NULL) {
709 if (Header ==
NULL) {
716 Header->Version = UNIT_TEST_PERSISTENCE_LIB_VERSION;
717 Header->SaveStateSize = TotalSize;
719 CopyMem (&Header->StartTime, &Framework->StartTime, sizeof (
EFI_TIME));
720 Header->TestCount = TestCount;
721 Header->HasSavedContext =
FALSE;
731 SuiteListHead = &Framework->TestSuiteList;
732 for (Suite =
GetFirstNode (SuiteListHead); Suite != SuiteListHead; Suite =
GetNextNode (SuiteListHead, Suite)) {
749 TestSaveData->Result = UnitTest->Result;
750 TestSaveData->FailureType = UnitTest->FailureType;
757 if (UnitTest->Log !=
NULL) {
761 LogSize = (
AsciiStrLen (UnitTest->Log) + 1) *
sizeof (CHAR8);
762 CopyMem (FloatingPointer, UnitTest->Log, LogSize);
763 FloatingPointer += LogSize;
770 TestSaveData->Size = (UINT32)(FloatingPointer - (UINT8 *)TestSaveData);
777 if ((ContextToSave !=
NULL) && (Framework->CurrentTest !=
NULL)) {
782 Header->HasSavedContext =
TRUE;
824 UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle;
828 FrameworkHandle = GetActiveFrameworkHandle ();
829 if (FrameworkHandle ==
NULL) {
830 DEBUG ((DEBUG_ERROR,
"%a - Could not save state! FrameworkHandle not initialized\n", __func__));
831 return EFI_DEVICE_ERROR;
837 if (FrameworkHandle ==
NULL) {
838 return EFI_NOT_FOUND;
844 if (((ContextToSave !=
NULL) && (ContextToSaveSize == 0)) ||
845 (ContextToSaveSize > MAX_UINT32))
847 return EFI_INVALID_PARAMETER;
853 Header = SerializeState (FrameworkHandle, ContextToSave, ContextToSaveSize);
854 if (Header ==
NULL) {
855 return EFI_OUT_OF_RESOURCES;
862 if (EFI_ERROR (Status)) {
863 DEBUG ((DEBUG_ERROR,
"%a - Could not save state! %r\n", __func__, Status));
864 Status = EFI_DEVICE_ERROR;
UINTN EFIAPI AsciiStrnLenS(IN CONST CHAR8 *String, IN UINTN MaxSize)
RETURN_STATUS EFIAPI AsciiStrnCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
UINT32 EFIAPI CalculateCrc32(IN VOID *Buffer, IN UINTN Length)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
RETURN_STATUS EFIAPI AsciiStrCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG(Expression)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STRING_ID NewString(IN CHAR16 *String, IN EFI_HII_HANDLE HiiHandle)
INTN EFIAPI Test(CONST VOID *b1, CONST VOID *b2)
VOID EFIAPI Exit(IN EFI_STATUS Status)
#define UNIT_TEST_FINGERPRINT_SIZE
#define UNIT_TEST_MAX_STRING_LENGTH
EFI_STATUS EFIAPI SaveFrameworkState(IN UNIT_TEST_CONTEXT ContextToSave OPTIONAL, IN UINTN ContextToSaveSize)
UNIT_TEST_STATUS(EFIAPI * UNIT_TEST_PREREQUISITE)(IN UNIT_TEST_CONTEXT Context)
VOID(EFIAPI * UNIT_TEST_SUITE_TEARDOWN)(VOID)
EFI_STATUS EFIAPI CreateUnitTestSuite(OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle, IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *Name, IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL, IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL)
EFI_STATUS EFIAPI FreeUnitTestFramework(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
EFI_STATUS EFIAPI AddTestCase(IN UNIT_TEST_SUITE_HANDLE SuiteHandle, IN CHAR8 *Description, IN CHAR8 *Name, IN UNIT_TEST_FUNCTION Function, IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL, IN UNIT_TEST_CLEANUP CleanUp OPTIONAL, IN UNIT_TEST_CONTEXT Context OPTIONAL)
VOID(EFIAPI * UNIT_TEST_SUITE_SETUP)(VOID)
EFI_STATUS EFIAPI InitUnitTestFramework(OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *ShortTitle, IN CHAR8 *VersionString)
UNIT_TEST_STATUS(EFIAPI * UNIT_TEST_FUNCTION)(IN UNIT_TEST_CONTEXT Context)
VOID(EFIAPI * UNIT_TEST_CLEANUP)(IN UNIT_TEST_CONTEXT Context)
EFI_STATUS EFIAPI SaveUnitTestCache(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, IN VOID *SaveData, IN UINTN SaveStateSize)
EFI_STATUS EFIAPI LoadUnitTestCache(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, OUT VOID **SaveData, OUT UINTN *SaveStateSize)
BOOLEAN EFIAPI DoesCacheExist(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)