forked from woai3c/MIT6.828
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grade-lab4
190 lines (166 loc) · 5.97 KB
/
grade-lab4
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python
import re
from gradelib import *
r = Runner(save("jos.out"),
stop_breakpoint("readline"))
def E(s, trim=False):
"""Expand $En in s to the environment ID of the n'th user
environment."""
tmpl = "%x" if trim else "%08x"
return re.sub(r"\$E([0-9]+)",
lambda m: tmpl % (0x1000 + int(m.group(1))-1), s)
@test(5)
def test_dumbfork():
r.user_test("dumbfork")
r.match(E(".00000000. new env $E1"),
E(".$E1. new env $E2"),
"0: I am the parent.",
"9: I am the parent.",
"0: I am the child.",
"9: I am the child.",
"19: I am the child.",
E(".$E1. exiting gracefully"),
E(".$E1. free env $E1"),
E(".$E2. exiting gracefully"),
E(".$E2. free env $E2"))
end_part("A")
@test(5)
def test_faultread():
r.user_test("faultread")
r.match(E(".$E1. user fault va 00000000 ip 008....."),
"TRAP frame at 0xf....... from CPU .",
" trap 0x0000000e Page Fault",
" err 0x00000004.*",
E(".$E1. free env $E1"),
no=["I read ........ from location 0."])
@test(5)
def test_faultwrite():
r.user_test("faultwrite")
r.match(E(".$E1. user fault va 00000000 ip 008....."),
"TRAP frame at 0xf....... from CPU .",
" trap 0x0000000e Page Fault",
" err 0x00000006.*",
E(".$E1. free env $E1"))
@test(5)
def test_faultdie():
r.user_test("faultdie")
r.match("i faulted at va deadbeef, err 6",
E(".$E1. exiting gracefully"),
E(".$E1. free env $E1"))
@test(5)
def test_faultregs():
r.user_test("faultregs")
r.match("Registers in UTrapframe OK",
"Registers after page-fault OK",
no=["Registers in UTrapframe MISMATCH",
"Registers after page-fault MISMATCH"])
@test(5)
def test_faultalloc():
r.user_test("faultalloc")
r.match("fault deadbeef",
"this string was faulted in at deadbeef",
"fault cafebffe",
"fault cafec000",
"this string was faulted in at cafebffe",
E(".$E1. exiting gracefully"),
E(".$E1. free env $E1"))
@test(5)
def test_faultallocbad():
r.user_test("faultallocbad")
r.match(E(".$E1. user_mem_check assertion failure for va deadbeef"),
E(".$E1. free env $E1"))
@test(5)
def test_faultnostack():
r.user_test("faultnostack")
r.match(E(".$E1. user_mem_check assertion failure for va eebfff.."),
E(".$E1. free env $E1"))
@test(5)
def test_faultbadhandler():
r.user_test("faultbadhandler")
r.match(E(".$E1. user_mem_check assertion failure for va (deadb|eebfe)..."),
E(".$E1. free env $E1"))
@test(5)
def test_faultevilhandler():
r.user_test("faultevilhandler")
r.match(E(".$E1. user_mem_check assertion failure for va (f0100|eebfe)..."),
E(".$E1. free env $E1"))
@test(5)
def test_forktree():
r.user_test("forktree")
r.match("....: I am .0.",
"....: I am .1.",
"....: I am .000.",
"....: I am .100.",
"....: I am .110.",
"....: I am .111.",
"....: I am .011.",
"....: I am .001.",
E(".$E1. exiting gracefully"),
E(".$E2. exiting gracefully"),
".0000200.. exiting gracefully",
".0000200.. free env 0000200.")
end_part("B")
@test(5)
def test_spin():
r.user_test("spin")
r.match(E(".00000000. new env $E1"),
"I am the parent. Forking the child...",
E(".$E1. new env $E2"),
"I am the parent. Running the child...",
"I am the child. Spinning...",
"I am the parent. Killing the child...",
E(".$E1. destroying $E2"),
E(".$E1. free env $E2"),
E(".$E1. exiting gracefully"),
E(".$E1. free env $E1"))
@test(5)
def test_stresssched():
r.user_test("stresssched", make_args=["CPUS=4"])
r.match(".000010... stresssched on CPU 0",
".000010... stresssched on CPU 1",
".000010... stresssched on CPU 2",
".000010... stresssched on CPU 3",
no=[".*ran on two CPUs at once"])
@test(5)
def test_sendpage():
r.user_test("sendpage", make_args=["CPUS=2"])
r.match(".00000000. new env 00001000",
E(".00000000. new env $E1"),
E(".$E1. new env $E2"),
E("$E1 got message: hello child environment! how are you?", trim=True),
E("child received correct message", trim=True),
E("$E2 got message: hello parent environment! I'm good", trim=True),
E("parent received correct message", trim=True),
E(".$E1. exiting gracefully"),
E(".$E1. free env $E1"),
E(".$E2. exiting gracefully"),
E(".$E2. free env $E2"))
@test(5)
def test_pingpong():
r.user_test("pingpong", make_args=["CPUS=4"])
r.match(E(".00000000. new env $E1"),
E(".$E1. new env $E2"),
E("send 0 from $E1 to $E2", trim=True),
E("$E2 got 0 from $E1", trim=True),
E("$E1 got 1 from $E2", trim=True),
E("$E2 got 8 from $E1", trim=True),
E("$E1 got 9 from $E2", trim=True),
E("$E2 got 10 from $E1", trim=True),
E(".$E1. exiting gracefully"),
E(".$E1. free env $E1"),
E(".$E2. exiting gracefully"),
E(".$E2. free env $E2"))
@test(5)
def test_primes():
r.user_test("primes", stop_on_line("CPU .: 1877"), stop_on_line(".*panic"),
make_args=["CPUS=4"], timeout=60)
r.match(E(".00000000. new env $E1"),
E(".$E1. new env $E2"),
E("CPU .: 2 .$E2. new env $E3"),
E("CPU .: 3 .$E3. new env $E4"),
E("CPU .: 5 .$E4. new env $E5"),
E("CPU .: 7 .$E5. new env $E6"),
E("CPU .: 11 .$E6. new env $E7"),
E("CPU .: 1877 .$E289. new env $E290"))
end_part("C")
run_tests()