Skip to content

Commit

Permalink
tests: replace mmap with test kernel module for test_read_physical()
Browse files Browse the repository at this point in the history
tests.linux_kernel.helpers.test_mm.TestMm.test_read_physical() fails on
Arm when the user page is mapped from high memory. Replace it with a
test case that uses the test physical address from the test kernel
module and asserts the expected PRNG data. (We will probably run into
more tests that fail with high memory once #244 is merged.)

Signed-off-by: Omar Sandoval <[email protected]>
  • Loading branch information
osandov committed Feb 22, 2023
1 parent dc38822 commit 69f5352
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tests/linux_kernel/helpers/test_mm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mmap
import os
import struct
import sys
import tempfile
import unittest

Expand Down Expand Up @@ -43,6 +44,7 @@
from tests.linux_kernel import (
LinuxKernelTestCase,
mlock,
prng32,
skip_unless_have_full_mm_support,
skip_unless_have_test_kmod,
)
Expand Down Expand Up @@ -227,13 +229,16 @@ def test_virt_to_phys(self):
virt_to_phys(self.prog["drgn_test_va"]), self.prog["drgn_test_pa"]
)

@skip_unless_have_test_kmod
def test_read_physical(self):
with self._pages() as (map, _, pfns):
for i, pfn in enumerate(pfns):
self.assertEqual(
self.prog.read(pfn * mmap.PAGESIZE, mmap.PAGESIZE, True),
map[i * mmap.PAGESIZE : (i + 1) * mmap.PAGESIZE],
)
expected = bytearray()
for x in prng32("PAGE"):
expected.extend(x.to_bytes(4, sys.byteorder))
if len(expected) >= mmap.PAGESIZE:
break
self.assertEqual(
self.prog.read(self.prog["drgn_test_pa"], mmap.PAGESIZE, True), expected
)

@skip_unless_have_full_mm_support
def test_access_process_vm(self):
Expand Down
9 changes: 9 additions & 0 deletions tests/linux_kernel/kmod/drgn_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,22 @@ struct page *drgn_test_compound_page;

static int drgn_test_mm_init(void)
{
u32 fill;
size_t i;

drgn_test_page = alloc_page(GFP_KERNEL);
if (!drgn_test_page)
return -ENOMEM;
drgn_test_compound_page = alloc_pages(GFP_KERNEL | __GFP_COMP, 1);
if (!drgn_test_compound_page)
return -ENOMEM;
drgn_test_va = page_address(drgn_test_page);
// Fill the page with a PRNG sequence.
fill = drgn_test_prng32_seed("PAGE");
for (i = 0; i < PAGE_SIZE / sizeof(fill); i++) {
fill = drgn_test_prng32(fill);
((u32 *)drgn_test_va)[i] = fill;
}
drgn_test_pa = virt_to_phys(drgn_test_va);
drgn_test_pfn = PHYS_PFN(drgn_test_pa);
return 0;
Expand Down

0 comments on commit 69f5352

Please sign in to comment.