-
Notifications
You must be signed in to change notification settings - Fork 4
/
grade-lab-traps
executable file
·70 lines (57 loc) · 1.83 KB
/
grade-lab-traps
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
#!/usr/bin/env python3
import os
import re
import subprocess
from gradelib import *
r = Runner(save("xv6.out"))
@test(5, "answers-traps.txt")
def test_answers():
# just a simple sanity check, will be graded manually
check_answers("answers-traps.txt")
BACKTRACE_RE = r"^(0x000000008[0-9a-f]+)"
def addr2line():
for f in ['riscv64-unknown-elf-addr2line', 'riscv64-linux-gnu-addr2line', 'addr2line', ]:
try:
devnull = open(os.devnull)
subprocess.Popen([f], stdout=devnull, stderr=devnull).communicate()
return f
except OSError:
continue
raise AssertionError('Cannot find the addr2line program')
@test(10, "backtrace test")
def test_backtracetest():
r.run_qemu(shell_script([
'bttest'
]))
a2l = addr2line()
matches = re.findall(BACKTRACE_RE, r.qemu.output, re.MULTILINE)
assert_equal(len(matches), 3)
files = ['sysproc.c', 'syscall.c', 'trap.c']
for f, m in zip(files, matches):
result = subprocess.run([a2l, '-e', 'kernel/kernel', m], stdout=subprocess.PIPE)
if not f in result.stdout.decode("utf-8"):
raise AssertionError('Trace is incorrect; no %s' % f)
@test(0, "running alarmtest")
def test_alarmtest():
r.run_qemu(shell_script([
'alarmtest'
]))
@test(20, "alarmtest: test0", parent=test_alarmtest)
def test_alarmtest_test0():
r.match('^test0 passed$')
@test(20, "alarmtest: test1", parent=test_alarmtest)
def test_alarmtest_test1():
r.match('^\\.?test1 passed$')
@test(10, "alarmtest: test2", parent=test_alarmtest)
def test_alarmtest_test2():
r.match('^\\.?test2 passed$')
@test(19, "usertests")
def test_usertests():
r.run_qemu(shell_script([
'usertests'
]), timeout=2000)
r.match('^ALL TESTS PASSED$')
@test(1, "time")
def test_time():
check_time()
run_tests()