18#define UNIT_TEST_MAX_LOG_BUFFER SIZE_16KB
27 { UNIT_TEST_LOG_LEVEL_WARN,
"[WARNING] " },
28 { UNIT_TEST_LOG_LEVEL_INFO,
"[INFO] " },
29 { UNIT_TEST_LOG_LEVEL_VERBOSE,
"[VERBOSE] " }
38GetStringForStatusLogPrefix (
46 for (Index = 0; Index <
ARRAY_SIZE (mLogPrefixStrings); Index++) {
47 if (mLogPrefixStrings[Index].LogLevel == LogLevel) {
48 Result = mLogPrefixStrings[Index].String;
58AddStringToUnitTestLog (
68 if ((UnitTest ==
NULL) || (String ==
NULL)) {
69 return EFI_INVALID_PARAMETER;
73 if (UnitTest->Log ==
NULL) {
74 UnitTestLogInit (UnitTest,
NULL, 0);
77 if (UnitTest->Log ==
NULL) {
78 DEBUG ((DEBUG_ERROR,
"Failed to allocate space for unit test log\n"));
79 ASSERT (UnitTest->Log !=
NULL);
80 return EFI_OUT_OF_RESOURCES;
85 UNIT_TEST_MAX_LOG_BUFFER / sizeof (CHAR8),
89 if (EFI_ERROR (Status)) {
90 DEBUG ((DEBUG_ERROR,
"Failed to add unit test log string. Status = %r\n", Status));
112 IN UINT8 *Buffer OPTIONAL,
120 DEBUG ((DEBUG_ERROR,
"%a called with invalid Test parameter\n", __func__));
135 DEBUG ((DEBUG_ERROR,
"Failed to allocate memory for the log\n"));
139 if ((Buffer !=
NULL) && (BufferSize > 0) && (BufferSize <= UNIT_TEST_MAX_LOG_BUFFER)) {
161 UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle;
164 CONST CHAR8 *LogTypePrefix;
167 FrameworkHandle = GetActiveFrameworkHandle ();
168 if (FrameworkHandle ==
NULL) {
169 DEBUG ((DEBUG_ERROR,
"%a - FrameworkHandle not initialized\n", __func__));
173 LogTypePrefix =
NULL;
178 if ((ErrorLevel & (
UINTN)
PcdGet32 (PcdUnitTestLogLevel)) == 0) {
186 LogTypePrefix = GetStringForStatusLogPrefix (ErrorLevel);
187 if (LogTypePrefix !=
NULL) {
188 AsciiSPrint (NewFormatString,
sizeof (NewFormatString),
"%a%a", LogTypePrefix, Format);
190 AsciiStrCpyS (NewFormatString,
sizeof (NewFormatString), Format);
197 AsciiVSPrint (LogString,
sizeof (LogString), NewFormatString, Marker);
RETURN_STATUS EFIAPI AsciiStrnCatS(IN OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
RETURN_STATUS EFIAPI AsciiStrCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
UINTN EFIAPI AsciiVSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
#define VA_START(Marker, Parameter)
#define ARRAY_SIZE(Array)
#define DEBUG(Expression)
#define PcdGet32(TokenName)
INTN EFIAPI Test(CONST VOID *b1, CONST VOID *b2)
#define UNIT_TEST_MAX_STRING_LENGTH
VOID EFIAPI UnitTestLog(IN UINTN ErrorLevel, IN CONST CHAR8 *Format,...)
#define UNIT_TEST_LOG_LEVEL_ERROR