-
Notifications
You must be signed in to change notification settings - Fork 18
/
grade-lab1
executable file
·55 lines (45 loc) · 1.77 KB
/
grade-lab1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
import re
from gradelib import *
r = Runner(save("jos.out"),
stop_breakpoint("readline"))
@test(0, "running JOS")
def test_jos():
r.run_qemu()
@test(20, parent=test_jos)
def test_printf():
r.match("6828 decimal is 15254 octal!")
BACKTRACE_RE = r"^ *rbp +00000080042[0-9a-z]{5} +rip +000000800420[0-1][0-9a-z]{3}"
@test(10, parent=test_jos)
def test_backtrace_count():
matches = re.findall(BACKTRACE_RE, r.qemu.output, re.MULTILINE)
assert_equal(len(matches), 8)
@test(10, parent=test_jos)
def test_backtrace_arguments():
matches = re.findall(r"kern/init.c:[0-9]+: +test_backtrace\+[0-9]{16} +args:[0-9] +([0-9a-f]{16})", r.qemu.output, re.MULTILINE)
assert_equal("\n".join(matches[:7]),
"\n".join("%016x" % n for n in [0,1,2,3,4,5]))
@test(5, parent=test_jos)
def test_backtrace_symbols():
matches = re.findall(r"kern/init.c:[0-9]+: +([^+]*)\+", r.qemu.output)
assert_equal("\n".join(matches[:7]),
"\n".join(["test_backtrace"] * 6 + ["i386_init"]))
matches = re.findall(r"kern/monitor.c:[0-9]+: +([^+]*)\+", r.qemu.output)
assert_equal("\n".join(matches),
"\n".join(["mon_backtrace"]))
@test(5, parent=test_jos)
def test_backtrace_lines():
matches = re.findall(r"([^ ]*init.c:([0-9]+):) +test_backtrace\+", r.qemu.output)
assert matches, "No line numbers"
code = open('kern/init.c').read().split('\n');
begin = 0
end = 0
for i in range(len(code)):
if code[i].startswith('test_backtrace('):
begin = i + 2
if begin > 0 and code[i].startswith('}'):
end = i
if any(int(m[1]) < begin or int(m[1]) > end for m in matches):
assert_equal("\n".join(m[0] for m in matches),
"Line numbers between 5 and 50")
run_tests()