|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import re |
| 4 | +from gradelib import * |
| 5 | + |
| 6 | +r = Runner(save("jos.out"), |
| 7 | + stop_breakpoint("readline")) |
| 8 | + |
| 9 | +def E(s, trim=False): |
| 10 | + """Expand $En in s to the environment ID of the n'th user |
| 11 | + environment.""" |
| 12 | + |
| 13 | + tmpl = "%x" if trim else "%08x" |
| 14 | + return re.sub(r"\$E([0-9]+)", |
| 15 | + lambda m: tmpl % (0x1000 + int(m.group(1))-1), s) |
| 16 | + |
| 17 | +@test(5) |
| 18 | +def test_dumbfork(): |
| 19 | + r.user_test("dumbfork") |
| 20 | + r.match(E(".00000000. new env $E1"), |
| 21 | + E(".$E1. new env $E2"), |
| 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")) |
| 31 | + |
| 32 | +end_part("A") |
| 33 | + |
| 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."]) |
| 43 | + |
| 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")) |
| 52 | + |
| 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")) |
| 59 | + |
| 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"]) |
| 67 | + |
| 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")) |
| 78 | + |
| 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")) |
| 84 | + |
| 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")) |
| 90 | + |
| 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")) |
| 96 | + |
| 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")) |
| 102 | + |
| 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.") |
| 118 | + |
| 119 | +end_part("B") |
| 120 | + |
| 121 | +@test(5) |
| 122 | +def test_spin(): |
| 123 | + r.user_test("spin") |
| 124 | + r.match(E(".00000000. new env $E1"), |
| 125 | + "I am the parent. Forking the child...", |
| 126 | + E(".$E1. new env $E2"), |
| 127 | + "I am the parent. Running the child...", |
| 128 | + "I am the child. Spinning...", |
| 129 | + "I am the parent. Killing the child...", |
| 130 | + E(".$E1. destroying $E2"), |
| 131 | + E(".$E1. free env $E2"), |
| 132 | + E(".$E1. exiting gracefully"), |
| 133 | + E(".$E1. free env $E1")) |
| 134 | + |
| 135 | +@test(5) |
| 136 | +def test_stresssched(): |
| 137 | + r.user_test("stresssched", make_args=["CPUS=4"]) |
| 138 | + r.match(".000010... stresssched on CPU 0", |
| 139 | + ".000010... stresssched on CPU 1", |
| 140 | + ".000010... stresssched on CPU 2", |
| 141 | + ".000010... stresssched on CPU 3", |
| 142 | + no=[".*ran on two CPUs at once"]) |
| 143 | + |
| 144 | +@test(5) |
| 145 | +def test_sendpage(): |
| 146 | + r.user_test("sendpage", make_args=["CPUS=2"]) |
| 147 | + r.match(".00000000. new env 00001000", |
| 148 | + E(".00000000. new env $E1"), |
| 149 | + E(".$E1. new env $E2"), |
| 150 | + E("$E1 got message: hello child environment! how are you?", trim=True), |
| 151 | + E("child received correct message", trim=True), |
| 152 | + E("$E2 got message: hello parent environment! I'm good", trim=True), |
| 153 | + E("parent received correct message", trim=True), |
| 154 | + E(".$E1. exiting gracefully"), |
| 155 | + E(".$E1. free env $E1"), |
| 156 | + E(".$E2. exiting gracefully"), |
| 157 | + E(".$E2. free env $E2")) |
| 158 | + |
| 159 | +@test(5) |
| 160 | +def test_pingpong(): |
| 161 | + r.user_test("pingpong", make_args=["CPUS=4"]) |
| 162 | + r.match(E(".00000000. new env $E1"), |
| 163 | + E(".$E1. new env $E2"), |
| 164 | + E("send 0 from $E1 to $E2", trim=True), |
| 165 | + E("$E2 got 0 from $E1", trim=True), |
| 166 | + E("$E1 got 1 from $E2", trim=True), |
| 167 | + E("$E2 got 8 from $E1", trim=True), |
| 168 | + E("$E1 got 9 from $E2", trim=True), |
| 169 | + E("$E2 got 10 from $E1", trim=True), |
| 170 | + E(".$E1. exiting gracefully"), |
| 171 | + E(".$E1. free env $E1"), |
| 172 | + E(".$E2. exiting gracefully"), |
| 173 | + E(".$E2. free env $E2")) |
| 174 | + |
| 175 | +@test(5) |
| 176 | +def test_primes(): |
| 177 | + r.user_test("primes", stop_on_line("CPU .: 1877"), stop_on_line(".*panic"), |
| 178 | + make_args=["CPUS=4"], timeout=30) |
| 179 | + r.match(E(".00000000. new env $E1"), |
| 180 | + E(".$E1. new env $E2"), |
| 181 | + E("CPU .: 2 .$E2. new env $E3"), |
| 182 | + E("CPU .: 3 .$E3. new env $E4"), |
| 183 | + E("CPU .: 5 .$E4. new env $E5"), |
| 184 | + E("CPU .: 7 .$E5. new env $E6"), |
| 185 | + E("CPU .: 11 .$E6. new env $E7"), |
| 186 | + E("CPU .: 1877 .$E289. new env $E290")) |
| 187 | + |
| 188 | +end_part("C") |
| 189 | + |
| 190 | +run_tests() |
0 commit comments