]> xenbits.xensource.com Git - ovmf.git/commitdiff
UefiCpuPkg/CpuPageTableLib: Modify RandomTest to check IsModified
authorDun Tan <dun.tan@intel.com>
Tue, 7 Mar 2023 07:25:27 +0000 (15:25 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 27 Mar 2023 08:21:58 +0000 (08:21 +0000)
Modify RandomTest to check if parameter IsModified of
PageTableMap() correctlly indicates whether input page table
is modified or not.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c

index e603dba269da5369cfd1858fb5adcc6ae93c8261..bffd95c898fb6c0a5b94a825ca7c27822178cfbf 100644 (file)
@@ -636,6 +636,8 @@ SingleMapEntryTest (
   VOID                *Buffer;\r
   IA32_MAP_ENTRY      *Map;\r
   UINTN               MapCount;\r
+  IA32_MAP_ENTRY      *Map2;\r
+  UINTN               MapCount2;\r
   UINTN               Index;\r
   UINTN               KeyPointCount;\r
   UINTN               NewKeyPointCount;\r
@@ -648,11 +650,13 @@ SingleMapEntryTest (
   IA32_MAP_ATTRIBUTE  *Attribute;\r
   UINT64              LastNotPresentRegionStart;\r
   BOOLEAN             IsNotPresent;\r
+  BOOLEAN             IsModified;\r
 \r
   MapsIndex                 = MapEntrys->Count;\r
   MapCount                  = 0;\r
   LastNotPresentRegionStart = 0;\r
   IsNotPresent              = FALSE;\r
+  IsModified                = FALSE;\r
 \r
   GenerateSingleRandomMapEntry (MaxAddress, MapEntrys);\r
   LastMapEntry = &MapEntrys->Maps[MapsIndex];\r
@@ -700,7 +704,7 @@ SingleMapEntryTest (
                           LastMapEntry->Length,\r
                           &LastMapEntry->Attribute,\r
                           &LastMapEntry->Mask,\r
-                          NULL\r
+                          &IsModified\r
                           );\r
 \r
   Attribute = &LastMapEntry->Attribute;\r
@@ -761,7 +765,7 @@ SingleMapEntryTest (
                LastMapEntry->Length,\r
                &LastMapEntry->Attribute,\r
                &LastMapEntry->Mask,\r
-               NULL\r
+               &IsModified\r
                );\r
   }\r
 \r
@@ -775,18 +779,31 @@ SingleMapEntryTest (
     return TestStatus;\r
   }\r
 \r
-  MapCount = 0;\r
-  Status   = PageTableParse (*PageTable, PagingMode, NULL, &MapCount);\r
-  if (MapCount != 0) {\r
+  MapCount2 = 0;\r
+  Status    = PageTableParse (*PageTable, PagingMode, NULL, &MapCount2);\r
+  if (MapCount2 != 0) {\r
     UT_ASSERT_EQUAL (Status, RETURN_BUFFER_TOO_SMALL);\r
 \r
     //\r
-    // Allocate memory for Maps\r
+    // Allocate memory for Map2\r
     // Note the memory is only used in this one Single MapEntry Test\r
     //\r
-    Map = AllocatePages (EFI_SIZE_TO_PAGES (MapCount * sizeof (IA32_MAP_ENTRY)));\r
-    ASSERT (Map != NULL);\r
-    Status = PageTableParse (*PageTable, PagingMode, Map, &MapCount);\r
+    Map2 = AllocatePages (EFI_SIZE_TO_PAGES (MapCount2 * sizeof (IA32_MAP_ENTRY)));\r
+    ASSERT (Map2 != NULL);\r
+    Status = PageTableParse (*PageTable, PagingMode, Map2, &MapCount2);\r
+  }\r
+\r
+  //\r
+  // Check if PageTable has been modified.\r
+  //\r
+  if (MapCount2 != MapCount) {\r
+    UT_ASSERT_EQUAL (IsModified, TRUE);\r
+  } else {\r
+    if (CompareMem (Map, Map2, MapCount2 * sizeof (IA32_MAP_ENTRY)) != 0) {\r
+      UT_ASSERT_EQUAL (IsModified, TRUE);\r
+    } else {\r
+      UT_ASSERT_EQUAL (IsModified, FALSE);\r
+    }\r
   }\r
 \r
   UT_ASSERT_EQUAL (Status, RETURN_SUCCESS);\r
@@ -796,17 +813,17 @@ SingleMapEntryTest (
   // Note the memory is only used in this one Single MapEntry Test\r
   //\r
   KeyPointCount = 0;\r
-  GetKeyPointList (MapEntrys, Map, MapCount, NULL, &KeyPointCount);\r
+  GetKeyPointList (MapEntrys, Map2, MapCount2, NULL, &KeyPointCount);\r
   KeyPointBuffer = AllocatePages (EFI_SIZE_TO_PAGES (KeyPointCount * sizeof (UINT64)));\r
   ASSERT (KeyPointBuffer != NULL);\r
   NewKeyPointCount = 0;\r
-  GetKeyPointList (MapEntrys, Map, MapCount, KeyPointBuffer, &NewKeyPointCount);\r
+  GetKeyPointList (MapEntrys, Map2, MapCount2, KeyPointBuffer, &NewKeyPointCount);\r
 \r
   //\r
   // Compare all key point's attribute\r
   //\r
   for (Index = 0; Index < NewKeyPointCount; Index++) {\r
-    if (!CompareEntrysforOnePoint (KeyPointBuffer[Index], MapEntrys, Map, MapCount, InitMap, InitMapCount)) {\r
+    if (!CompareEntrysforOnePoint (KeyPointBuffer[Index], MapEntrys, Map2, MapCount2, InitMap, InitMapCount)) {\r
       DEBUG ((DEBUG_INFO, "Error happens at below key point\n"));\r
       DEBUG ((DEBUG_INFO, "Index = %d KeyPointBuffer[Index] = 0x%lx\n", Index, KeyPointBuffer[Index]));\r
       Value = GetEntryFromPageTable (*PageTable, PagingMode, KeyPointBuffer[Index], &Level);\r
@@ -820,6 +837,10 @@ SingleMapEntryTest (
     FreePages (Map, EFI_SIZE_TO_PAGES (MapCount * sizeof (IA32_MAP_ENTRY)));\r
   }\r
 \r
+  if (MapCount2 != 0) {\r
+    FreePages (Map2, EFI_SIZE_TO_PAGES (MapCount2 * sizeof (IA32_MAP_ENTRY)));\r
+  }\r
+\r
   return UNIT_TEST_PASSED;\r
 }\r
 \r