]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTest.h
UefiCpuPkg/CpuPageTableLib/UnitTest: Add host based unit test
[mirror_edk2.git] / UefiCpuPkg / Library / CpuPageTableLib / UnitTest / CpuPageTableLibUnitTest.h
1 /** @file
2
3 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
5
6 **/
7
8 #ifndef CPU_PAGE_TABLE_SUPPORT_H_
9 #define CPU_PAGE_TABLE_SUPPORT_H_
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <stdarg.h>
15 #include <stddef.h>
16 #include <setjmp.h>
17 #include <cmocka.h>
18 #include <time.h>
19
20 #include <Uefi.h>
21 #include <Library/BaseLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/UnitTestLib.h>
25 #include <Library/CpuPageTableLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/UnitTestHostBaseLib.h>
28 #include <Library/BaseCryptLib.h>
29 #include "../CpuPageTable.h"
30
31 #define UNIT_TEST_APP_NAME "Cpu Page Table Lib Unit Tests"
32 #define UNIT_TEST_APP_VERSION "1.0"
33
34 //
35 // Random Options
36 //
37
38 //
39 // Only test one-one mapping case
40 //
41 #define ONLY_ONE_ONE_MAPPING 0x00000001
42
43 //
44 // Change page table without using function PageTableMap, and use the modified page table as input
45 //
46 #define MANUAL_CHANGE_PAGE_TABLE 0x00000002
47
48 //
49 // Use pre-generated random number array to generate random number
50 //
51 #define USE_RANDOM_ARRAY 0x00000004
52
53 typedef struct {
54 PAGING_MODE PagingMode;
55 UINTN TestCount;
56 UINTN TestRangeCount;
57 UINTN RandomOption;
58 } CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT;
59
60 /**
61 Random Test
62
63 @param[in] Context [Optional] An optional parameter that enables:
64 1) test-case reuse with varied parameters and
65 2) test-case re-entry for Target tests that need a
66 reboot. This parameter is a VOID* and it is the
67 responsibility of the test author to ensure that the
68 contents are well understood by all test cases that may
69 consume it.
70
71 @retval UNIT_TEST_PASSED The Unit test has completed and the test
72 case was successful.
73 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
74 **/
75 UNIT_TEST_STATUS
76 EFIAPI
77 TestCaseforRandomTest (
78 IN UNIT_TEST_CONTEXT Context
79 );
80
81 /**
82 Init global data
83
84 @param[in] MemorySpace Memory space
85 **/
86 VOID
87 InitGlobalData (
88 UINTN MemorySpace
89 );
90
91 /**
92 Check if the Page table is valid
93
94 @param[in] PageTable The pointer to the page table.
95 @param[in] PagingMode The paging mode.
96
97 @retval UNIT_TEST_PASSED It is a valid Page Table
98 **/
99 UNIT_TEST_STATUS
100 IsPageTableValid (
101 IN UINTN PageTable,
102 IN PAGING_MODE PagingMode
103 );
104
105 /**
106 Get max physical adrress supported by specific page mode
107
108 @param[in] Mode The paging mode.
109
110 @retval max address.
111 **/
112 UINT64
113 GetMaxAddress (
114 IN PAGING_MODE Mode
115 );
116
117 #endif