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>
---
UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c b/UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c
index dc348ef0a3..b252eacf34 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;
@@ -292,12 +296,22 @@ UnitTestMtrrSetMemoryAttributesInMtrrSettings (
&ActualMemoryRangesCount,
&ActualVariableMtrrUsage
);
-
UT_LOG_INFO ("--- Actual Memory Ranges [%d] ---\n", ActualMemoryRangesCount);
DumpMemoryRanges (ActualMemoryRanges, ActualMemoryRangesCount);
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));
}
@@ -1041,6 +1055,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;
@@ -1117,6 +1134,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));
}
@@ -1226,7 +1254,7 @@ UnitTestingEntry (
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 MtrrSetAndGetMemoryAttributesInMtrrSettings", "MtrrSetAndGetMemoryAttributesInMtrrSettings", UnitTestMtrrSetAndGetMemoryAttributesInMtrrSettings, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
}
}
--
2.36.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108571): https://edk2.groups.io/g/devel/message/108571
Mute This Topic: https://groups.io/mt/101331034/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-