Skip to content

Commit

Permalink
Merge branch 'release/202302' into fancier_tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
kuqin12 authored Jan 26, 2024
2 parents 51bf64f + 832500f commit ca7fc9b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ InitializeInMemoryLog (

// Make sure the wrapper feature is enabled.
if (!FeaturePcdGet (PcdAdvancedLoggerAutoWrapEnable)) {
return UNIT_TEST_ERROR_TEST_FAILED;
return UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
}

//
Expand All @@ -185,6 +185,7 @@ InitializeInMemoryLog (

if (!ValidateInfoBlock ()) {
mLoggerInfo = NULL;
UT_ASSERT_NOT_NULL ((VOID *)mLoggerInfo);
}

// This is to bypass the restriction on runtime check.
Expand Down Expand Up @@ -220,6 +221,8 @@ TestCursorWrapping (

Btc = (BASIC_TEST_CONTEXT *)Context;

UT_ASSERT_TRUE (mLoggerInfo != NULL);

// First fill in the buffer
while (mLoggerInfo->LogCurrent + MESSAGE_ENTRY_SIZE_V2 (sizeof (ADVANCED_LOGGER_MESSAGE_ENTRY_V2), sizeof (ADV_TIME_TEST_STR)) < mMaxAddress) {
AdvancedLoggerWrite (DEBUG_ERROR, ADV_TIME_TEST_STR, sizeof (ADV_TIME_TEST_STR));
Expand Down Expand Up @@ -295,28 +298,27 @@ TestCursorWrappingMP (
IN UNIT_TEST_CONTEXT Context
)
{
BASIC_TEST_CONTEXT *Btc;
EFI_STATUS Status;
UINTN Index;
UINTN StrIndex;
UINTN NumberOfProcessors;
UINTN EnabledProcessors;
UINT8 *TempCache = NULL;
UNIT_TEST_STATUS UtStatus;
UINTN PrefixSize;
CHAR8 *EndPointer;
BASIC_TEST_CONTEXT *Btc;
EFI_STATUS Status;
UINTN Index;
UINTN StrIndex;
UINTN NumberOfProcessors;
UINTN EnabledProcessors;
UINT8 *TempCache = NULL;
UINTN PrefixSize;
CHAR8 EndChar;
EFI_PROCESSOR_INFORMATION CpuInfo;

Btc = (BASIC_TEST_CONTEXT *)Context;

UT_ASSERT_NOT_NULL ((VOID *)mLoggerInfo);

// First fill in the buffer
while (mLoggerInfo->LogCurrent + MESSAGE_ENTRY_SIZE_V2 (sizeof (ADVANCED_LOGGER_MESSAGE_ENTRY_V2), sizeof (ADV_TIME_TEST_STR)) < mMaxAddress) {
AdvancedLoggerWrite (DEBUG_ERROR, ADV_TIME_TEST_STR, sizeof (ADV_TIME_TEST_STR));
}

if (mMpServicesProtocol == NULL) {
UtStatus = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
goto Done;
}
UT_ASSERT_NOT_NULL (mMpServicesProtocol);

Status = mMpServicesProtocol->StartupAllAPs (
mMpServicesProtocol,
Expand All @@ -327,35 +329,32 @@ TestCursorWrappingMP (
NULL,
NULL
);
if (EFI_ERROR (Status)) {
UtStatus = UNIT_TEST_ERROR_TEST_FAILED;
goto Done;
}
UT_ASSERT_NOT_EFI_ERROR (Status);

// BSP needs to run the procedure as well...
ApProcedure (NULL);

Status = mMpServicesProtocol->GetNumberOfProcessors (mMpServicesProtocol, &NumberOfProcessors, &EnabledProcessors);
if (EFI_ERROR (Status)) {
UtStatus = UNIT_TEST_ERROR_TEST_FAILED;
goto Done;
}
UT_ASSERT_NOT_EFI_ERROR (Status);

TempCache = AllocatePool (NumberOfProcessors * sizeof (UINT8));
if (TempCache == NULL) {
UtStatus = UNIT_TEST_ERROR_TEST_FAILED;
goto Done;
}
UT_ASSERT_NOT_NULL (TempCache);

// Initialize the cache to 0xFF
SetMem (TempCache, NumberOfProcessors * sizeof (UINT8), 0xFF);

for (Index = 0; Index < NumberOfProcessors; Index++) {
Status = AdvancedLoggerAccessLibGetNextFormattedLine (&mMessageEntry);
if (EFI_ERROR (Status)) {
UtStatus = UNIT_TEST_ERROR_TEST_FAILED;
goto Done;
Status = mMpServicesProtocol->GetProcessorInfo (mMpServicesProtocol, CPU_V2_EXTENDED_TOPOLOGY | Index, &CpuInfo);
UT_ASSERT_NOT_EFI_ERROR (Status);

if (CpuInfo.StatusFlag & PROCESSOR_ENABLED_BIT) {
TempCache[Index] = 0xFF;
} else {
TempCache[Index] = 0;
}
}

for (Index = 0; Index < EnabledProcessors; Index++) {
Status = AdvancedLoggerAccessLibGetNextFormattedLine (&mMessageEntry);
UT_ASSERT_TRUE ((Status == EFI_SUCCESS) || (Status == EFI_END_OF_FILE));

// HACKHACK: Bypass the potential print out from MpLib
if ((Index == 0) && (AsciiStrStr (mMessageEntry.Message, "5-Level Paging") != NULL)) {
Expand All @@ -365,9 +364,7 @@ TestCursorWrappingMP (

UT_ASSERT_NOT_NULL (mMessageEntry.Message);
UT_LOG_INFO ("\nReturn Length=%d\n", mMessageEntry.MessageLen);
UT_LOG_INFO ("\n = %a =\n", mMessageEntry.Message);
UT_LOG_INFO ("\nExpected Length=%d\n", AsciiStrLen (Btc->ExpectedLine));
UT_LOG_INFO ("\n = %a =\n", Btc->ExpectedLine);

if (mMessageEntry.MessageLen != AsciiStrLen (Btc->ExpectedLine)) {
DUMP_HEX (DEBUG_ERROR, 0, mMessageEntry.Message, mMessageEntry.MessageLen, "Actual - ");
Expand All @@ -392,47 +389,38 @@ TestCursorWrappingMP (
);

// Now check the index
EndPointer = &mMessageEntry.Message[ADV_TIME_STAMP_PREFIX_LEN + sizeof (ADV_WRAP_TEST_STR) + 8 - 1];
Status = AsciiStrHexToUintnS (
&mMessageEntry.Message[ADV_TIME_STAMP_PREFIX_LEN + sizeof (ADV_WRAP_TEST_STR) - 1],
&EndPointer,
&StrIndex
);
if (EFI_ERROR (Status)) {
UtStatus = UNIT_TEST_ERROR_TEST_FAILED;
goto Done;
}
// First cache the current value at the end of target sequence
EndChar = mMessageEntry.Message[ADV_TIME_STAMP_PREFIX_LEN + PrefixSize + 8];

if (StrIndex >= NumberOfProcessors) {
// Index is out of range
UtStatus = UNIT_TEST_ERROR_TEST_FAILED;
goto Done;
}
// Then set that char to NULL
mMessageEntry.Message[ADV_TIME_STAMP_PREFIX_LEN + PrefixSize + 8] = '\0';

if (TempCache[StrIndex] == 0) {
// Printed this index already
UtStatus = UNIT_TEST_ERROR_TEST_FAILED;
goto Done;
} else {
TempCache[StrIndex] = 0;
}
}
// Then convert the string to a number
Status = AsciiStrHexToUintnS (
&mMessageEntry.Message[ADV_TIME_STAMP_PREFIX_LEN + PrefixSize],
NULL,
&StrIndex
);
UT_ASSERT_NOT_EFI_ERROR (Status);

if (!IsZeroBuffer (TempCache, NumberOfProcessors * sizeof (UINT8))) {
UtStatus = UNIT_TEST_ERROR_TEST_FAILED;
goto Done;
// Now we can set the char back to what it was
mMessageEntry.Message[ADV_TIME_STAMP_PREFIX_LEN + PrefixSize + 8] = EndChar;

UT_ASSERT_TRUE (StrIndex < NumberOfProcessors);

UT_ASSERT_TRUE (TempCache[StrIndex] == 0xFF);
TempCache[StrIndex] = 0;
}

UtStatus = UNIT_TEST_PASSED;
UT_ASSERT_TRUE (IsZeroBuffer (TempCache, NumberOfProcessors * sizeof (UINT8)));

Done:
if (TempCache != NULL) {
FreePool (TempCache);
}

Btc->MemoryToFree = mMessageEntry.Message;

return UtStatus;
return UNIT_TEST_PASSED;
}

/// ================================================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
UefiApplicationEntryPoint
UefiLib
UnitTestLib
UefiBootServicesTableLib

[FeaturePcd]
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerAutoWrapEnable

0 comments on commit ca7fc9b

Please sign in to comment.