-
Notifications
You must be signed in to change notification settings - Fork 4
/
grade-lab-pgtbl
executable file
·99 lines (82 loc) · 3.06 KB
/
grade-lab-pgtbl
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
import re
from gradelib import *
r = Runner(save("xv6.out"))
PTE_PRINT = """page table 0x0000000087f6e000
..0: pte 0x0000000021fda801 pa 0x0000000087f6a000
.. ..0: pte 0x0000000021fda401 pa 0x0000000087f69000
.. .. ..0: pte 0x0000000021fdac1f pa 0x0000000087f6b000
.. .. ..1: pte 0x0000000021fda00f pa 0x0000000087f68000
.. .. ..2: pte 0x0000000021fd9c1f pa 0x0000000087f67000
..255: pte 0x0000000021fdb401 pa 0x0000000087f6d000
.. ..511: pte 0x0000000021fdb001 pa 0x0000000087f6c000
.. .. ..510: pte 0x0000000021fdd807 pa 0x0000000087f76000
.. .. ..511: pte 0x0000000020001c0b pa 0x0000000080007000"""
VAL_RE = "(0x00000000[0-9a-f]+)"
INDENT_RE = r"\s*\.\.\s*"
INDENT_ESC = "\\\s*\.\.\\\s*"
@test(10, "pte printout")
def test_pteprint():
first = True
r.run_qemu(shell_script([
'echo hi'
]))
r.match('^hi')
p = re.compile(VAL_RE)
d = re.compile(INDENT_RE)
for l in PTE_PRINT.splitlines():
l = d.sub(INDENT_ESC, l)
l = p.sub(VAL_RE, l)
r.match(r'^{}$'.format(l))
if first:
first = False
else:
matches = re.findall(r'^{}$'.format(l), r.qemu.output, re.MULTILINE)
assert_equal(len(matches[0]), 2)
pa = (int(matches[0][0], 16) >> 10) << 12
assert_equal(int(matches[0][1], 16), pa)
@test(5, "answers-pgtbl.txt")
def test_answers():
# just a simple sanity check, will be graded manually
check_answers("answers-pgtbl.txt")
@test(5, "count copyin")
def test_count():
r.run_qemu(shell_script([
'stats', 'stats'
]), timeout=150)
matches = re.findall(r'^copyin: (\d+)', r.qemu.output, re.MULTILINE)
assert_equal(len(matches), 2)
assert_equal(int(matches[1]), int(matches[0]) + 28)
matches = re.findall(r'^copyinstr: (\d+)', r.qemu.output, re.MULTILINE)
assert_equal(len(matches), 2)
assert_equal(int(matches[1]), int(matches[0]) + 3)
@test(0, "usertests")
def test_usertests():
r.run_qemu(shell_script([
'usertests'
]), timeout=2000)
def usertest_check(testcase, nextcase, output):
if not re.search(r'\ntest {}: [\s\S]*OK\ntest {}'.format(testcase, nextcase), output):
raise AssertionError('Failed ' + testcase)
@test(5, "usertests: copyin", parent=test_usertests)
def test_copyin():
usertest_check("copyin", "copyout", r.qemu.output)
@test(5, "usertests: copyinstr1", parent=test_usertests)
def test_copyin():
usertest_check("copyinstr1", "copyinstr2", r.qemu.output)
@test(5, "usertests: copyinstr2", parent=test_usertests)
def test_copyinstr2():
usertest_check("copyinstr2", "copyinstr3", r.qemu.output)
@test(5, "usertests: copyinstr3", parent=test_usertests)
def test_copyinstr3():
usertest_check("copyinstr3", "truncate1", r.qemu.output)
@test(5, "usertests: sbrkmuch", parent=test_usertests)
def test_sbrkmuch():
usertest_check("sbrkmuch", "kernmem", r.qemu.output)
@test(20, "usertests: all tests", parent=test_usertests)
def test_usertests():
r.match('^ALL TESTS PASSED$')
@test(1, "time")
def test_time():
check_time()
run_tests()