summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.h
diff options
context:
space:
mode:
authorZhiguang Liu <zhiguang.liu@intel.com>2022-06-27 16:58:48 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2022-08-16 02:44:08 +0000
commit2812668bfc121ee792cf3302195176ef4a2ad0bc (patch)
tree93704c1fab34322f4337bbc6c32fd0c9b5003ca1 /UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.h
parent809b5a3d2a3b7732459dd63c9382fe6ec42d1856 (diff)
downloadedk2-2812668bfc121ee792cf3302195176ef4a2ad0bc.tar.gz
edk2-2812668bfc121ee792cf3302195176ef4a2ad0bc.tar.bz2
edk2-2812668bfc121ee792cf3302195176ef4a2ad0bc.zip
UefiCpuPkg/CpuPageTableLib/UnitTest: Add host based unit test
Add host based unit tests for the CpuPageTableLib services. Unit test focuses on PageTableMap function, containing two kinds of test cases: manual test case and random test case. Manual test case creates some corner case to test function PageTableMap. Random test case generates multiple random memory entries (with random attribute) as the input of function PageTableMap to get the output pagetable. Output pagetable will be validated and be parsed to get output memory entries, and then the input and output memory entries will be compared to verify the functionality. The unit test is not perfect yet. There are options for random test, and some of them control the test coverage, and some option are not ready. Will enhance in the future. Cc: Eric Dong <eric.dong@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
Diffstat (limited to 'UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.h')
-rw-r--r--UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.h b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.h
new file mode 100644
index 0000000000..cdc81e0af3
--- /dev/null
+++ b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.h
@@ -0,0 +1,57 @@
+/** @file
+ Internal header for Random test.
+
+ Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RANDOM_TEST_H_
+#define RANDOM_TEST_H_
+
+#include "CpuPageTableLibUnitTest.h"
+
+typedef struct _ALLOCATE_PAGE_RECORDS ALLOCATE_PAGE_RECORDS;
+
+typedef
+VOID *
+(EFIAPI *ALLOCATE_PAGES)(
+ IN ALLOCATE_PAGE_RECORDS *PagesRecord,
+ IN UINTN Pages
+ );
+
+typedef struct {
+ VOID *Buffer;
+ UINTN Pages;
+} ALLOCATE_PAGE_RECORD;
+
+struct _ALLOCATE_PAGE_RECORDS {
+ UINTN Count;
+ UINTN MaxCount;
+ ALLOCATE_PAGES AllocatePagesForPageTable;
+ ALLOCATE_PAGE_RECORD Records[0];
+};
+
+typedef struct {
+ UINT64 LinearAddress;
+ UINT64 Length;
+ IA32_MAP_ATTRIBUTE Attribute;
+ IA32_MAP_ATTRIBUTE Mask;
+} MAP_ENTRY;
+
+typedef struct {
+ UINTN Count;
+ UINTN InitCount;
+ UINTN MaxCount;
+ MAP_ENTRY Maps[10];
+} MAP_ENTRYS;
+
+UINT64
+GetEntryFromPageTable (
+ IN UINTN PageTable,
+ IN PAGING_MODE PagingMode,
+ IN UINT64 Address,
+ OUT UINTN *Level
+ );
+
+#endif