forked from Ubsefor/oscourse-shared
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grade-lab9
executable file
·159 lines (138 loc) · 4.78 KB
/
grade-lab9
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
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(8)
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(6)
def test_faultread():
r.user_test("faultread")
r.match(E(".$E1. user fault va 00000000 ip 008....."),
"TRAP frame at 0x804.......",
" trap 0x0000000e Page Fault",
" err 0x00000004.*",
E(".$E1. free env $E1"),
no=["I read ........ from location 0."])
@test(6)
def test_faultwrite():
r.user_test("faultwrite")
r.match(E(".$E1. user fault va 00000000 ip 008....."),
"TRAP frame at 0x804.......",
" trap 0x0000000e Page Fault",
" err 0x00000006.*",
E(".$E1. free env $E1"))
@test(8)
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(8)
def test_faultalloc():
r.user_test("faultalloc")
r.match("fault beefdead",
"this string was faulted in at beefdead",
"fault cafebffe",
"fault cafec000",
"this string was faulted in at cafebffe",
E(".$E1. exiting gracefully"),
E(".$E1. free env $E1"))
@test(8)
def test_faultallocbad():
r.user_test("faultallocbad")
r.match(E(".$E1. user_mem_check assertion failure for va 00000000deadbeef"),
E(".$E1. free env $E1"))
@test(8)
def test_faultnostack():
r.user_test("faultnostack")
r.match(E(".$E1. user_mem_check assertion failure for va 0000007fffff...."),
E(".$E1. free env $E1"))
@test(8)
def test_faultbadhandler():
r.user_test("faultbadhandler")
r.match(E(".$E1. user_mem_check assertion failure for va 0000007fffff...."),
E(".$E1. free env $E1"))
@test(8)
def test_faultevilhandler():
r.user_test("faultevilhandler")
r.match(E(".$E1. user_mem_check assertion failure for va 0000007fffff...."),
E(".$E1. free env $E1"))
@test(8)
def test_forktree():
r.user_test("forktree", timeout=120)
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(8)
def test_spin():
r.user_test("spin", timeout=120)
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(8)
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(8)
def test_primes():
r.user_test("primes", stop_on_line("101"), stop_on_line(".*panic"),
make_args=["CPUS=4"], timeout=120)
r.match(E(".00000000. new env $E1"),
E(".$E1. new env $E2"),
E("2 .$E2. new env $E3"),
E("3 .$E3. new env $E4"),
E("5 .$E4. new env $E5"),
E("7 .$E5. new env $E6"),
E("11 .$E6. new env $E7"),
E("101 .$E27. new env $E28"))
end_part("C")
run_tests()