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

@ -159,6 +159,7 @@ AllocateAlignedPages (
if (Alignment < SIZE_4KB) {
Alignment = SIZE_4KB;
}
AlignmentMask = Alignment - 1;
//
@ -171,6 +172,7 @@ AllocateAlignedPages (
if (PageHead.AllocatedBufffer == NULL) {
return NULL;
}
PageHead.AlignedBuffer = (VOID *)(((UINTN)PageHead.AllocatedBufffer + AlignmentMask) & ~AlignmentMask);
if ((UINTN)PageHead.AlignedBuffer - (UINTN)PageHead.AllocatedBufffer < sizeof (PAGE_HEAD)) {
PageHead.AlignedBuffer = (VOID *)((UINTN)PageHead.AlignedBuffer + Alignment);
@ -271,6 +273,7 @@ FreeAlignedPages (
if (PageHeadPtr->Signature != PAGE_HEAD_PRIVATE_SIGNATURE) {
return;
}
if (PageHeadPtr->AlignedPages != Pages) {
return;
}
@ -366,6 +369,7 @@ AllocateZeroPool (
if (Buffer == NULL) {
return NULL;
}
memset (Buffer, 0, AllocationSize);
return Buffer;
}
@ -444,6 +448,7 @@ AllocateCopyPool (
if (Memory == NULL) {
return NULL;
}
memcpy (Memory, Buffer, AllocationSize);
return Memory;
}
@ -534,12 +539,14 @@ ReallocatePool (
VOID *NewBuffer;
NewBuffer = malloc (NewSize);
if (NewBuffer != NULL && OldBuffer != NULL) {
if ((NewBuffer != NULL) && (OldBuffer != NULL)) {
memcpy (NewBuffer, OldBuffer, MIN (OldSize, NewSize));
}
if (OldBuffer != NULL) {
FreePool (OldBuffer);
}
return NewBuffer;
}

View File

@ -117,11 +117,14 @@ CLEANUP:
if (Dp != NULL) {
FreePool (Dp);
}
if (DpEnd != NULL) {
FreePool (DpEnd);
}
if (NewOptionValid) {
EfiBootManagerFreeLoadOption (&NewOption);
}
return Status;
}

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,6 +216,7 @@ UnitTestAssertNotEfiError (
Status
);
}
return !EFI_ERROR (Status);
}
@ -271,6 +274,7 @@ UnitTestAssertEqual (
ValueB
);
}
return (ValueA == ValueB);
}
@ -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

@ -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);
_assert_true (FALSE, TempStr, FileName, (INT32)LineNumber);
}
return (UnitTestStatus != UNIT_TEST_ERROR_TEST_FAILED);
}

View File

@ -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;
}

View File

@ -55,7 +55,8 @@ RunTestSuite (
//
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))
{
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,7 +76,7 @@ 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) {
@ -167,7 +168,8 @@ RunAllTestSuites (
//
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)) {
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

@ -132,6 +132,7 @@ CmockaUnitTestSuiteSetupFunctionRunner (
if (mActiveUnitTestSuite == NULL) {
return -1;
}
if (mActiveUnitTestSuite->Setup == NULL) {
return 0;
}
@ -151,6 +152,7 @@ CmockaUnitTestSuiteTeardownFunctionRunner (
if (mActiveUnitTestSuite == NULL) {
return -1;
}
if (mActiveUnitTestSuite->Teardown == NULL) {
return 0;
}
@ -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);
//
@ -264,7 +268,8 @@ RunAllTestSuites (
//
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)) {
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

@ -61,6 +61,7 @@ AllocateAndCopyString (
if (NewString != NULL) {
AsciiStrCpyS (NewString, NewStringLength, StringToCopy);
}
return NewString;
}
@ -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));
//
@ -468,6 +472,7 @@ AddTestCase (
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
if (NewTestEntry->UT.Name == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
@ -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,8 +596,9 @@ 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.
//
@ -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;
}
@ -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.
//
@ -737,7 +748,6 @@ SerializeState (
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,7 +772,7 @@ SerializeState (
//
// If there is a context to save, let's do that now.
//
if (ContextToSave != NULL && Framework->CurrentTest != NULL) {
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);
@ -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;
}

View File

@ -71,6 +71,7 @@ GetCacheFileDevicePath (
if (!TestName) {
goto Exit;
}
AsciiStrToUnicodeStrS (Framework->ShortTitle, TestName, CacheFilePathLength);
//
@ -99,6 +100,7 @@ GetCacheFileDevicePath (
if (AppPath[DirectorySlashOffset] == L'\\') {
break;
}
DirectorySlashOffset--;
} while (DirectorySlashOffset > 0);
@ -143,9 +145,11 @@ Exit:
if (AppPath != NULL) {
FreePool (AppPath);
}
if (CacheFilePath != NULL) {
FreePool (CacheFilePath);
}
if (TestName != NULL) {
FreePool (TestName);
}
@ -229,7 +233,7 @@ SaveUnitTestCache (
//
// Check the inputs for sanity.
//
if (FrameworkHandle == NULL || SaveData == NULL) {
if ((FrameworkHandle == NULL) || (SaveData == NULL)) {
return EFI_INVALID_PARAMETER;
}
@ -284,7 +288,7 @@ SaveUnitTestCache (
SaveData
);
if (EFI_ERROR (Status) || WriteCount != SaveData->SaveStateSize) {
if (EFI_ERROR (Status) || (WriteCount != SaveData->SaveStateSize)) {
DEBUG ((DEBUG_ERROR, "%a - Writing to file failed! %r\n", __FUNCTION__, Status));
} else {
DEBUG ((DEBUG_INFO, "%a - SUCCESS!\n", __FUNCTION__));
@ -338,7 +342,7 @@ LoadUnitTestCache (
//
// Check the inputs for sanity.
//
if (FrameworkHandle == NULL || SaveData == NULL) {
if ((FrameworkHandle == NULL) || (SaveData == NULL)) {
return EFI_INVALID_PARAMETER;
}
@ -399,6 +403,7 @@ Exit:
if (FileDevicePath != NULL) {
FreePool (FileDevicePath);
}
if (IsFileOpened) {
ShellCloseFile (&FileHandle);
}
@ -406,7 +411,7 @@ Exit:
//
// If we're returning an error, make sure
// the state is sane.
if (EFI_ERROR (Status) && Buffer != NULL) {
if (EFI_ERROR (Status) && (Buffer != NULL)) {
FreePool (Buffer);
Buffer = NULL;
}

View File

@ -75,6 +75,7 @@ GetStringForUnitTestStatus (
return mStatusStrings[Index].String;
}
}
//
// Return last entry if no match found.
//
@ -97,6 +98,7 @@ GetStringForFailureType (
return mFailureTypeStrings[Index].String;
}
}
//
// Return last entry if no match found.
//
@ -146,8 +148,8 @@ OutputUnitTestFrameworkReport (
//
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)) {
Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetNextNode (&Framework->TestSuiteList, (LIST_ENTRY *)Suite))
{
Test = NULL;
SPassed = 0;
SFailed = 0;
@ -163,8 +165,8 @@ OutputUnitTestFrameworkReport (
//
for (Test = (UNIT_TEST_LIST_ENTRY *)GetFirstNode (&(Suite->UTS.TestCaseList));
(LIST_ENTRY *)Test != &(Suite->UTS.TestCaseList);
Test = (UNIT_TEST_LIST_ENTRY*)GetNextNode(&(Suite->UTS.TestCaseList), (LIST_ENTRY*)Test)) {
Test = (UNIT_TEST_LIST_ENTRY *)GetNextNode (&(Suite->UTS.TestCaseList), (LIST_ENTRY *)Test))
{
ReportPrint ("*********************************************************\n");
ReportPrint (" CLASS NAME: %a\n", Test->UT.Name);
ReportPrint (" TEST: %a\n", Test->UT.Description);
@ -192,6 +194,7 @@ OutputUnitTestFrameworkReport (
default:
break;
}
ReportPrint ("**********************************************************\n");
} // End Test iteration

View File

@ -29,6 +29,7 @@ ReportPrint (
} else {
gST->ConOut->OutputString (gST->ConOut, String);
}
VA_END (Marker);
}

View File

@ -28,6 +28,7 @@ ReportPrint (
} else {
DEBUG ((DEBUG_INFO, String));
}
VA_END (Marker);
}

View File

@ -684,6 +684,7 @@ UefiTestMain (
Status = EFI_OUT_OF_RESOURCES;
goto EXIT;
}
AddTestCase (SimpleMathTests, "Adding 1 to 1 should produce 2", "Addition", OnePlusOneShouldEqualTwo, NULL, NULL, NULL);
//
@ -695,6 +696,7 @@ UefiTestMain (
Status = EFI_OUT_OF_RESOURCES;
goto EXIT;
}
AddTestCase (GlobalVarTests, "You should be able to change a global BOOLEAN", "Boolean", GlobalBooleanShouldBeChangeable, NULL, NULL, NULL);
AddTestCase (GlobalVarTests, "You should be able to change a global pointer", "Pointer", GlobalPointerShouldBeChangeable, MakeSureThatPointerIsNull, ClearThePointer, NULL);
@ -707,6 +709,7 @@ UefiTestMain (
Status = EFI_OUT_OF_RESOURCES;
goto EXIT;
}
AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_TRUE() macro", "MacroUtAssertTrue", MacroUtAssertTrue, NULL, NULL, NULL);
AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_FALSE() macro", "MacroUtAssertFalse", MacroUtAssertFalse, NULL, NULL, NULL);
AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_EQUAL() macro", "MacroUtAssertEqual", MacroUtAssertEqual, NULL, NULL, NULL);
@ -731,6 +734,7 @@ UefiTestMain (
Status = EFI_OUT_OF_RESOURCES;
goto EXIT;
}
AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_TRUE() macro", "MacroUtAssertTrue", MacroUtAssertTrue, NULL, NULL, NULL);
AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_FALSE() macro", "MacroUtAssertFalse", MacroUtAssertFalse, NULL, NULL, NULL);
AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_EQUAL() macro", "MacroUtAssertEqual", MacroUtAssertEqual, NULL, NULL, NULL);