This repository has been archived by the owner on Apr 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrade-lab4
executable file
·108 lines (91 loc) · 2.86 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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import re, sys
import random, string, base64, time
from gradelib import *
from base64 import b64decode as decode
def is_hex(s):
try:
int(s, 16)
return True
except ValueError:
return False
clock_thdlr_addr = 0
envrun_running = 0
def set_breakpoint_on_clock(line):
global envrun_running, clock_thdlr_addr
if envrun_running == 0:
clock_thdlr_addr = get_symbol_address("clock_thdlr")[0]
r.gdb.breakpoint(clock_thdlr_addr)
envrun_running += 1
run = 10
time_diff = []
def measure_time(out):
global run, time_diff
if out.startswith("T"):
if run == 0:
raise TerminateTest
if run % 2 == 0:
time_diff.append(time.time())
else:
time_diff[-1] = time.time() - time_diff[-1]
run -= 1
r.gdb.cont()
return 0
res = []
def save_res(out):
global res
if is_hex(out):
res.append(out)
return 1
return 0
def continue_after_i386_init(out):
if out.startswith("T"):
pp = ['_head64', '_generall_syscall', 'sys_yield', 'sys_exit']
map(lambda x: r.gdb.view_memory(get_symbol_address(x)[0], 1), pp)
r.gdb.remove_breakpoint(get_symbol_address("i386_init")[0])
r.gdb.cont()
return 1
return 0
r = Runner(save("jos.out"),
add_breakpoint("i386_init"),
call_on_line(r"envrun RUNNING:", set_breakpoint_on_clock),
add_gdb_command(continue_after_i386_init),
add_gdb_command(save_res),
add_gdb_command(save_res),
add_gdb_command(save_res),
add_gdb_command(save_res),
add_gdb_command(measure_time))
@test(0, "running JOS")
def test_jos():
#r.run_qemu(target_base="qemu-oscheck")
print(color("yellow", "Please, be patient. It takes from 10 to 20 seconds to run the tests."))
r.run_qemu()
@test(10, parent=test_jos)
def test_cli():
e = False
if len(res) == 4:
if res[0] != u'fa' or res[3] != u'fa':
e = True
if res[1] != u'fa' and res[2] != u'fa':
e = True
if e:
raise AssertionError("cli check isn't passed.\n")
@test(10, parent=test_jos)
def test_enabled_interrupts():
m = re.search(r'^enabled interrupts: 2 8$', r.qemu.output, re.MULTILINE)
if not m:
raise AssertionError("Clock IRQ is masked on controller.\n")
@test(40, parent=test_jos)
def test_rtc():
if envrun_running == 0:
raise AssertionError("RTC isn't working.\n")
@test(40, parent=test_jos)
def test_frequency():
if len(time_diff):
avr = sum(time_diff) / len(time_diff)
if not (0.47 < avr and avr < 0.53):
raise AssertionError("RTC should fire interrupts once in 0.5s (measured time: %.2fs)\n" % avr)
else:
raise AssertionError("Can't measure frequency of RTC interrupts.\n")
run_tests()