Skip to content

Commit 252c774

Browse files
committed
qemu: Add qemu-ptdump test
1 parent 8f122df commit 252c774

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

scripts/test/qemu-ptdump

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/python3
2+
#
3+
# Test that ptdump works
4+
5+
import os
6+
import sys
7+
import logging
8+
sys.path.append(f'{os.path.dirname(sys.argv[0])}/../../lib')
9+
10+
from qemu import QemuConfig, qemu_main, kvm_or_tcg
11+
from utils import setup_logging, test_harness
12+
from dump import read_symbols, find_symbol
13+
14+
15+
def test(name, cpu, machine):
16+
qconf = QemuConfig(machine)
17+
qconf.configure_from_env()
18+
qconf.net_tests = False
19+
qconf.mem = '2G'
20+
qconf.smp = 1
21+
qconf.cpu = cpu
22+
qconf.accel = kvm_or_tcg(machine, cpu)
23+
24+
syms = read_symbols(qconf.vmlinux)
25+
26+
start = find_symbol(syms, '__start')
27+
28+
boundary = find_symbol(syms, '__srwx_boundary')
29+
if boundary is None:
30+
boundary = find_symbol(syms, '__init_begin')
31+
32+
if start is None or boundary is None:
33+
logging.error("Can't determine SRWX boundary?")
34+
return False
35+
36+
37+
def test(p):
38+
p.cmd('mount -t debugfs none /sys/kernel/debug')
39+
p.send('cat /sys/kernel/debug/kernel_page_tables')
40+
i = p.expect(["can't open '/sys/kernel/debug/kernel_page_tables': No such file or directory",
41+
"Start of kernel VM"])
42+
43+
if i == 0:
44+
logging.error("Kernel not built with CONFIG_PTDUMP_DEBUGFS?")
45+
return False
46+
47+
if cpu == 'power9':
48+
p.expect("---[ Start of kernel VM ]---")
49+
p.expect("0xc000000000000000-0xc000000001ffffff 0x0000000000000000 32M r X pte valid present dirty accessed")
50+
p.expect("0xc000000002000000-0xc00000007fffffff 0x0000000002000000 2016M r w pte valid present dirty accessed")
51+
p.expect("---[ vmalloc() Area ]---")
52+
# vmalloc/IO mappings change so skip those
53+
p.expect("---[ vmemmap start ]---")
54+
p.expect("0xc00c000000000000-0xc00c0000001fffff 0x000000006e000000 2M r w pte valid present dirty accessed")
55+
elif cpu == 'power8':
56+
p.cmd('cat /sys/kernel/debug/kernel_hash_pagetable | head')
57+
58+
p.expect_prompt()
59+
60+
qconf.callback = test
61+
qconf.apply_defaults()
62+
63+
return qemu_main(qconf)
64+
65+
66+
def main():
67+
setup_logging()
68+
69+
rc = True
70+
rc &= test_harness(test, 'ptdump', cpu='power8', machine='pseries')
71+
rc &= test_harness(test, 'ptdump', cpu='power9', machine='pseries')
72+
73+
return rc
74+
75+
76+
sys.exit(0 if main() else 1)

0 commit comments

Comments
 (0)