* same with xv6
[mascara-docs.git] / i386 / MIT / course / src / git.lab / grade-lab4
blob39cb70fe66dc252e3410a9bd97c5b624df2b8b70
1 #!/usr/bin/env python
3 import re
4 from gradelib import *
6 r = Runner(save("jos.out"),
7 stop_breakpoint("readline"))
9 def E(s, trim=False):
10 """Expand $En in s to the environment ID of the n'th user
11 environment, accounting for idle environments."""
13 tmpl = "%x" if trim else "%08x"
14 return re.sub(r"\$E([0-9]+)",
15 lambda m: tmpl % (0x1007 + int(m.group(1))), s)
17 @test(5)
18 def test_dumbfork():
19 r.user_test("dumbfork")
20 r.match(".00000000. new env 00001000",
21 E(".00000000. new env $E1"),
22 "0: I am the parent.",
23 "9: I am the parent.",
24 "0: I am the child.",
25 "9: I am the child.",
26 "19: I am the child.",
27 E(".$E1. exiting gracefully"),
28 E(".$E1. free env $E1"),
29 E(".$E2. exiting gracefully"),
30 E(".$E2. free env $E2"))
32 end_part("A")
34 @test(5)
35 def test_faultread():
36 r.user_test("faultread")
37 r.match(E(".$E1. user fault va 00000000 ip 008....."),
38 "TRAP frame at 0xf....... from CPU .",
39 " trap 0x0000000e Page Fault",
40 " err 0x00000004.*",
41 E(".$E1. free env $E1"),
42 no=["I read ........ from location 0."])
44 @test(5)
45 def test_faultwrite():
46 r.user_test("faultwrite")
47 r.match(E(".$E1. user fault va 00000000 ip 008....."),
48 "TRAP frame at 0xf....... from CPU .",
49 " trap 0x0000000e Page Fault",
50 " err 0x00000006.*",
51 E(".$E1. free env $E1"))
53 @test(5)
54 def test_faultdie():
55 r.user_test("faultdie")
56 r.match("i faulted at va deadbeef, err 6",
57 E(".$E1. exiting gracefully"),
58 E(".$E1. free env $E1"))
60 @test(5)
61 def test_faultregs():
62 r.user_test("faultregs")
63 r.match("Registers in UTrapframe OK",
64 "Registers after page-fault OK",
65 no=["Registers in UTrapframe MISMATCH",
66 "Registers after page-fault MISMATCH"])
68 @test(5)
69 def test_faultalloc():
70 r.user_test("faultalloc")
71 r.match("fault deadbeef",
72 "this string was faulted in at deadbeef",
73 "fault cafebffe",
74 "fault cafec000",
75 "this string was faulted in at cafebffe",
76 E(".$E1. exiting gracefully"),
77 E(".$E1. free env $E1"))
79 @test(5)
80 def test_faultallocbad():
81 r.user_test("faultallocbad")
82 r.match(E(".$E1. user_mem_check assertion failure for va deadbeef"),
83 E(".$E1. free env $E1"))
85 @test(5)
86 def test_faultnostack():
87 r.user_test("faultnostack")
88 r.match(E(".$E1. user_mem_check assertion failure for va eebfff.."),
89 E(".$E1. free env $E1"))
91 @test(5)
92 def test_faultbadhandler():
93 r.user_test("faultbadhandler")
94 r.match(E(".$E1. user_mem_check assertion failure for va (deadb|eebfe)..."),
95 E(".$E1. free env $E1"))
97 @test(5)
98 def test_faultevilhandler():
99 r.user_test("faultevilhandler")
100 r.match(E(".$E1. user_mem_check assertion failure for va (f0100|eebfe)..."),
101 E(".$E1. free env $E1"))
103 @test(5)
104 def test_forktree():
105 r.user_test("forktree")
106 r.match("....: I am .0.",
107 "....: I am .1.",
108 "....: I am .000.",
109 "....: I am .100.",
110 "....: I am .110.",
111 "....: I am .111.",
112 "....: I am .011.",
113 "....: I am .001.",
114 E(".$E1. exiting gracefully"),
115 E(".$E2. exiting gracefully"),
116 ".0000200.. exiting gracefully",
117 ".0000200.. free env 0000200.")
119 end_part("B")
121 @test(5)
122 def test_spin():
123 r.user_test("spin")
124 r.match(".00000000. new env 00001000",
125 E(".00000000. new env $E1"),
126 "I am the parent. Forking the child...",
127 E(".$E1. new env $E2"),
128 "I am the parent. Running the child...",
129 "I am the child. Spinning...",
130 "I am the parent. Killing the child...",
131 E(".$E1. destroying $E2"),
132 E(".$E1. free env $E2"),
133 E(".$E1. exiting gracefully"),
134 E(".$E1. free env $E1"))
136 @test(5)
137 def test_stresssched():
138 r.user_test("stresssched", make_args=["CPUS=2"])
139 r.match(".000010... stresssched on CPU 0",
140 ".000010... stresssched on CPU 1",
141 no=[".*ran on two CPUs at once"])
143 @test(5)
144 def test_pingpong():
145 r.user_test("pingpong", make_args=["CPUS=2"])
146 r.match(".00000000. new env 00001000",
147 E(".00000000. new env $E1"),
148 E(".$E1. new env $E2"),
149 E("send 0 from $E1 to $E2", trim=True),
150 E("$E2 got 0 from $E1", trim=True),
151 E("$E1 got 1 from $E2", trim=True),
152 E("$E2 got 8 from $E1", trim=True),
153 E("$E1 got 9 from $E2", trim=True),
154 E("$E2 got 10 from $E1", trim=True),
155 E(".$E1. exiting gracefully"),
156 E(".$E1. free env $E1"),
157 E(".$E2. exiting gracefully"),
158 E(".$E2. free env $E2"))
160 @test(5)
161 def test_primes():
162 r.user_test("primes", stop_on_line("CPU .: 1877"), stop_on_line(".*panic"),
163 make_args=["CPUS=2"], timeout=30)
164 r.match(".00000000. new env 00001000",
165 E(".00000000. new env $E1"),
166 E(".$E1. new env $E2"),
167 E("CPU .: 2 .$E2. new env $E3"),
168 E("CPU .: 3 .$E3. new env $E4"),
169 E("CPU .: 5 .$E4. new env $E5"),
170 E("CPU .: 7 .$E5. new env $E6"),
171 E("CPU .: 11 .$E6. new env $E7"),
172 E("CPU .: 1877 .$E289. new env $E290"))
174 end_part("C")
176 run_tests()