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:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user