Skip to content

Commit 3bbb19d

Browse files
committed
tests: replace mmap with test kernel module for test_read_physical()
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]>
1 parent daf675b commit 3bbb19d

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

tests/linux_kernel/helpers/test_mm.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import mmap
77
import os
88
import struct
9+
import sys
910
import tempfile
1011
import unittest
1112

@@ -43,6 +44,7 @@
4344
from tests.linux_kernel import (
4445
LinuxKernelTestCase,
4546
mlock,
47+
prng32,
4648
skip_unless_have_full_mm_support,
4749
skip_unless_have_test_kmod,
4850
)
@@ -227,13 +229,16 @@ def test_virt_to_phys(self):
227229
virt_to_phys(self.prog["drgn_test_va"]), self.prog["drgn_test_pa"]
228230
)
229231

232+
@skip_unless_have_test_kmod
230233
def test_read_physical(self):
231-
with self._pages() as (map, _, pfns):
232-
for i, pfn in enumerate(pfns):
233-
self.assertEqual(
234-
self.prog.read(pfn * mmap.PAGESIZE, mmap.PAGESIZE, True),
235-
map[i * mmap.PAGESIZE : (i + 1) * mmap.PAGESIZE],
236-
)
234+
expected = bytearray()
235+
for x in prng32("PAGE"):
236+
expected.extend(x.to_bytes(4, sys.byteorder))
237+
if len(expected) >= mmap.PAGESIZE:
238+
break
239+
self.assertEqual(
240+
self.prog.read(self.prog["drgn_test_pa"], mmap.PAGESIZE, True), expected
241+
)
237242

238243
@skip_unless_have_full_mm_support
239244
def test_access_process_vm(self):

tests/linux_kernel/kmod/drgn_test.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,21 @@ struct page *drgn_test_compound_page;
150150

151151
static int drgn_test_mm_init(void)
152152
{
153+
u32 fill;
154+
153155
drgn_test_page = alloc_page(GFP_KERNEL);
154156
if (!drgn_test_page)
155157
return -ENOMEM;
156158
drgn_test_compound_page = alloc_pages(GFP_KERNEL | __GFP_COMP, 1);
157159
if (!drgn_test_compound_page)
158160
return -ENOMEM;
159161
drgn_test_va = page_address(drgn_test_page);
162+
// Fill the page with a PRNG sequence.
163+
fill = drgn_test_prng32_seed("PAGE");
164+
for (int i = 0; i < PAGE_SIZE / sizeof(fill); i++) {
165+
fill = drgn_test_prng32(fill);
166+
((u32 *)drgn_test_va)[i] = fill;
167+
}
160168
drgn_test_pa = virt_to_phys(drgn_test_va);
161169
drgn_test_pfn = PHYS_PFN(drgn_test_pa);
162170
return 0;

0 commit comments

Comments
 (0)