UnitTestFrameworkPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the UnitTestFrameworkPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:19 -08:00
committed by mergify[bot]
parent e5efcf8be8
commit 7c0ad2c338
18 changed files with 368 additions and 309 deletions

View File

@@ -26,7 +26,7 @@ AddUnitTestFailure (
//
// Make sure that you're cooking with gas.
//
if (UnitTest == NULL || FailureMessage == NULL) {
if ((UnitTest == NULL) || (FailureMessage == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -120,6 +120,7 @@ UnitTestAssertTrue (
Description
);
}
return Expression;
}
@@ -166,6 +167,7 @@ UnitTestAssertFalse (
Description
);
}
return !Expression;
}
@@ -214,7 +216,8 @@ UnitTestAssertNotEfiError (
Status
);
}
return !EFI_ERROR( Status );
return !EFI_ERROR (Status);
}
/**
@@ -271,6 +274,7 @@ UnitTestAssertEqual (
ValueB
);
}
return (ValueA == ValueB);
}
@@ -312,7 +316,7 @@ UnitTestAssertMemEqual (
IN CONST CHAR8 *DescriptionB
)
{
if (CompareMem(BufferA, BufferB, Length) != 0) {
if (CompareMem (BufferA, BufferB, Length) != 0) {
UT_LOG_ERROR (
"[ASSERT FAIL] %a:%d: Value %a != %a for length %d bytes!\n",
FileName,
@@ -332,6 +336,7 @@ UnitTestAssertMemEqual (
);
return FALSE;
}
return TRUE;
}
@@ -389,6 +394,7 @@ UnitTestAssertNotEqual (
ValueB
);
}
return (ValueA != ValueB);
}
@@ -442,6 +448,7 @@ UnitTestAssertStatusEqual (
Expected
);
}
return (Status == Expected);
}
@@ -490,6 +497,7 @@ UnitTestAssertNotNull (
PointerName
);
}
return (Pointer != NULL);
}
@@ -536,6 +544,7 @@ UnitTestExpectAssertFailure (
if (ResultStatus != NULL) {
*ResultStatus = UnitTestStatus;
}
if (UnitTestStatus == UNIT_TEST_PASSED) {
UT_LOG_INFO (
"[ASSERT PASS] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) detected expected assert\n",
@@ -544,6 +553,7 @@ UnitTestExpectAssertFailure (
FunctionCall
);
}
if (UnitTestStatus == UNIT_TEST_SKIPPED) {
UT_LOG_WARNING (
"[ASSERT WARN] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) disabled\n",
@@ -552,6 +562,7 @@ UnitTestExpectAssertFailure (
FunctionCall
);
}
if (UnitTestStatus == UNIT_TEST_ERROR_TEST_FAILED) {
UT_LOG_ERROR (
"[ASSERT FAIL] %a:%d: Function call (%a) did not ASSERT()!\n",
@@ -567,5 +578,6 @@ UnitTestExpectAssertFailure (
FunctionCall
);
}
return (UnitTestStatus != UNIT_TEST_ERROR_TEST_FAILED);
}

View File

@@ -48,7 +48,7 @@ UnitTestAssertTrue (
{
CHAR8 TempStr[MAX_STRING_SIZE];
snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_TRUE(%s:%x)", Description, Expression);
snprintf (TempStr, sizeof (TempStr), "UT_ASSERT_TRUE(%s:%x)", Description, Expression);
_assert_true (Expression, TempStr, FileName, (INT32)LineNumber);
return Expression;
@@ -84,7 +84,7 @@ UnitTestAssertFalse (
{
CHAR8 TempStr[MAX_STRING_SIZE];
snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_FALSE(%s:%x)", Description, Expression);
snprintf (TempStr, sizeof (TempStr), "UT_ASSERT_FALSE(%s:%x)", Description, Expression);
_assert_true (!Expression, TempStr, FileName, (INT32)LineNumber);
return !Expression;
@@ -120,7 +120,7 @@ UnitTestAssertNotEfiError (
{
CHAR8 TempStr[MAX_STRING_SIZE];
snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_NOT_EFI_ERROR(%s:%p)", Description, (void *)Status);
snprintf (TempStr, sizeof (TempStr), "UT_ASSERT_NOT_EFI_ERROR(%s:%p)", Description, (void *)Status);
_assert_true (!EFI_ERROR (Status), TempStr, FileName, (INT32)LineNumber);
return !EFI_ERROR (Status);
@@ -161,7 +161,7 @@ UnitTestAssertEqual (
{
CHAR8 TempStr[MAX_STRING_SIZE];
snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_EQUAL(%s:%llx, %s:%llx)", DescriptionA, ValueA, DescriptionB, ValueB);
snprintf (TempStr, sizeof (TempStr), "UT_ASSERT_EQUAL(%s:%llx, %s:%llx)", DescriptionA, ValueA, DescriptionB, ValueB);
_assert_true ((ValueA == ValueB), TempStr, FileName, (INT32)LineNumber);
return (ValueA == ValueB);
@@ -208,9 +208,9 @@ UnitTestAssertMemEqual (
CHAR8 TempStr[MAX_STRING_SIZE];
BOOLEAN Result;
Result = (CompareMem(BufferA, BufferB, Length) == 0);
Result = (CompareMem (BufferA, BufferB, Length) == 0);
snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_MEM_EQUAL(%s:%p, %s:%p)", DescriptionA, BufferA, DescriptionB, BufferB);
snprintf (TempStr, sizeof (TempStr), "UT_ASSERT_MEM_EQUAL(%s:%p, %s:%p)", DescriptionA, BufferA, DescriptionB, BufferB);
_assert_true (Result, TempStr, FileName, (INT32)LineNumber);
return Result;
@@ -251,7 +251,7 @@ UnitTestAssertNotEqual (
{
CHAR8 TempStr[MAX_STRING_SIZE];
snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_NOT_EQUAL(%s:%llx, %s:%llx)", DescriptionA, ValueA, DescriptionB, ValueB);
snprintf (TempStr, sizeof (TempStr), "UT_ASSERT_NOT_EQUAL(%s:%llx, %s:%llx)", DescriptionA, ValueA, DescriptionB, ValueB);
_assert_true ((ValueA != ValueB), TempStr, FileName, (INT32)LineNumber);
return (ValueA != ValueB);
@@ -290,7 +290,7 @@ UnitTestAssertStatusEqual (
{
CHAR8 TempStr[MAX_STRING_SIZE];
snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_STATUS_EQUAL(%s:%p)", Description, (VOID *)Status);
snprintf (TempStr, sizeof (TempStr), "UT_ASSERT_STATUS_EQUAL(%s:%p)", Description, (VOID *)Status);
_assert_true ((Status == Expected), TempStr, FileName, (INT32)LineNumber);
return (Status == Expected);
@@ -328,7 +328,7 @@ UnitTestAssertNotNull (
{
CHAR8 TempStr[MAX_STRING_SIZE];
snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_NOT_NULL(%s:%p)", PointerName, Pointer);
snprintf (TempStr, sizeof (TempStr), "UT_ASSERT_NOT_NULL(%s:%p)", PointerName, Pointer);
_assert_true ((Pointer != NULL), TempStr, FileName, (INT32)LineNumber);
return (Pointer != NULL);
@@ -379,6 +379,7 @@ UnitTestExpectAssertFailure (
if (ResultStatus != NULL) {
*ResultStatus = UnitTestStatus;
}
if (UnitTestStatus == UNIT_TEST_PASSED) {
UT_LOG_INFO (
"[ASSERT PASS] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) detected expected assert\n",
@@ -387,6 +388,7 @@ UnitTestExpectAssertFailure (
FunctionCall
);
}
if (UnitTestStatus == UNIT_TEST_SKIPPED) {
UT_LOG_WARNING (
"[ASSERT WARN] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) disabled\n",
@@ -395,9 +397,11 @@ UnitTestExpectAssertFailure (
FunctionCall
);
}
if (UnitTestStatus == UNIT_TEST_ERROR_TEST_FAILED) {
snprintf (TempStr, sizeof(TempStr), "UT_EXPECT_ASSERT_FAILURE(%s) did not trigger ASSERT()", FunctionCall);
snprintf (TempStr, sizeof (TempStr), "UT_EXPECT_ASSERT_FAILURE(%s) did not trigger ASSERT()", FunctionCall);
_assert_true (FALSE, TempStr, FileName, (INT32)LineNumber);
}
return (UnitTestStatus != UNIT_TEST_ERROR_TEST_FAILED);
}

View File

@@ -19,8 +19,8 @@
#define UNIT_TEST_MAX_LOG_BUFFER SIZE_16KB
struct _UNIT_TEST_LOG_PREFIX_STRING {
UNIT_TEST_STATUS LogLevel;
CHAR8 *String;
UNIT_TEST_STATUS LogLevel;
CHAR8 *String;
};
struct _UNIT_TEST_LOG_PREFIX_STRING mLogPrefixStrings[] = {
@@ -35,7 +35,7 @@ struct _UNIT_TEST_LOG_PREFIX_STRING mLogPrefixStrings[] = {
//
STATIC
CONST CHAR8*
CONST CHAR8 *
GetStringForStatusLogPrefix (
IN UINTN LogLevel
)
@@ -50,6 +50,7 @@ GetStringForStatusLogPrefix (
break;
}
}
return Result;
}
@@ -65,7 +66,7 @@ AddStringToUnitTestLog (
//
// Make sure that you're cooking with gas.
//
if (UnitTest == NULL || String == NULL) {
if ((UnitTest == NULL) || (String == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -86,7 +87,7 @@ AddStringToUnitTestLog (
String,
UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH
);
if(EFI_ERROR (Status)) {
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to add unit test log string. Status = %r\n", Status));
return Status;
}
@@ -129,14 +130,14 @@ UnitTestLogInit (
}
//
//check again to make sure allocate worked
// check again to make sure allocate worked
//
if(Test->Log == NULL) {
if (Test->Log == NULL) {
DEBUG ((DEBUG_ERROR, "Failed to allocate memory for the log\n"));
return;
}
if((Buffer != NULL) && (BufferSize > 0) && (BufferSize <= UNIT_TEST_MAX_LOG_BUFFER)) {
if ((Buffer != NULL) && (BufferSize > 0) && (BufferSize <= UNIT_TEST_MAX_LOG_BUFFER)) {
CopyMem (Test->Log, Buffer, BufferSize);
}
}

View File

@@ -54,8 +54,9 @@ RunTestSuite (
// Iterate all tests within the suite
//
for (TestEntry = (UNIT_TEST_LIST_ENTRY *)GetFirstNode (&(Suite->TestCaseList));
(LIST_ENTRY*)TestEntry != &(Suite->TestCaseList);
TestEntry = (UNIT_TEST_LIST_ENTRY *)GetNextNode (&(Suite->TestCaseList), (LIST_ENTRY *)TestEntry)) {
(LIST_ENTRY *)TestEntry != &(Suite->TestCaseList);
TestEntry = (UNIT_TEST_LIST_ENTRY *)GetNextNode (&(Suite->TestCaseList), (LIST_ENTRY *)TestEntry))
{
Test = &TestEntry->UT;
ParentFramework->CurrentTest = Test;
@@ -67,7 +68,7 @@ RunTestSuite (
// First, check to see whether the test has already been run.
// NOTE: This would generally only be the case if a saved state was detected and loaded.
//
if (Test->Result != UNIT_TEST_PENDING && Test->Result != UNIT_TEST_RUNNING) {
if ((Test->Result != UNIT_TEST_PENDING) && (Test->Result != UNIT_TEST_RUNNING)) {
DEBUG ((DEBUG_VERBOSE, "Test was run on a previous pass. Skipping.\n"));
ParentFramework->CurrentTest = NULL;
continue;
@@ -75,19 +76,19 @@ RunTestSuite (
//
// Next, if we're still running, make sure that our test prerequisites are in place.
if (Test->Result == UNIT_TEST_PENDING && Test->Prerequisite != NULL) {
if ((Test->Result == UNIT_TEST_PENDING) && (Test->Prerequisite != NULL)) {
DEBUG ((DEBUG_VERBOSE, "PREREQ\n"));
if (SetJump (&gUnitTestJumpBuffer) == 0) {
if (Test->Prerequisite (Test->Context) != UNIT_TEST_PASSED) {
DEBUG ((DEBUG_ERROR, "Prerequisite Not Met\n"));
Test->Result = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
ParentFramework->CurrentTest = NULL;
Test->Result = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
ParentFramework->CurrentTest = NULL;
continue;
}
} else {
DEBUG ((DEBUG_ERROR, "Prerequisite Not Met\n"));
Test->Result = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
ParentFramework->CurrentTest = NULL;
Test->Result = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
ParentFramework->CurrentTest = NULL;
continue;
}
}
@@ -166,8 +167,9 @@ RunAllTestSuites (
// Iterate all suites
//
for (Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetFirstNode (&Framework->TestSuiteList);
(LIST_ENTRY *)Suite != &Framework->TestSuiteList;
Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetNextNode (&Framework->TestSuiteList, (LIST_ENTRY *)Suite)) {
(LIST_ENTRY *)Suite != &Framework->TestSuiteList;
Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetNextNode (&Framework->TestSuiteList, (LIST_ENTRY *)Suite))
{
Status = RunTestSuite (&(Suite->UTS));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Test Suite Failed with Error. %r\n", Status));

View File

@@ -38,7 +38,7 @@ UNIT_TEST_SUITE *mActiveUnitTestSuite = NULL;
void
CmockaUnitTestFunctionRunner (
void **state
void **state
)
{
UNIT_TEST *UnitTest;
@@ -52,16 +52,16 @@ CmockaUnitTestFunctionRunner (
if (UnitTest->RunTest == NULL) {
UnitTest->Result = UNIT_TEST_SKIPPED;
} else {
UnitTest->Result = UNIT_TEST_RUNNING;
UnitTest->Result = UNIT_TEST_RUNNING;
Framework->CurrentTest = UnitTest;
UnitTest->Result = UnitTest->RunTest (UnitTest->Context);
UnitTest->Result = UnitTest->RunTest (UnitTest->Context);
Framework->CurrentTest = NULL;
}
}
int
CmockaUnitTestSetupFunctionRunner (
void **state
void **state
)
{
UNIT_TEST *UnitTest;
@@ -78,7 +78,7 @@ CmockaUnitTestSetupFunctionRunner (
}
Framework->CurrentTest = UnitTest;
Result = UnitTest->Prerequisite (UnitTest->Context);
Result = UnitTest->Prerequisite (UnitTest->Context);
Framework->CurrentTest = NULL;
//
@@ -89,7 +89,7 @@ CmockaUnitTestSetupFunctionRunner (
int
CmockaUnitTestTeardownFunctionRunner (
void **state
void **state
)
{
UNIT_TEST *UnitTest;
@@ -112,10 +112,10 @@ CmockaUnitTestTeardownFunctionRunner (
// stdout and stderr in their xml format
//
if (UnitTest->Log != NULL) {
print_message("UnitTest: %s - %s\n", UnitTest->Name, UnitTest->Description);
print_message("Log Output Start\n");
print_message("%s", UnitTest->Log);
print_message("Log Output End\n");
print_message ("UnitTest: %s - %s\n", UnitTest->Name, UnitTest->Description);
print_message ("Log Output Start\n");
print_message ("%s", UnitTest->Log);
print_message ("Log Output End\n");
}
//
@@ -126,12 +126,13 @@ CmockaUnitTestTeardownFunctionRunner (
int
CmockaUnitTestSuiteSetupFunctionRunner (
void **state
void **state
)
{
if (mActiveUnitTestSuite == NULL) {
return -1;
}
if (mActiveUnitTestSuite->Setup == NULL) {
return 0;
}
@@ -145,12 +146,13 @@ CmockaUnitTestSuiteSetupFunctionRunner (
int
CmockaUnitTestSuiteTeardownFunctionRunner (
void **state
void **state
)
{
if (mActiveUnitTestSuite == NULL) {
return -1;
}
if (mActiveUnitTestSuite->Teardown == NULL) {
return 0;
}
@@ -173,7 +175,7 @@ RunTestSuite (
struct CMUnitTest *Tests;
UINTN Index;
TestEntry = NULL;
TestEntry = NULL;
if (Suite == NULL) {
return EFI_INVALID_PARAMETER;
@@ -195,7 +197,8 @@ RunTestSuite (
Index = 0;
for (TestEntry = (UNIT_TEST_LIST_ENTRY *)GetFirstNode (&(Suite->TestCaseList));
(LIST_ENTRY *)TestEntry != &(Suite->TestCaseList);
TestEntry = (UNIT_TEST_LIST_ENTRY *)GetNextNode (&(Suite->TestCaseList), (LIST_ENTRY *)TestEntry)) {
TestEntry = (UNIT_TEST_LIST_ENTRY *)GetNextNode (&(Suite->TestCaseList), (LIST_ENTRY *)TestEntry))
{
UnitTest = &TestEntry->UT;
Tests[Index].name = UnitTest->Description;
Tests[Index].test_func = CmockaUnitTestFunctionRunner;
@@ -204,6 +207,7 @@ RunTestSuite (
Tests[Index].initial_state = UnitTest;
Index++;
}
ASSERT (Index == Suite->NumTests);
//
@@ -254,17 +258,18 @@ RunAllTestSuites (
return EFI_INVALID_PARAMETER;
}
DEBUG((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
DEBUG((DEBUG_VERBOSE, "------------ RUNNING ALL TEST SUITES --------------\n"));
DEBUG((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
DEBUG ((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
DEBUG ((DEBUG_VERBOSE, "------------ RUNNING ALL TEST SUITES --------------\n"));
DEBUG ((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
mFrameworkHandle = FrameworkHandle;
//
// Iterate all suites
//
for (Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetFirstNode (&Framework->TestSuiteList);
(LIST_ENTRY *)Suite != &Framework->TestSuiteList;
Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetNextNode (&Framework->TestSuiteList, (LIST_ENTRY *)Suite)) {
(LIST_ENTRY *)Suite != &Framework->TestSuiteList;
Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetNextNode (&Framework->TestSuiteList, (LIST_ENTRY *)Suite))
{
Status = RunTestSuite (&(Suite->UTS));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Test Suite Failed with Error. %r\n", Status));

View File

@@ -47,7 +47,7 @@ IsFrameworkShortNameValid (
}
STATIC
CHAR8*
CHAR8 *
AllocateAndCopyString (
IN CHAR8 *StringToCopy
)
@@ -55,12 +55,13 @@ AllocateAndCopyString (
CHAR8 *NewString;
UINTN NewStringLength;
NewString = NULL;
NewString = NULL;
NewStringLength = AsciiStrnLenS (StringToCopy, UNIT_TEST_MAX_STRING_LENGTH) + 1;
NewString = AllocatePool (NewStringLength * sizeof( CHAR8 ));
NewString = AllocatePool (NewStringLength * sizeof (CHAR8));
if (NewString != NULL) {
AsciiStrCpyS (NewString, NewStringLength, StringToCopy);
}
return NewString;
}
@@ -74,10 +75,10 @@ SetFrameworkFingerprint (
UINT32 NewFingerprint;
// For this one we'll just use the title and version as the unique fingerprint.
NewFingerprint = CalculateCrc32( Framework->Title, (AsciiStrLen( Framework->Title ) * sizeof( CHAR8 )) );
NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32( Framework->VersionString, (AsciiStrLen( Framework->VersionString ) * sizeof( CHAR8 )) );
NewFingerprint = CalculateCrc32 (Framework->Title, (AsciiStrLen (Framework->Title) * sizeof (CHAR8)));
NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32 (Framework->VersionString, (AsciiStrLen (Framework->VersionString) * sizeof (CHAR8)));
CopyMem( Fingerprint, &NewFingerprint, UNIT_TEST_FINGERPRINT_SIZE );
CopyMem (Fingerprint, &NewFingerprint, UNIT_TEST_FINGERPRINT_SIZE);
return;
}
@@ -92,11 +93,11 @@ SetSuiteFingerprint (
UINT32 NewFingerprint;
// For this one, we'll use the fingerprint from the framework, and the title of the suite.
NewFingerprint = CalculateCrc32( &Framework->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE );
NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32( Suite->Title, (AsciiStrLen( Suite->Title ) * sizeof( CHAR8 )) );
NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32( Suite->Name, (AsciiStrLen(Suite->Name) * sizeof(CHAR8)) );
NewFingerprint = CalculateCrc32 (&Framework->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE);
NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32 (Suite->Title, (AsciiStrLen (Suite->Title) * sizeof (CHAR8)));
NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32 (Suite->Name, (AsciiStrLen (Suite->Name) * sizeof (CHAR8)));
CopyMem( Fingerprint, &NewFingerprint, UNIT_TEST_FINGERPRINT_SIZE );
CopyMem (Fingerprint, &NewFingerprint, UNIT_TEST_FINGERPRINT_SIZE);
return;
}
@@ -111,11 +112,11 @@ SetTestFingerprint (
UINT32 NewFingerprint;
// For this one, we'll use the fingerprint from the suite, and the description and classname of the test.
NewFingerprint = CalculateCrc32( &Suite->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE );
NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32( Test->Description, (AsciiStrLen( Test->Description ) * sizeof( CHAR8 )) );
NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32( Test->Name, (AsciiStrLen(Test->Name) * sizeof(CHAR8)) );
NewFingerprint = CalculateCrc32 (&Suite->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE);
NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32 (Test->Description, (AsciiStrLen (Test->Description) * sizeof (CHAR8)));
NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32 (Test->Name, (AsciiStrLen (Test->Name) * sizeof (CHAR8)));
CopyMem( Fingerprint, &NewFingerprint, UNIT_TEST_FINGERPRINT_SIZE );
CopyMem (Fingerprint, &NewFingerprint, UNIT_TEST_FINGERPRINT_SIZE);
return;
}
@@ -126,7 +127,7 @@ CompareFingerprints (
IN UINT8 *FingerprintB
)
{
return (CompareMem( FingerprintA, FingerprintB, UNIT_TEST_FINGERPRINT_SIZE ) == 0);
return (CompareMem (FingerprintA, FingerprintB, UNIT_TEST_FINGERPRINT_SIZE) == 0);
}
/**
@@ -216,8 +217,9 @@ InitUnitTestFramework (
//
// First, check all pointers and make sure nothing's broked.
//
if (FrameworkHandle == NULL || Title == NULL ||
ShortTitle == NULL || VersionString == NULL) {
if ((FrameworkHandle == NULL) || (Title == NULL) ||
(ShortTitle == NULL) || (VersionString == NULL))
{
return EFI_INVALID_PARAMETER;
}
@@ -246,12 +248,14 @@ InitUnitTestFramework (
NewFramework->Log = NULL;
NewFramework->CurrentTest = NULL;
NewFramework->SavedState = NULL;
if (NewFramework->Title == NULL ||
NewFramework->ShortTitle == NULL ||
NewFramework->VersionString == NULL) {
if ((NewFramework->Title == NULL) ||
(NewFramework->ShortTitle == NULL) ||
(NewFramework->VersionString == NULL))
{
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
InitializeListHead (&(NewFramework->TestSuiteList));
//
@@ -263,12 +267,12 @@ InitUnitTestFramework (
// If there is a persisted context, load it now.
//
if (DoesCacheExist (NewFrameworkHandle)) {
Status = LoadUnitTestCache (NewFrameworkHandle, (UNIT_TEST_SAVE_HEADER**)(&NewFramework->SavedState));
Status = LoadUnitTestCache (NewFrameworkHandle, (UNIT_TEST_SAVE_HEADER **)(&NewFramework->SavedState));
if (EFI_ERROR (Status)) {
//
// Don't actually report it as an error, but emit a warning.
//
DEBUG (( DEBUG_ERROR, "%a - Cache was detected, but failed to load.\n", __FUNCTION__ ));
DEBUG ((DEBUG_ERROR, "%a - Cache was detected, but failed to load.\n", __FUNCTION__));
Status = EFI_SUCCESS;
}
}
@@ -330,7 +334,7 @@ CreateUnitTestSuite (
UNIT_TEST_SUITE_LIST_ENTRY *NewSuiteEntry;
UNIT_TEST_FRAMEWORK *Framework;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
Framework = (UNIT_TEST_FRAMEWORK *)FrameworkHandle;
//
@@ -351,12 +355,12 @@ CreateUnitTestSuite (
//
// Copy the fields we think we need.
//
NewSuiteEntry->UTS.NumTests = 0;
NewSuiteEntry->UTS.Title = AllocateAndCopyString (Title);
NewSuiteEntry->UTS.Name = AllocateAndCopyString (Name);
NewSuiteEntry->UTS.Setup = Setup;
NewSuiteEntry->UTS.Teardown = Teardown;
NewSuiteEntry->UTS.ParentFramework = FrameworkHandle;
NewSuiteEntry->UTS.NumTests = 0;
NewSuiteEntry->UTS.Title = AllocateAndCopyString (Title);
NewSuiteEntry->UTS.Name = AllocateAndCopyString (Name);
NewSuiteEntry->UTS.Setup = Setup;
NewSuiteEntry->UTS.Teardown = Teardown;
NewSuiteEntry->UTS.ParentFramework = FrameworkHandle;
InitializeListHead (&(NewSuiteEntry->Entry)); // List entry for sibling suites.
InitializeListHead (&(NewSuiteEntry->UTS.TestCaseList)); // List entry for child tests.
if (NewSuiteEntry->UTS.Title == NULL) {
@@ -372,13 +376,13 @@ CreateUnitTestSuite (
//
// Create the suite fingerprint.
//
SetSuiteFingerprint( &NewSuiteEntry->UTS.Fingerprint[0], Framework, &NewSuiteEntry->UTS );
SetSuiteFingerprint (&NewSuiteEntry->UTS.Fingerprint[0], Framework, &NewSuiteEntry->UTS);
Exit:
//
// If everything is going well, add the new suite to the tail list for the framework.
//
if (!EFI_ERROR( Status )) {
if (!EFI_ERROR (Status)) {
InsertTailList (&(Framework->TestSuiteList), (LIST_ENTRY *)NewSuiteEntry);
*SuiteHandle = (UNIT_TEST_SUITE_HANDLE)(&NewSuiteEntry->UTS);
} else {
@@ -432,8 +436,8 @@ AddTestCase (
UNIT_TEST_FRAMEWORK *ParentFramework;
UNIT_TEST_SUITE *Suite;
Status = EFI_SUCCESS;
Suite = (UNIT_TEST_SUITE *)SuiteHandle;
Status = EFI_SUCCESS;
Suite = (UNIT_TEST_SUITE *)SuiteHandle;
//
// First, let's check to make sure that our parameters look good.
@@ -445,7 +449,7 @@ AddTestCase (
ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite->ParentFramework;
//
// Create the new entry.
NewTestEntry = AllocateZeroPool (sizeof( UNIT_TEST_LIST_ENTRY ));
NewTestEntry = AllocateZeroPool (sizeof (UNIT_TEST_LIST_ENTRY));
if (NewTestEntry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -468,6 +472,7 @@ AddTestCase (
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
if (NewTestEntry->UT.Name == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
@@ -492,7 +497,7 @@ Exit:
// If everything is going well, add the new suite to the tail list for the framework.
//
if (!EFI_ERROR (Status)) {
InsertTailList (&(Suite->TestCaseList), (LIST_ENTRY*)NewTestEntry);
InsertTailList (&(Suite->TestCaseList), (LIST_ENTRY *)NewTestEntry);
Suite->NumTests++;
} else {
//
@@ -520,9 +525,10 @@ UpdateTestFromSave (
//
// First, evaluate the inputs.
//
if (Test == NULL || SavedState == NULL) {
if ((Test == NULL) || (SavedState == NULL)) {
return;
}
if (SavedState->TestCount == 0) {
return;
}
@@ -590,18 +596,19 @@ UpdateTestFromSave (
// at the beginning of the context structure.
//
SavedContext = (UNIT_TEST_SAVE_CONTEXT *)FloatingPointer;
if ((SavedContext->Size - sizeof (UNIT_TEST_SAVE_CONTEXT)) > 0 &&
CompareFingerprints (&Test->Fingerprint[0], &SavedContext->Fingerprint[0])) {
if (((SavedContext->Size - sizeof (UNIT_TEST_SAVE_CONTEXT)) > 0) &&
CompareFingerprints (&Test->Fingerprint[0], &SavedContext->Fingerprint[0]))
{
//
// Override the test context with the saved context.
//
Test->Context = (VOID*)SavedContext->Data;
Test->Context = (VOID *)SavedContext->Data;
}
}
}
STATIC
UNIT_TEST_SAVE_HEADER*
UNIT_TEST_SAVE_HEADER *
SerializeState (
IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
IN UNIT_TEST_CONTEXT ContextToSave OPTIONAL,
@@ -628,9 +635,10 @@ SerializeState (
//
// First, let's not make assumptions about the parameters.
//
if (Framework == NULL ||
(ContextToSave != NULL && ContextToSaveSize == 0) ||
ContextToSaveSize > MAX_UINT32) {
if ((Framework == NULL) ||
((ContextToSave != NULL) && (ContextToSaveSize == 0)) ||
(ContextToSaveSize > MAX_UINT32))
{
return NULL;
}
@@ -658,11 +666,11 @@ SerializeState (
//
// Account for the size of a test structure.
//
TotalSize += sizeof( UNIT_TEST_SAVE_TEST );
TotalSize += sizeof (UNIT_TEST_SAVE_TEST);
//
// If there's a log, make sure to account for the log size.
//
if (UnitTest->Log != NULL) {
if (UnitTest->Log != NULL) {
//
// The +1 is for the NULL character. Can't forget the NULL character.
//
@@ -670,18 +678,21 @@ SerializeState (
ASSERT (LogSize < MAX_UINT32);
TotalSize += (UINT32)LogSize;
}
//
// Increment the test count.
//
TestCount++;
}
}
//
// If there are no tests, we're done here.
//
if (TestCount == 0) {
return NULL;
}
//
// Add room for the context, if there is one.
//
@@ -700,8 +711,8 @@ SerializeState (
//
// Alright, let's start setting up some data.
//
Header->Version = UNIT_TEST_PERSISTENCE_LIB_VERSION;
Header->SaveStateSize = TotalSize;
Header->Version = UNIT_TEST_PERSISTENCE_LIB_VERSION;
Header->SaveStateSize = TotalSize;
CopyMem (&Header->Fingerprint[0], &Framework->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE);
CopyMem (&Header->StartTime, &Framework->StartTime, sizeof (EFI_TIME));
Header->TestCount = TestCount;
@@ -711,7 +722,7 @@ SerializeState (
// Start adding all of the test cases.
// Set the floating pointer to the start of the current test save buffer.
//
FloatingPointer = (UINT8*)Header + sizeof( UNIT_TEST_SAVE_HEADER );
FloatingPointer = (UINT8 *)Header + sizeof (UNIT_TEST_SAVE_HEADER);
//
// Iterate all suites.
//
@@ -722,8 +733,8 @@ SerializeState (
//
TestListHead = &((UNIT_TEST_SUITE_LIST_ENTRY *)Suite)->UTS.TestCaseList;
for (Test = GetFirstNode (TestListHead); Test != TestListHead; Test = GetNextNode (TestListHead, Test)) {
TestSaveData = (UNIT_TEST_SAVE_TEST *)FloatingPointer;
UnitTest = &((UNIT_TEST_LIST_ENTRY *)Test)->UT;
TestSaveData = (UNIT_TEST_SAVE_TEST *)FloatingPointer;
UnitTest = &((UNIT_TEST_LIST_ENTRY *)Test)->UT;
//
// Save the fingerprint.
@@ -733,11 +744,10 @@ SerializeState (
//
// Save the result.
//
TestSaveData->Result = UnitTest->Result;
TestSaveData->Result = UnitTest->Result;
TestSaveData->FailureType = UnitTest->FailureType;
AsciiStrnCpyS (&TestSaveData->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH, &UnitTest->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH);
//
// If there is a log, save the log.
//
@@ -762,9 +772,9 @@ SerializeState (
//
// If there is a context to save, let's do that now.
//
if (ContextToSave != NULL && Framework->CurrentTest != NULL) {
TestSaveContext = (UNIT_TEST_SAVE_CONTEXT*)FloatingPointer;
TestSaveContext->Size = (UINT32)ContextToSaveSize + sizeof (UNIT_TEST_SAVE_CONTEXT);
if ((ContextToSave != NULL) && (Framework->CurrentTest != NULL)) {
TestSaveContext = (UNIT_TEST_SAVE_CONTEXT *)FloatingPointer;
TestSaveContext->Size = (UINT32)ContextToSaveSize + sizeof (UNIT_TEST_SAVE_CONTEXT);
CopyMem (&TestSaveContext->Fingerprint[0], &Framework->CurrentTest->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE);
CopyMem (((UINT8 *)TestSaveContext + sizeof (UNIT_TEST_SAVE_CONTEXT)), ContextToSave, ContextToSaveSize);
Header->HasSavedContext = TRUE;
@@ -804,15 +814,15 @@ SerializeState (
EFI_STATUS
EFIAPI
SaveFrameworkState (
IN UNIT_TEST_CONTEXT ContextToSave OPTIONAL,
IN UINTN ContextToSaveSize
IN UNIT_TEST_CONTEXT ContextToSave OPTIONAL,
IN UINTN ContextToSaveSize
)
{
EFI_STATUS Status;
UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle;
UNIT_TEST_SAVE_HEADER *Header;
Header = NULL;
Header = NULL;
FrameworkHandle = GetActiveFrameworkHandle ();
//
@@ -825,8 +835,9 @@ SaveFrameworkState (
//
// First, let's not make assumptions about the parameters.
//
if ((ContextToSave != NULL && ContextToSaveSize == 0) ||
ContextToSaveSize > MAX_UINT32) {
if (((ContextToSave != NULL) && (ContextToSaveSize == 0)) ||
(ContextToSaveSize > MAX_UINT32))
{
return EFI_INVALID_PARAMETER;
}