First upload
[CS310.git] / grade_lab_lazy.py
bloba4fafab4b5314b6c2484689d69292ecee7c76474
1 #!/usr/bin/env python3
3 import re
4 import sys
5 from gradelib import *
7 r = Runner(save("xv6.out"))
9 PTE_PRINT = """page table 0x0000000087f6e000
10 ..0: pte 0x0000000021fda801 pa 0x0000000087f6a000
11 .. ..0: pte 0x0000000021fda401 pa 0x0000000087f69000
12 .. .. ..0: pte 0x0000000021fdac1f pa 0x0000000087f6b000
13 .. .. ..1: pte 0x0000000021fda00f pa 0x0000000087f68000
14 .. .. ..2: pte 0x0000000021fd9c1f pa 0x0000000087f67000
15 ..255: pte 0x0000000021fdb401 pa 0x0000000087f6d000
16 .. ..511: pte 0x0000000021fdb001 pa 0x0000000087f6c000
17 .. .. ..510: pte 0x0000000021fdd807 pa 0x0000000087f76000
18 .. .. ..511: pte 0x000000002000200b pa 0x0000000080008000"""
20 VAL_RE = "(0x00000000[0-9a-f]+)"
21 INDENT_RE = r"\s*\.\.\s*"
22 INDENT_ESC = "\\\s*\.\.\\\s*"
24 @test(0, "running lazytests")
25 def test_lazytests():
26 r.run_qemu(shell_script([
27 'lazytests'
28 ]))
30 @test(10, "lazy: pte printout", parent=test_lazytests)
31 def test_filetest():
32 first = True
33 p = re.compile(VAL_RE)
34 d = re.compile(INDENT_RE)
35 for l in PTE_PRINT.splitlines():
36 l = d.sub(INDENT_ESC, l)
37 l = p.sub(VAL_RE, l)
38 r.match(r'^{}$'.format(l))
39 if first:
40 first = False
41 else:
42 matches = re.findall(r'^{}$'.format(l), r.qemu.output, re.MULTILINE)
43 assert_equal(len(matches[0]), 2)
44 pa = (int(matches[0][0], 16) >> 10) << 12
45 assert_equal(int(matches[0][1], 16), pa)
47 @test(20, "lazy: map", parent=test_lazytests)
48 def test_filetest():
49 r.match("^test lazy unmap: OK$")
51 @test(20, "lazy: unmap", parent=test_lazytests)
52 def test_memtest():
53 r.match("test lazy alloc: OK$")
55 @test(0, "usertests")
56 def test_usertests():
57 r.run_qemu(shell_script([
58 'usertests'
59 ]), timeout=300)
61 def usertest_check(testcase, nextcase, output):
62 if not re.search(r'\ntest {}: [\s\S]*OK\ntest {}'.format(testcase, nextcase), output):
63 raise AssertionError('Failed ' + testcase)
65 @test(4, "usertests: pgbug", parent=test_usertests)
66 def test_pgbug():
67 usertest_check("pgbug", "sbrkbugs", r.qemu.output)
69 @test(4, "usertests: sbrkbugs", parent=test_usertests)
70 def test_sbrkbugs():
71 usertest_check("sbrkbugs", "badarg", r.qemu.output)
73 @test(4, "usertests: argptest", parent=test_usertests)
74 def test_argptest():
75 usertest_check("argptest", "createdelete", r.qemu.output)
77 @test(4, "usertests: sbrkmuch", parent=test_usertests)
78 def test_sbrkmuch():
79 usertest_check("sbrkmuch", "kernmem", r.qemu.output)
81 @test(4, "usertests: sbrkfail", parent=test_usertests)
82 def test_sbrkfail():
83 usertest_check("sbrkfail", "sbrkarg", r.qemu.output)
85 @test(5, "usertests: sbrkarg", parent=test_usertests)
86 def test_sbrkarg():
87 usertest_check("sbrkarg", "validatetest", r.qemu.output)
89 @test(5, "usertests: stacktest", parent=test_usertests)
90 def test_stacktest():
91 usertest_check("stacktest", "opentest", r.qemu.output)
93 @test(20, "usertests: all tests", parent=test_usertests)
94 def test_usertests_all():
95 r.match('^ALL TESTS PASSED$')
97 if __name__ == '__main__':
98 if len(sys.argv) > 1:
99 run_tests(outputJSON=sys.argv[1])
100 else:
101 run_tests()