diff options
Diffstat (limited to 'na/test')
| -rw-r--r-- | na/test/test_pmm.cc | 46 | ||||
| -rw-r--r-- | na/test/test_slab.cc | 4 | ||||
| -rw-r--r-- | na/test/test_vmm.cc | 48 |
3 files changed, 44 insertions, 54 deletions
diff --git a/na/test/test_pmm.cc b/na/test/test_pmm.cc index 3263662..948e444 100644 --- a/na/test/test_pmm.cc +++ b/na/test/test_pmm.cc @@ -28,11 +28,11 @@ void selftest_pmm() ST_ASSERT(f->state == FrameState::Allocated); ST_ASSERT(f->order == 0); - uint64 pa = frame_to_pa(f); + uint64 pa = frame_to_pa(f).raw; ST_ASSERT_EQ(pa % kPageSize, 0ULL); // 4KB aligned - uint64 va = frame_to_va(f); - ST_ASSERT_EQ(va, pa_to_va(pa)); + uint64 va = frame_to_va(f).raw; + ST_ASSERT_EQ(va, pa_to_va(phys_addr(pa)).raw); pmm_free_frame(f); } @@ -45,7 +45,7 @@ void selftest_pmm() ST_ASSERT(f1 != nullptr); ST_ASSERT(f2 != nullptr); ST_ASSERT_NE(f1, f2); - ST_ASSERT_NE(frame_to_pa(f1), frame_to_pa(f2)); + ST_ASSERT_NE(frame_to_pa(f1).raw, frame_to_pa(f2).raw); pmm_free_frame(f2); pmm_free_frame(f1); } @@ -54,12 +54,12 @@ void selftest_pmm() st_begin("pmm: free then re-alloc (PCP)"); { Frame* f1 = pmm_alloc_frame(); - uint64 pa1 = frame_to_pa(f1); + uint64 pa1 = frame_to_pa(f1).raw; pmm_free_frame(f1); // PCP should return the most recently freed frame Frame* f2 = pmm_alloc_frame(); - uint64 pa2 = frame_to_pa(f2); + uint64 pa2 = frame_to_pa(f2).raw; ST_ASSERT_EQ(pa1, pa2); pmm_free_frame(f2); } @@ -71,7 +71,7 @@ void selftest_pmm() ST_ASSERT(f != nullptr); ST_ASSERT(f->order == 2); - uint64 pa = frame_to_pa(f); + uint64 pa = frame_to_pa(f).raw; ST_ASSERT_EQ(pa % (kPageSize * 4), 0ULL); // Naturally aligned pmm_free_frames(f, 2); @@ -105,8 +105,8 @@ void selftest_pmm() { Frame* f = pmm_alloc_frame(); ST_ASSERT(f != nullptr); - uint64 pa = frame_to_pa(f); - Frame* f2 = pa_to_frame(pa); + uint64 pa = frame_to_pa(f).raw; + Frame* f2 = pa_to_frame(phys_addr(pa)); ST_ASSERT_EQ(f, f2); pmm_free_frame(f); } @@ -134,7 +134,7 @@ void selftest_pmm() { Frame* f = pmm_alloc_frames(3); ST_ASSERT(f != nullptr); - uint64 pa = frame_to_pa(f); + uint64 pa = frame_to_pa(f).raw; ST_ASSERT_EQ(pa % (kPageSize * 8), 0ULL); pmm_free_frames(f, 3); } @@ -143,12 +143,12 @@ void selftest_pmm() st_begin("pmm: frame_decref to 0 and reuse (order-0)"); { Frame* f = pmm_alloc_frame(); - uint64 pa = frame_to_pa(f); + uint64 pa = frame_to_pa(f).raw; frame_decref(f); // drops 1 -> 0, freeing it // Next alloc from PCP should give back the same frame Frame* f2 = pmm_alloc_frame(); - ST_ASSERT_EQ(frame_to_pa(f2), pa); + ST_ASSERT_EQ(frame_to_pa(f2).raw, pa); pmm_free_frame(f2); } st_pass(); @@ -156,12 +156,12 @@ void selftest_pmm() st_begin("pmm: frame_decref to 0 on multi-page blocks (order-3)"); { Frame* f = pmm_alloc_frames(3); - uint64 pa = frame_to_pa(f); + uint64 pa = frame_to_pa(f).raw; frame_decref(f); // Should internally route to pmm_free_frames(f, 3) // Re-allocate order-3 and see if we get it back (buddy coalescing was respected) Frame* f2 = pmm_alloc_frames(3); - ST_ASSERT_EQ(frame_to_pa(f2), pa); + ST_ASSERT_EQ(frame_to_pa(f2).raw, pa); pmm_free_frames(f2, 3); } st_pass(); @@ -170,7 +170,7 @@ void selftest_pmm() { // Force split: allocate order-1, free it, allocate two order-0 Frame* f_ord1 = pmm_alloc_frames(1); - uint64 pa1 = frame_to_pa(f_ord1); + uint64 pa1 = frame_to_pa(f_ord1).raw; pmm_free_frames(f_ord1, 1); Frame* f0_a = pmm_alloc_frame(); @@ -182,7 +182,7 @@ void selftest_pmm() // Allocate order-1 again to verify successful coalescing Frame* f_ord1_again = pmm_alloc_frames(1); - ST_ASSERT_EQ(frame_to_pa(f_ord1_again), pa1); + ST_ASSERT_EQ(frame_to_pa(f_ord1_again).raw, pa1); pmm_free_frames(f_ord1_again, 1); } st_pass(); @@ -196,7 +196,7 @@ void selftest_pmm() ST_ASSERT(f0 != nullptr); ST_ASSERT(f2 != nullptr); ST_ASSERT(f0b != nullptr); - ST_ASSERT_NE(frame_to_pa(f0), frame_to_pa(f2)); + ST_ASSERT_NE(frame_to_pa(f0).raw, frame_to_pa(f2).raw); pmm_free_frame(f0); pmm_free_frames(f2, 2); @@ -225,7 +225,7 @@ void selftest_pmm() while (true) { Frame* f = pmm_alloc_frames(5); if (!f) break; - uint64* ptr = reinterpret_cast<uint64*>(frame_to_va(f)); + uint64* ptr = reinterpret_cast<uint64*>(frame_to_va(f).raw); *ptr = reinterpret_cast<uint64>(head); // encode order in the second word *(ptr + 1) = 5; @@ -235,7 +235,7 @@ void selftest_pmm() while (true) { Frame* f = pmm_alloc_frame(); if (!f) break; - uint64* ptr = reinterpret_cast<uint64*>(frame_to_va(f)); + uint64* ptr = reinterpret_cast<uint64*>(frame_to_va(f).raw); *ptr = reinterpret_cast<uint64>(head); *(ptr + 1) = 0; head = f; @@ -246,7 +246,7 @@ void selftest_pmm() // Free everything while (head) { - uint64* ptr = reinterpret_cast<uint64*>(frame_to_va(head)); + uint64* ptr = reinterpret_cast<uint64*>(frame_to_va(head).raw); Frame* nxt = reinterpret_cast<Frame*>(*ptr); uint64 order = *(ptr + 1); if (order == 5) pmm_free_frames(head, 5); @@ -268,11 +268,11 @@ void selftest_pmm() st_begin("pmm: pmm_get_mem_base / pmm_get_mem_size sanity"); { - uint64 base = pmm_get_mem_base(); + uint64 base = pmm_get_mem_base().raw; uint64 size = pmm_get_mem_size(); - // QEMU virt platform: RAM starts at 0x80000000 - ST_ASSERT(base >= 0x80000000ULL); + // We no longer assert on QEMU specific memory address + // ST_ASSERT(base >= 0x80000000ULL); ST_ASSERT(size > 0); // Size must be page-aligned ST_ASSERT_EQ(size % kPageSize, 0ULL); diff --git a/na/test/test_slab.cc b/na/test/test_slab.cc index 1035663..e3ac72d 100644 --- a/na/test/test_slab.cc +++ b/na/test/test_slab.cc @@ -200,8 +200,8 @@ void selftest_slab() } // At this point, we completely own all 32 objects of this slab page. - uint64 page_pa = ensure_pa(reinterpret_cast<uint64>(base_ptr)); - Frame* f = pa_to_frame(page_pa); + uint64 page_pa = va_to_pa(virt_addr(reinterpret_cast<uint64>(base_ptr))).raw; + Frame* f = pa_to_frame(phys_addr(page_pa)); ST_ASSERT(f->state == FrameState::Slab); ST_ASSERT(f->slab.obj_count == 32); diff --git a/na/test/test_vmm.cc b/na/test/test_vmm.cc index cd76140..049570f 100644 --- a/na/test/test_vmm.cc +++ b/na/test/test_vmm.cc @@ -8,6 +8,7 @@ #include <lume/selftest.h> #include <lume/addr.h> #include <lume/vmm.h> +#include <lume/pmm.h> #include <arch/config.h> /* Assuming pmap namespace is accessible or we can test basic structures */ @@ -15,47 +16,36 @@ void selftest_vmm() { st_begin("vmm: virtual/physical address translation"); { - uint64 pa = 0x80000000ULL; - uint64 va = pa_to_va(pa); - ST_ASSERT_EQ(va, 0xFFFFFFC080000000ULL); - ST_ASSERT_EQ(va_to_pa(va), pa); - - uint64 pfn = pa_to_pfn(pa); - ST_ASSERT_EQ(pfn, 0x80000ULL); - ST_ASSERT_EQ(pfn_to_pa(pfn), pa); - - ST_ASSERT(is_kernel_va(va)); - ST_ASSERT(!is_kernel_va(pa)); - - ST_ASSERT_EQ(ensure_pa(va), pa); - ST_ASSERT_EQ(ensure_pa(pa), pa); - - ST_ASSERT_EQ(ensure_va(va), va); - ST_ASSERT_EQ(ensure_va(pa), va); + PhysAddr pa = pmm_get_mem_base(); + VirtAddr va = pa_to_va(pa); + ST_ASSERT_EQ(va.raw, arch::g_direct_map_base + pa.raw); + ST_ASSERT_EQ(va_to_pa(va).raw, pa.raw); + + Pfn p = pa_to_pfn(pa); + ST_ASSERT_EQ(p.raw, pa.raw / kPageSize); + ST_ASSERT_EQ(pfn_to_pa(p).raw, pa.raw); } st_pass(); st_begin("vmm: page alignment macros"); { - uint64 addr = 0x80000FFFULL; - ST_ASSERT_EQ(page_align_down(addr), 0x80000000ULL); - ST_ASSERT_EQ(page_align_up(addr), 0x80001000ULL); - ST_ASSERT_EQ(page_align_down(0x80000000ULL), 0x80000000ULL); - ST_ASSERT_EQ(page_align_up(0x80000000ULL), 0x80000000ULL); + uint64 base = pmm_get_mem_base().raw; + uint64 addr = base + 0xFFF; + ST_ASSERT_EQ(page_align_down(addr), base); + ST_ASSERT_EQ(page_align_up(addr), base + kPageSize); + ST_ASSERT_EQ(page_align_down(base), base); + ST_ASSERT_EQ(page_align_up(base), base); } st_pass(); st_begin("vmm: mapping kernel MMIO (driver API)"); { - // Map 4KB of MMIO at 0x10001000 (UART is at 0x10000000) - vmm_map_kernel_mmio(0x10001000, 0x1000); + uint64 mmio_pa = pmm_get_mem_base().raw; + vmm_map_kernel_mmio(mmio_pa, 0x1000); // Verify it doesn't crash and address is reachable in higher half - uint64 va = pa_to_va(0x10001000); - ST_ASSERT(is_kernel_va(va)); - - // We can't safely dereference it here without knowing QEMU layout perfectly, - // but vmm_init should have mapped it. + uint64 va = pa_to_va(phys_addr(mmio_pa)).raw; + ST_ASSERT(va >= arch::g_direct_map_base); } st_pass(); } |
