Skip to content

Commit

Permalink
UefiCpuPkg/MtrrLibUnitTest: Change to use static array for CI test
Browse files Browse the repository at this point in the history
The unit test app supports running in 3 mode:
1. MtrrLibUnitTest generate-random-numbers
     <path to MtrrLib/UnitTest/RandomNumber.c> <random-number count>
   It generates random numbers and writes to RandomNumber.c.

2. MtrrLibUnitTest [<iterations>]
   It tests MtrrLib APIs using configurations generated from static
   numbers generated by mode #1.
   This is the default execution mode running in CI environment.

3. MtrrLibUnitTest <iterations> random
   It tests MtrrLib APIs using configurations generated from random
   numbers.
   This is what developers can use to test MtrrLib for regressions.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ming Shao <ming.shao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
  • Loading branch information
niruiyu committed Aug 12, 2020
1 parent 4448a1a commit a1ca847
Show file tree
Hide file tree
Showing 5 changed files with 5,126 additions and 12 deletions.
44 changes: 34 additions & 10 deletions UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,8 +1055,6 @@ UnitTestingEntry (
GetFirmwareVariableMtrrCountContext.SystemParameter = &mDefaultSystemParameter;
Framework = NULL;

DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));

//
// Setup the test framework for running the tests.
//
Expand Down Expand Up @@ -1100,7 +1098,6 @@ UnitTestingEntry (
//
// Execute the tests.
//
srand ((unsigned int) time (NULL));
Status = RunAllTestSuites (Framework);

EXIT:
Expand All @@ -1125,15 +1122,42 @@ main (
CHAR8 *Argv[]
)
{
UINTN Iteration;
UINTN Count;

DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
srand ((unsigned int) time (NULL));

//
// MtrrLibUnitTest generate-random-numbers <path to MtrrLib/UnitTest/RandomNumber.c> <random-number count>
//
if ((Argc == 4) && (AsciiStriCmp ("generate-random-numbers", Argv[1]) == 0)) {
Count = atoi (Argv[3]);
DEBUG ((DEBUG_INFO, "Generate %d random numbers to %a.\n", Count, Argv[2]));
GenerateRandomNumbers (Argv[2], Count);
return 0;
}

//
// First parameter specifies the test iterations.
// Default is 10.
// MtrrLibUnitTest [<iterations>]
// <iterations> [fixed|random]
// Default <iterations> is 10.
// Default uses fixed inputs.
//
Iteration = 10;
if (Argc == 2) {
Iteration = atoi (Argv[1]);
Count = 10;
mRandomInput = FALSE;
if ((Argc == 2) || (Argc == 3)) {
Count = atoi (Argv[1]);
if (Argc == 3) {
if (AsciiStriCmp ("fixed", Argv[2]) == 0) {
mRandomInput = FALSE;
} else if (AsciiStriCmp ("random", Argv[2]) == 0) {
mRandomInput = TRUE;
}
}
}
return UnitTestingEntry (Iteration);

DEBUG ((DEBUG_INFO, "Iterations = %d\n", Count));
DEBUG ((DEBUG_INFO, "Input = %a\n", mRandomInput ? "random" : "fixed"));

return UnitTestingEntry (Count);
}
13 changes: 13 additions & 0 deletions UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct {
} MTRR_LIB_SYSTEM_PARAMETER;

extern UINT32 mFixedMtrrsIndex[];
extern BOOLEAN mRandomInput;

/**
Initialize the MTRR registers.
Expand Down Expand Up @@ -179,4 +180,16 @@ Random32 (
UINT32 Start,
UINT32 Limit
);

/**
Generate Count random numbers in FilePath.
@param FilePath The file path to put the generated random numbers.
@param Count Count of random numbers.
**/
VOID
GenerateRandomNumbers (
CHAR8 *FilePath,
UINTN Count
);
#endif
4 changes: 4 additions & 0 deletions UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTestHost.inf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
MtrrLibUnitTest.c
MtrrLibUnitTest.h
Support.c
RandomNumber.c

[Packages]
MdePkg/MdePkg.dec
Expand All @@ -37,3 +38,6 @@

[Pcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuNumberOfReservedVariableMtrrs ## SOMETIMES_CONSUMES

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = -D _CRT_SECURE_NO_WARNINGS

0 comments on commit a1ca847

Please sign in to comment.