-
Notifications
You must be signed in to change notification settings - Fork 18
/
grade-lab5
executable file
·139 lines (123 loc) · 4.04 KB
/
grade-lab5
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python
from gradelib import *
r = Runner(save("jos.out"),
stop_breakpoint("readline"))
def matchtest(parent, name, *args, **kw):
def do_test():
r.match(*args, **kw)
test(5, name, parent=parent)(do_test)
@test(0, "internal FS tests [fs/test.c]")
def test_fs():
r.user_test("hello")
matchtest(test_fs, "fs i/o",
"FS can do I/O",
no=["idle loop can do I/O"])
matchtest(test_fs, "check_bc",
"block cache is good")
matchtest(test_fs, "check_super",
"superblock is good")
matchtest(test_fs, "check_bitmap",
"bitmap is good")
matchtest(test_fs, "alloc_block",
"alloc_block is good")
matchtest(test_fs, "file_open",
"file_open is good")
matchtest(test_fs, "file_get_block",
"file_get_block is good")
matchtest(test_fs, "file_flush/file_truncate/file rewrite",
"file_flush is good",
"file_truncate is good",
"file rewrite is good")
@test(0)
def test_testfile():
r.user_test("testfile")
matchtest(test_testfile, "serve_open/file_stat/file_close",
"serve_open is good",
"file_stat is good",
"file_close is good",
"stale fileid is good")
matchtest(test_testfile, "file_read",
"file_read is good")
matchtest(test_testfile, "file_write",
"file_write is good")
matchtest(test_testfile, "file_read after file_write",
"file_read after file_write is good")
matchtest(test_testfile, "open",
"open is good")
matchtest(test_testfile, "large file",
"large file is good")
@test(10, "motd display [writemotd]")
def test_writemotd1():
r.user_test("writemotd", snapshot=False)
r.match("OLD MOTD",
"This is /motd, the message of the day.",
"NEW MOTD",
"This is the NEW message of the day!")
@test(10, "motd change [writemotd]", parent=test_writemotd1)
def test_writemotd2():
try:
r.user_test("writemotd")
r.match("OLD MOTD",
"This is the NEW message of the day!",
"NEW MOTD",
no=["This is /motd, the message of the day."])
finally:
reset_fs()
@test(10, "PTE_SHARE [testpteshare]")
def test_pte_share():
r.user_test("testpteshare")
r.match('fork handles PTE_SHARE right',
'spawn handles PTE_SHARE right')
@test(20, "start the shell [icode]")
def test_icode():
r.user_test("icode")
r.match('icode: read /motd',
'This is /motd, the message of the day.',
'icode: spawn /sbin/init',
'init: running',
'init: data seems okay',
'icode: exiting',
'init: bss seems okay',
"init: args: 'init' 'initarg1' 'initarg2'",
'init: running sh',
'\$ ')
@test(20)
def test_testshell():
r.user_test("testshell", timeout=60)
r.match("shell ran correctly")
# Obsolete
#@test(10)
def test_testpipe():
r.user_test("testpipe", stop_on_line("pipe tests passed"),
stop_on_line(".*panic"))
r.match("pipe read closed properly",
"pipe write closed properly")
# Obsolete
#@test(10)
def test_testpiperace():
r.user_test("testpiperace", stop_on_line("race didn't happen"),
stop_on_line(".*panic"))
r.match("race didn't happen",
no=["child detected race",
"RACE: pipe appears closed"])
# Obsolete
#@test(10)
def test_testpiperace2():
r.user_test("testpiperace2", stop_on_line("race didn't happen"),
stop_on_line(".*panic"))
r.match("race didn't happen",
no=["child detected race",
"RACE: pipe appears closed"])
def gen_primes(n):
rest = range(2, n)
while rest:
yield rest[0]
rest = [n for n in rest if n % rest[0]]
@test(10)
def test_primespipe():
r.user_test("primespipe", stop_on_line("[0-9]{4}$"), timeout=120)
primes = set(gen_primes(1000))
nonprimes = set(range(1000)) - primes
r.match(no=["%d$" % np for np in nonprimes],
*["%d$" % p for p in primes])
run_tests()