40 PAGING_MODE PagingMode;
42 UINTN PageTableBufferSize;
46 MapAttribute.Uint64 = 0;
48 PagingMode = Paging5Level1GB;
49 PageTableBufferSize = 0;
60 PageTableBufferSize = 10;
66 PageTableBufferSize = 0;
67 PagingMode = Paging32bit;
73 PagingMode = Paging5Level1GB;
76 return UNIT_TEST_PASSED;
101 PAGING_MODE PagingMode;
103 UINTN PageTableBufferSize;
106 RETURN_STATUS Status;
109 MapAttribute.Uint64 = 0;
111 PagingMode = Paging4Level1GB;
112 PageTableBufferSize = 0;
115 MapAttribute.Bits.Present = 1;
116 MapAttribute.Bits.Nx = 1;
117 MapMask.Bits.Present = 1;
118 MapMask.Uint64 = MAX_UINT64;
123 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, 0, (UINT64)SIZE_2MB * 5, &MapAttribute, &MapMask,
NULL);
126 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, 0, (UINT64)SIZE_2MB * 5, &MapAttribute, &MapMask,
NULL);
129 if (TestStatus != UNIT_TEST_PASSED) {
138 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, 0, (UINT64)SIZE_4KB, &MapAttribute, &MapMask,
NULL);
142 if (TestStatus != UNIT_TEST_PASSED) {
151 PageTableBufferSize = 0;
152 Status =
PageTableMap (&PageTable, PagingMode,
NULL, &PageTableBufferSize, 0, (UINT64)SIZE_4KB, &MapAttribute, &MapMask,
NULL);
156 if (TestStatus != UNIT_TEST_PASSED) {
165 MapAttribute.Bits.Accessed = 1;
166 MapMask.Bits.Accessed = 1;
167 PageTableBufferSize = 0;
168 Status =
PageTableMap (&PageTable, PagingMode,
NULL, &PageTableBufferSize, (UINT64)SIZE_2MB, (UINT64)SIZE_2MB, &MapAttribute, &MapMask,
NULL);
172 if (TestStatus != UNIT_TEST_PASSED) {
176 return UNIT_TEST_PASSED;
201 PAGING_MODE PagingMode;
203 UINTN PageTableBufferSize;
206 RETURN_STATUS Status;
212 PagingMode = Paging4Level1GB;
213 PageTableBufferSize = 0;
216 MapAttribute.Uint64 = (UINT64)SIZE_4KB * 2;
217 MapMask.Uint64 = (UINT64)SIZE_4KB * 2;
218 MapAttribute.Bits.Present = 1;
219 MapMask.Bits.Present = 1;
220 MapMask.Uint64 = MAX_UINT64;
221 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, (UINT64)0, (UINT64)SIZE_1GB, &MapAttribute, &MapMask,
NULL);
224 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, (UINT64)0, (UINT64)SIZE_1GB, &MapAttribute, &MapMask,
NULL);
231 if (TestStatus != UNIT_TEST_PASSED) {
235 return UNIT_TEST_PASSED;
260 PAGING_MODE PagingMode;
262 UINTN PageTableBufferSize;
266 RETURN_STATUS Status;
271 UINTN BackupPageTableBufferSize;
273 PagingMode = Paging4Level;
274 PageTableBufferSize = 0;
277 MapAttribute.Uint64 = 0;
278 MapMask.Uint64 = MAX_UINT64;
279 MapAttribute.Bits.Present = 1;
280 MapAttribute.Bits.ReadWrite = 1;
285 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, 0, SIZE_2GB, &MapAttribute, &MapMask,
NULL);
287 BackupPageTableBufferSize = PageTableBufferSize;
289 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, 0, SIZE_2GB, &MapAttribute, &MapMask,
NULL);
303 ExpectedMapAttribute.Uint64 = MapAttribute.Uint64;
304 UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64);
310 PagingEntry->Uint64 = PagingEntry->Uint64 & (~(UINT64)0x2);
321 ExpectedMapAttribute.Uint64 = MapAttribute.Uint64;
322 ExpectedMapAttribute.Bits.ReadWrite = 0;
323 UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64);
334 MapAttribute.Bits.ReadWrite = 0;
335 Status =
PageTableMap (&PageTable, PagingMode,
NULL, &PageTableBufferSize, 0, SIZE_2MB, &MapAttribute, &MapMask,
NULL);
350 ExpectedMapAttribute.Uint64 = MapAttribute.Uint64;
351 UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64);
362 MapAttribute.Bits.ReadWrite = 1;
363 PageTableBufferSize = 0;
364 Status =
PageTableMap (&PageTable, PagingMode,
NULL, &PageTableBufferSize, 0, SIZE_2MB, &MapAttribute, &MapMask,
NULL);
380 ExpectedMapAttribute.Uint64 = MapAttribute.Uint64;
381 UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64);
385 ExpectedMapAttribute.Uint64 = SIZE_2MB;
386 ExpectedMapAttribute.Bits.ReadWrite = 0;
387 ExpectedMapAttribute.Bits.Present = 1;
388 UT_ASSERT_EQUAL (Map[1].Attribute.Uint64, ExpectedMapAttribute.Uint64);
390 return UNIT_TEST_PASSED;
415 PAGING_MODE PagingMode;
417 UINTN PageTableBufferSize;
421 RETURN_STATUS Status;
426 PagingMode = Paging4Level;
427 PageTableBufferSize = 0;
430 MapMask.Uint64 = MAX_UINT64;
431 MapAttribute.Uint64 = (SIZE_2MB - SIZE_4KB);
432 MapAttribute.Bits.Present = 1;
433 MapAttribute.Bits.ReadWrite = 1;
437 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, SIZE_2MB - SIZE_4KB, SIZE_4KB + SIZE_2MB, &MapAttribute, &MapMask,
NULL);
440 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, SIZE_2MB - SIZE_4KB, SIZE_4KB + SIZE_2MB, &MapAttribute, &MapMask,
NULL);
454 ExpectedMapAttribute.Uint64 = MapAttribute.Uint64;
455 UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64);
466 PagingEntry->Uint64 = PagingEntry->Uint64 & (~(UINT64)0x2);
477 ExpectedMapAttribute.Uint64 = MapAttribute.Uint64;
478 ExpectedMapAttribute.Bits.ReadWrite = 0;
479 UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64);
483 ExpectedMapAttribute.Uint64 = MapAttribute.Uint64 + SIZE_4KB;
484 ExpectedMapAttribute.Bits.ReadWrite = 1;
485 UT_ASSERT_EQUAL (Map[1].Attribute.Uint64, ExpectedMapAttribute.Uint64);
491 MapAttribute.Uint64 = SIZE_2MB - SIZE_4KB;
492 MapAttribute.Bits.Present = 1;
493 MapAttribute.Bits.ReadWrite = 1;
494 PageTableBufferSize = 0;
495 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, SIZE_2MB - SIZE_4KB, SIZE_4KB * 2, &MapAttribute, &MapMask,
NULL);
497 return UNIT_TEST_PASSED;
522 PAGING_MODE PagingMode;
524 UINTN PageTableBufferSize;
527 RETURN_STATUS Status;
530 PagingMode = Paging4Level1GB;
531 PageTableBufferSize = 0;
534 MapAttribute.Uint64 = 0;
535 MapMask.Uint64 = MAX_UINT64;
536 MapAttribute.Bits.Present = 1;
537 MapMask.Bits.Present = 1;
542 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, (UINT64)0, (UINT64)SIZE_2MB * 2, &MapAttribute, &MapMask,
NULL);
545 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, (UINT64)0, (UINT64)SIZE_2MB * 2, &MapAttribute, &MapMask,
NULL);
548 if (TestStatus != UNIT_TEST_PASSED) {
556 PageTableBufferSize = 0;
557 Status =
PageTableMap (&PageTable, PagingMode,
NULL, &PageTableBufferSize, (UINT64)0, (UINT64)SIZE_1GB, &MapAttribute, &MapMask,
NULL);
560 if (TestStatus != UNIT_TEST_PASSED) {
564 MapAttribute.Bits.Accessed = 1;
565 PageTableBufferSize = 0;
566 Status =
PageTableMap (&PageTable, PagingMode,
NULL, &PageTableBufferSize, (UINT64)0, (UINT64)SIZE_2MB, &MapAttribute, &MapMask,
NULL);
572 return UNIT_TEST_PASSED;
597 PAGING_MODE PagingMode;
599 UINTN PageTableBufferSize;
603 RETURN_STATUS Status;
609 PagingMode = Paging4Level1GB;
610 PageTableBufferSize = 0;
613 MapAttribute.Uint64 = 0;
614 MapMask.Uint64 = MAX_UINT64;
615 MapAttribute.Bits.Present = 1;
616 MapAttribute.Bits.Nx = 0;
621 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, (UINT64)0, (UINT64)SIZE_1GB * 2, &MapAttribute, &MapMask,
NULL);
624 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, (UINT64)0, (UINT64)SIZE_1GB * 2, &MapAttribute, &MapMask,
NULL);
627 if (TestStatus != UNIT_TEST_PASSED) {
635 if (TestStatus != UNIT_TEST_PASSED) {
645 ExpectedMapAttribute.Uint64 = MapAttribute.Uint64;
646 UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64);
652 PagingEntry->Uint64 = PagingEntry->Uint64 | BIT63;
662 ExpectedMapAttribute.Bits.Nx = 1;
663 UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64);
668 Status =
PageTableMap (&PageTable, PagingMode,
NULL, &PageTableBufferSize, (UINT64)0, (UINT64)SIZE_1GB, &MapAttribute, &MapMask,
NULL);
671 if (TestStatus != UNIT_TEST_PASSED) {
688 ExpectedMapAttribute.Uint64 = MapAttribute.Uint64;
689 UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64);
692 ExpectedMapAttribute.Uint64 = SIZE_1GB;
693 ExpectedMapAttribute.Bits.Present = 1;
694 ExpectedMapAttribute.Bits.Nx = 1;
695 UT_ASSERT_EQUAL (Map[1].Attribute.Uint64, ExpectedMapAttribute.Uint64);
696 return UNIT_TEST_PASSED;
722 PAGING_MODE PagingMode;
724 UINTN PageTableBufferSize;
728 RETURN_STATUS Status;
732 PagingMode = Paging4Level;
733 PageTableBufferSize = 0;
736 MapAttribute.Uint64 = 0;
737 MapAttribute.Bits.Present = 1;
739 MapMask.Bits.Present = 1;
743 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, 0, SIZE_2GB, &MapAttribute, &MapMask,
NULL);
745 MapMask.Uint64 = MAX_UINT64;
746 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, 0, SIZE_2GB, &MapAttribute, &MapMask,
NULL);
749 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, 0, SIZE_2GB, &MapAttribute, &MapMask,
NULL);
755 PageTableBufferSize = 0;
756 MapAttribute.Uint64 = 0;
758 MapMask.Bits.Present = 1;
759 MapMask.Bits.ReadWrite = 1;
760 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, SIZE_2GB - SIZE_8KB, SIZE_8KB, &MapAttribute, &MapMask,
NULL);
762 MapMask.Bits.ReadWrite = 0;
763 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, SIZE_2GB - SIZE_8KB, SIZE_8KB, &MapAttribute, &MapMask,
NULL);
766 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, SIZE_2GB - SIZE_8KB, SIZE_8KB, &MapAttribute, &MapMask,
NULL);
772 PageTableBufferSize = 0;
773 MapAttribute.Uint64 = 0;
775 MapMask.Bits.Present = 1;
776 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, SIZE_2GB - SIZE_8KB, SIZE_8KB, &MapAttribute, &MapMask,
NULL);
778 MapAttribute.Bits.ReadWrite = 1;
779 MapMask.Bits.ReadWrite = 1;
780 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, SIZE_2GB - SIZE_8KB, SIZE_8KB, &MapAttribute, &MapMask,
NULL);
786 PageTableBufferSize = 0;
787 MapAttribute.Uint64 = SIZE_2GB - SIZE_8KB;
788 MapAttribute.Bits.ReadWrite = 1;
789 MapAttribute.Bits.Present = 1;
791 MapMask.Bits.ReadWrite = 1;
792 MapMask.Bits.Present = 1;
793 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, SIZE_2GB - SIZE_8KB, SIZE_8KB, &MapAttribute, &MapMask,
NULL);
795 MapMask.Uint64 = MAX_UINT64;
796 Status =
PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBufferSize, SIZE_2GB - SIZE_8KB, SIZE_8KB, &MapAttribute, &MapMask,
NULL);
812 ExpectedMapAttribute.Uint64 = 0;
813 ExpectedMapAttribute.Bits.Present = 1;
814 UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64);
817 ExpectedMapAttribute.Uint64 = SIZE_2GB - SIZE_8KB;
818 ExpectedMapAttribute.Bits.Present = 1;
819 ExpectedMapAttribute.Bits.ReadWrite = 1;
820 UT_ASSERT_EQUAL (Map[1].Attribute.Uint64, ExpectedMapAttribute.Uint64);
821 return UNIT_TEST_PASSED;
839 UNIT_TEST_FRAMEWORK_HANDLE Framework;
840 UNIT_TEST_SUITE_HANDLE ManualTestCase;
846 DEBUG ((DEBUG_INFO,
"%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
851 Status =
InitUnitTestFramework (&Framework, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);
852 if (EFI_ERROR (Status)) {
853 DEBUG ((DEBUG_ERROR,
"Failed in InitUnitTestFramework. Status = %r\n", Status));
861 if (EFI_ERROR (Status)) {
862 DEBUG ((DEBUG_ERROR,
"Failed in CreateUnitTestSuite for Manual Test Cases\n"));
863 Status = EFI_OUT_OF_RESOURCES;
RETURN_STATUS EFIAPI PageTableMap(IN OUT UINTN *PageTable OPTIONAL, IN PAGING_MODE PagingMode, IN VOID *Buffer, IN OUT UINTN *BufferSize, IN UINT64 LinearAddress, IN UINT64 Length, IN IA32_MAP_ATTRIBUTE *Attribute, IN IA32_MAP_ATTRIBUTE *Mask, OUT BOOLEAN *IsModified OPTIONAL)
RETURN_STATUS EFIAPI PageTableParse(IN UINTN PageTable, IN PAGING_MODE PagingMode, IN IA32_MAP_ENTRY *Map, IN OUT UINTN *MapCount)
UNIT_TEST_STATUS IsPageTableValid(IN UINTN PageTable, IN PAGING_MODE PagingMode)
VOID InitGlobalData(UINTN MemorySpace)
EFI_STATUS EFIAPI UefiTestMain(VOID)
UNIT_TEST_STATUS EFIAPI TestCaseManualChangeReadWrite(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestCase1Gmapto4K(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestCaseForParameter(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestCaseManualSizeNotMatch(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestCaseToCheckMapMaskAndAttr(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestCaseManualChangeNx(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestCaseManualNotMergeEntry(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestCaseWhichNoNeedExtraSize(IN UNIT_TEST_CONTEXT Context)
int main()
=== TEST ENGINE ================================================================================
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define RETURN_BUFFER_TOO_SMALL
#define RETURN_UNSUPPORTED
#define RETURN_INVALID_PARAMETER
#define DEBUG(Expression)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
#define EFI_SIZE_TO_PAGES(Size)
EFI_STATUS EFIAPI RunAllTestSuites(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
#define UT_ASSERT_MEM_EQUAL(BufferA, BufferB, Length)
#define UT_ASSERT_EQUAL(ValueA, ValueB)
EFI_STATUS EFIAPI CreateUnitTestSuite(OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle, IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *Name, IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL, IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL)
EFI_STATUS EFIAPI FreeUnitTestFramework(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
EFI_STATUS EFIAPI AddTestCase(IN UNIT_TEST_SUITE_HANDLE SuiteHandle, IN CHAR8 *Description, IN CHAR8 *Name, IN UNIT_TEST_FUNCTION Function, IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL, IN UNIT_TEST_CLEANUP CleanUp OPTIONAL, IN UNIT_TEST_CONTEXT Context OPTIONAL)
EFI_STATUS EFIAPI InitUnitTestFramework(OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *ShortTitle, IN CHAR8 *VersionString)