summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg
diff options
context:
space:
mode:
authorYuanhaoXie <yuanhao.xie@intel.com>2023-09-11 18:42:55 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-10-09 08:22:02 +0000
commit01b0d19dbbc58034808e4f0cac8d8df56f4787f7 (patch)
tree30b7a306446c0c912a2932b56789bb145710a3dd /UefiCpuPkg
parentc4fdec0a83d69bd0399b1b4351fa9c3af3c6fd65 (diff)
downloadedk2-01b0d19dbbc58034808e4f0cac8d8df56f4787f7.tar.gz
edk2-01b0d19dbbc58034808e4f0cac8d8df56f4787f7.tar.bz2
edk2-01b0d19dbbc58034808e4f0cac8d8df56f4787f7.zip
UefiCpuPkg/MtrrUnitTest: Add Unit test of setting/getting memory
attributes Add Unit test of trrGetMemoryAttributesInMtrrSettings and MtrrSetMemoryAttributesInMtrrSettings. Signed-off-by: Ray Ni <ray.ni@intel.com> Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com> Cc: Eric Dong <eric.dong@intel.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
Diffstat (limited to 'UefiCpuPkg')
-rw-r--r--UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c b/UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c
index 339e95cc46..376fd96091 100644
--- a/UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c
+++ b/UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c
@@ -177,7 +177,8 @@ GenerateRandomMemoryTypeCombination (
}
/**
- Unit test of MtrrLib service MtrrSetMemoryAttribute()
+ Unit test of MtrrLib service MtrrGetMemoryAttributesInMtrrSettings() and
+ MtrrSetMemoryAttributesInMtrrSettings()
@param[in] Context Ignored
@@ -188,7 +189,7 @@ GenerateRandomMemoryTypeCombination (
**/
UNIT_TEST_STATUS
EFIAPI
-UnitTestMtrrSetMemoryAttributesInMtrrSettings (
+UnitTestMtrrSetAndGetMemoryAttributesInMtrrSettings (
IN UNIT_TEST_CONTEXT Context
)
{
@@ -214,6 +215,9 @@ UnitTestMtrrSetMemoryAttributesInMtrrSettings (
UINT32 ActualVariableMtrrUsage;
UINTN ActualMemoryRangesCount;
+ MTRR_MEMORY_RANGE ReturnedMemoryRanges[MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];
+ UINTN ReturnedMemoryRangesCount;
+
MTRR_SETTINGS *Mtrrs[2];
SystemParameter = (MTRR_LIB_SYSTEM_PARAMETER *)Context;
@@ -298,6 +302,17 @@ UnitTestMtrrSetMemoryAttributesInMtrrSettings (
VerifyMemoryRanges (ExpectedMemoryRanges, ExpectedMemoryRangesCount, ActualMemoryRanges, ActualMemoryRangesCount);
UT_ASSERT_TRUE (ExpectedVariableMtrrUsage >= ActualVariableMtrrUsage);
+ ReturnedMemoryRangesCount = ARRAY_SIZE (ReturnedMemoryRanges);
+ Status = MtrrGetMemoryAttributesInMtrrSettings (
+ Mtrrs[MtrrIndex],
+ ReturnedMemoryRanges,
+ &ReturnedMemoryRangesCount
+ );
+ UT_ASSERT_STATUS_EQUAL (Status, RETURN_SUCCESS);
+ UT_LOG_INFO ("--- Returned Memory Ranges [%d] ---\n", ReturnedMemoryRangesCount);
+ DumpMemoryRanges (ReturnedMemoryRanges, ReturnedMemoryRangesCount);
+ VerifyMemoryRanges (ExpectedMemoryRanges, ExpectedMemoryRangesCount, ReturnedMemoryRanges, ReturnedMemoryRangesCount);
+
ZeroMem (&LocalMtrrs, sizeof (LocalMtrrs));
}
@@ -1019,7 +1034,8 @@ UnitTestMtrrGetDefaultMemoryType (
}
/**
- Unit test of MtrrLib service MtrrSetMemoryAttributeInMtrrSettings().
+ Unit test of MtrrLib service MtrrSetMemoryAttributeInMtrrSettings() and
+ MtrrGetMemoryAttributesInMtrrSettings().
@param[in] Context Ignored
@@ -1030,7 +1046,7 @@ UnitTestMtrrGetDefaultMemoryType (
**/
UNIT_TEST_STATUS
EFIAPI
-UnitTestMtrrSetMemoryAttributeInMtrrSettings (
+UnitTestMtrrSetMemoryAttributeAndGetMemoryAttributesInMtrrSettings (
IN UNIT_TEST_CONTEXT Context
)
{
@@ -1055,6 +1071,9 @@ UnitTestMtrrSetMemoryAttributeInMtrrSettings (
UINT32 ActualVariableMtrrUsage;
UINTN ActualMemoryRangesCount;
+ MTRR_MEMORY_RANGE ReturnedMemoryRanges[MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];
+ UINTN ReturnedMemoryRangesCount;
+
MTRR_SETTINGS *Mtrrs[2];
SystemParameter = (MTRR_LIB_SYSTEM_PARAMETER *)Context;
@@ -1131,6 +1150,17 @@ UnitTestMtrrSetMemoryAttributeInMtrrSettings (
VerifyMemoryRanges (ExpectedMemoryRanges, ExpectedMemoryRangesCount, ActualMemoryRanges, ActualMemoryRangesCount);
UT_ASSERT_TRUE (ExpectedVariableMtrrUsage >= ActualVariableMtrrUsage);
+ ReturnedMemoryRangesCount = ARRAY_SIZE (ReturnedMemoryRanges);
+ Status = MtrrGetMemoryAttributesInMtrrSettings (
+ &LocalMtrrs,
+ ReturnedMemoryRanges,
+ &ReturnedMemoryRangesCount
+ );
+ UT_ASSERT_STATUS_EQUAL (Status, RETURN_SUCCESS);
+ UT_LOG_INFO ("--- Returned Memory Ranges [%d] ---\n", ReturnedMemoryRangesCount);
+ DumpMemoryRanges (ReturnedMemoryRanges, ReturnedMemoryRangesCount);
+ VerifyMemoryRanges (ExpectedMemoryRanges, ExpectedMemoryRangesCount, ReturnedMemoryRanges, ReturnedMemoryRangesCount);
+
ZeroMem (&LocalMtrrs, sizeof (LocalMtrrs));
}
@@ -1239,8 +1269,8 @@ UnitTestingEntry (
for (SystemIndex = 0; SystemIndex < ARRAY_SIZE (mSystemParameters); SystemIndex++) {
for (Index = 0; Index < Iteration; Index++) {
AddTestCase (MtrrApiTests, "Test InvalidMemoryLayouts", "InvalidMemoryLayouts", UnitTestInvalidMemoryLayouts, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
- AddTestCase (MtrrApiTests, "Test MtrrSetMemoryAttributeInMtrrSettings", "MtrrSetMemoryAttributeInMtrrSettings", UnitTestMtrrSetMemoryAttributeInMtrrSettings, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
- AddTestCase (MtrrApiTests, "Test MtrrSetMemoryAttributesInMtrrSettings", "MtrrSetMemoryAttributesInMtrrSettings", UnitTestMtrrSetMemoryAttributesInMtrrSettings, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
+ AddTestCase (MtrrApiTests, "Test MtrrSetMemoryAttributeInMtrrSettings and MtrrGetMemoryAttributesInMtrrSettings", "MtrrSetMemoryAttributeInMtrrSettings and MtrrGetMemoryAttributesInMtrrSettings", UnitTestMtrrSetMemoryAttributeAndGetMemoryAttributesInMtrrSettings, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
+ AddTestCase (MtrrApiTests, "Test MtrrSetMemoryAttributesInMtrrSettings and MtrrGetMemoryAttributesInMtrrSettings", "MtrrSetMemoryAttributesInMtrrSettings and MtrrGetMemoryAttributesInMtrrSetting", UnitTestMtrrSetAndGetMemoryAttributesInMtrrSettings, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
}
}