UefiCpuPkg/MtrrLibUnitTest: Change to use static array for CI test

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>
This commit is contained in:
Ray Ni 2020-08-12 19:21:22 +08:00 committed by mergify[bot]
parent e17f459af2
commit 65904cdbb3
5 changed files with 5126 additions and 12 deletions

View File

@ -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.
//
@ -1100,7 +1098,6 @@ UnitTestingEntry (
//
// Execute the tests.
//
srand ((unsigned int) time (NULL));
Status = RunAllTestSuites (Framework);
EXIT:
@ -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));
//
// First parameter specifies the test iterations.
// Default is 10.
// MtrrLibUnitTest generate-random-numbers <path to MtrrLib/UnitTest/RandomNumber.c> <random-number count>
//
Iteration = 10;
if (Argc == 2) {
Iteration = atoi (Argv[1]);
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;
}
return UnitTestingEntry (Iteration);
//
// MtrrLibUnitTest [<iterations>]
// <iterations> [fixed|random]
// Default <iterations> is 10.
// Default uses fixed inputs.
//
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;
}
}
}
DEBUG ((DEBUG_INFO, "Iterations = %d\n", Count));
DEBUG ((DEBUG_INFO, "Input = %a\n", mRandomInput ? "random" : "fixed"));
return UnitTestingEntry (Count);
}

View File

@ -43,6 +43,7 @@ typedef struct {
} MTRR_LIB_SYSTEM_PARAMETER;
extern UINT32 mFixedMtrrsIndex[];
extern BOOLEAN mRandomInput;
/**
Initialize the MTRR registers.
@ -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

View File

@ -22,6 +22,7 @@
MtrrLibUnitTest.c
MtrrLibUnitTest.h
Support.c
RandomNumber.c
[Packages]
MdePkg/MdePkg.dec
@ -37,3 +38,6 @@
[Pcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuNumberOfReservedVariableMtrrs ## SOMETIMES_CONSUMES
[BuildOptions]
MSFT:*_*_*_CC_FLAGS = -D _CRT_SECURE_NO_WARNINGS

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,70 @@ MSR_IA32_MTRRCAP_REGISTER mMtrrCapMsr;
CPUID_VERSION_INFO_EDX mCpuidVersionInfoEdx;
CPUID_VIR_PHY_ADDRESS_SIZE_EAX mCpuidVirPhyAddressSizeEax;
BOOLEAN mRandomInput;
UINTN mNumberIndex = 0;
extern UINTN mNumbers[];
extern UINTN mNumberCount;
/**
Return a random number between 0 and RAND_MAX.
If mRandomInput is TRUE, the routine directly calls rand().
Otherwise, the routine returns the pre-generated numbers.
@return a number between 0 and RAND_MAX.
**/
UINTN
Rand (
VOID
)
{
if (mRandomInput) {
return rand ();
} else {
DEBUG ((DEBUG_INFO, "random: %d\n", mNumberIndex));
return mNumbers[mNumberIndex++ % (mNumberCount - 1)];
}
}
CHAR8 mContentTemplate[] = {
"/** @file\n"
" Pre-generated random number used by MtrrLib test.\n"
"\n"
" Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>\n"
" SPDX-License-Identifier: BSD-2-Clause-Patent\n"
"**/\n"
"UINTN mNumberCount = %d;\n"
"UINTN mNumbers[] = {"
};
/**
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
)
{
FILE *File;
UINTN Index;
File = fopen (FilePath, "w");
fprintf (File, mContentTemplate, Count);
for (Index = 0; Index < Count; Index++) {
if (Index % 10 == 0) {
fprintf (File, "\n ");
}
fprintf (File, " %d,", rand ());
}
fprintf (File, "\n};\n");
fclose (File);
}
/**
Retrieves CPUID information.
@ -328,7 +392,7 @@ Random32 (
UINT32 Limit
)
{
return (UINT32) (((double) rand () / RAND_MAX) * (Limit - Start)) + Start;
return (UINT32) (((double) Rand () / RAND_MAX) * (Limit - Start)) + Start;
}
/**
@ -344,7 +408,7 @@ Random64 (
UINT64 Limit
)
{
return (UINT64) (((double) rand () / RAND_MAX) * (Limit - Start)) + Start;
return (UINT64) (((double) Rand () / RAND_MAX) * (Limit - Start)) + Start;
}
/**