Skip to content

Commit

Permalink
UnitTestFrameworkPkg: UnitTestLib: Support Failure Strings of 512 Chars
Browse files Browse the repository at this point in the history
Currently, there is a mismatch of allowed string sizes in UnitTestLib.
The UT_LOG_* macros allow a string size of 512, but failure messages
are constrained to 120 characters and some other string lengths are
similarly constrained. 120 characters is too few for some longer
error messages, particularly the ones that print out the path to
the failing line. This can result in the actual error not getting
printed in the log.

This patch updates all UnitTestLib allowed string lengths to be 512
characters.

Signed-off-by: Oliver Smith-Denny <[email protected]>
  • Loading branch information
os-d authored and mergify[bot] committed Oct 8, 2024
1 parent d99045f commit 2ee050d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
4 changes: 2 additions & 2 deletions UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ AddUnitTestFailure (
UnitTest->FailureType = FailureType;
AsciiStrCpyS (
&UnitTest->FailureMessage[0],
UNIT_TEST_TESTFAILUREMSG_LENGTH,
UNIT_TEST_MAX_STRING_LENGTH,
FailureMessage
);

Expand All @@ -50,7 +50,7 @@ UnitTestLogFailure (
)
{
UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle;
CHAR8 LogString[UNIT_TEST_TESTFAILUREMSG_LENGTH];
CHAR8 LogString[UNIT_TEST_MAX_STRING_LENGTH];
VA_LIST Marker;

//
Expand Down
9 changes: 4 additions & 5 deletions UnitTestFrameworkPkg/Library/UnitTestLib/Log.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#include <Library/PrintLib.h>
#include <Library/PcdLib.h>

#define UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH (512)
#define UNIT_TEST_MAX_LOG_BUFFER SIZE_16KB
#define UNIT_TEST_MAX_LOG_BUFFER SIZE_16KB

struct _UNIT_TEST_LOG_PREFIX_STRING {
UNIT_TEST_STATUS LogLevel;
Expand Down Expand Up @@ -85,7 +84,7 @@ AddStringToUnitTestLog (
UnitTest->Log,
UNIT_TEST_MAX_LOG_BUFFER / sizeof (CHAR8),
String,
UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH
UNIT_TEST_MAX_STRING_LENGTH
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to add unit test log string. Status = %r\n", Status));
Expand Down Expand Up @@ -160,8 +159,8 @@ UnitTestLog (
)
{
UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle;
CHAR8 NewFormatString[UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH];
CHAR8 LogString[UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH];
CHAR8 NewFormatString[UNIT_TEST_MAX_STRING_LENGTH];
CHAR8 LogString[UNIT_TEST_MAX_STRING_LENGTH];
CONST CHAR8 *LogTypePrefix;
VA_LIST Marker;

Expand Down
6 changes: 3 additions & 3 deletions UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ UpdateTestFromSave (
Test->FailureType = MatchingTest->FailureType;
AsciiStrnCpyS (
&Test->FailureMessage[0],
UNIT_TEST_TESTFAILUREMSG_LENGTH,
UNIT_TEST_MAX_STRING_LENGTH,
&MatchingTest->FailureMessage[0],
UNIT_TEST_TESTFAILUREMSG_LENGTH
UNIT_TEST_MAX_STRING_LENGTH
);

//
Expand Down Expand Up @@ -748,7 +748,7 @@ SerializeState (
//
TestSaveData->Result = UnitTest->Result;
TestSaveData->FailureType = UnitTest->FailureType;
AsciiStrnCpyS (&TestSaveData->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH, &UnitTest->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH);
AsciiStrnCpyS (&TestSaveData->FailureMessage[0], UNIT_TEST_MAX_STRING_LENGTH, &UnitTest->FailureMessage[0], UNIT_TEST_MAX_STRING_LENGTH);

//
// If there is a log, save the log.
Expand Down
12 changes: 3 additions & 9 deletions UnitTestFrameworkPkg/PrivateInclude/UnitTestFrameworkTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
///
/// The maximum length of a string stored in the unit test framework
///
#define UNIT_TEST_MAX_STRING_LENGTH (120)
#define UNIT_TEST_MAX_STRING_LENGTH (512)

///
/// The size of a firngerprint used to save/resume execution of a unit test
Expand All @@ -24,12 +24,6 @@
///
#define UNIT_TEST_FINGERPRINT_SIZE (sizeof (UINT32))

///
/// The maximum length of a test failure message stored in the unit test
/// framework
///
#define UNIT_TEST_TESTFAILUREMSG_LENGTH (120)

///
/// FAILURE_TYPE used to record the type of assert that was triggered by a unit
/// test.
Expand All @@ -54,7 +48,7 @@ typedef struct {
CHAR8 *Name; // can't have spaces and should be short
CHAR8 *Log;
FAILURE_TYPE FailureType;
CHAR8 FailureMessage[UNIT_TEST_TESTFAILUREMSG_LENGTH];
CHAR8 FailureMessage[UNIT_TEST_MAX_STRING_LENGTH];
UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE];
UNIT_TEST_STATUS Result;
UNIT_TEST_FUNCTION RunTest;
Expand Down Expand Up @@ -117,7 +111,7 @@ typedef struct {
typedef struct {
UINT32 Size; // Size of the UNIT_TEST_SAVE_TEST including Log[]
UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE]; // Fingerprint of the test itself.
CHAR8 FailureMessage[UNIT_TEST_TESTFAILUREMSG_LENGTH];
CHAR8 FailureMessage[UNIT_TEST_MAX_STRING_LENGTH];
FAILURE_TYPE FailureType;
UNIT_TEST_STATUS Result;
CHAR8 Log[];
Expand Down

0 comments on commit 2ee050d

Please sign in to comment.