forked from m-Vins/OS161-DEMAND-PAGING
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute_tests.py
217 lines (174 loc) · 5.28 KB
/
execute_tests.py
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import pexpect
import sys
import os
import shutil
import os.path
stats = [
"TLB Faults",
"TLB Faults with Free",
"TLB Faults with Replace",
"TLB Invalidations",
"TLB Reloads",
"Page Faults (Zeroed)",
"Page Faults (Disk)",
"Page Faults from ELF",
"Page Faults from Swapfile",
"Swapfile Writes"
]
programs = [
"palin",
"huge",
"sort",
"matmult",
"hugematmult1",
"hugematmult2",
"ctest"
]
tests = [
"at",
"at2",
"bt",
"km1",
"km2",
"km3 1000",
"km4"
]
def getprompt(proc, prompt):
which = proc.expect_exact([
prompt,
"panic: ", # panic message
"sys161: No progress in ", # sys161 deadman print
"sys161: Elapsed ", # sys161 shutdown print
pexpect.EOF,
pexpect.TIMEOUT
],
timeout=3600
) #large timeout due to ctest program which takes more time
if which == 0:
# got the prompt
return None
if which == 1:
proc.expect_exact([pexpect.EOF, pexpect.TIMEOUT])
return "panic"
if which == 2:
proc.expect_exact([pexpect.EOF, pexpect.TIMEOUT])
return "progress timeout"
if which == 3:
proc.expect_exact([pexpect.EOF, pexpect.TIMEOUT])
return "unexpected shutdown"
if which == 4:
return "unexpected end of input"
if which == 5:
return "top-level timeout"
return "runtest: Internal error: pexpect returned out-of-range result"
# end getprompt
def open_instance():
proc = pexpect.spawn("bash", ignore_sighup=False, encoding='utf-8')
#proc.logfile_read = sys.stdout
proc.sendline(f'cd {os.getenv("HOME",default=None)}/os161/root;sys161 kernel')
msg = getprompt(proc, "OS/161 kernel [? for menu]: ")
if msg:
print("ERROR STARTING OS")
sys.exit(-1)
return proc
def close_instance(proc):
proc.sendline("q")
msg = getprompt(proc, "The system is halted.")
if msg:
return None
output = proc.before
test_result_rows = [o.strip() for o in output.split("\n")][-12:-2]
proc.close()
return [r.split(" ")[-1] for r in test_result_rows]
def kill_instance(proc):
proc.close()
def run_program(proc, test):
return run_cmd(proc,"p testbin/" + test)
def run_cmd(proc,cmd):
print("Running command \"" + cmd + "\"")
proc.sendline(cmd)
msg = getprompt(proc, "OS/161 kernel [? for menu]: ")
if msg == None:
return proc.before
else:
return None
def extract_execution_time(output):
return output.split("\n")[-2].strip().split(" ")[2][:6]
def run_program_tests(f, ram_size):
passed_programs = []
for program in programs:
proc = open_instance()
program_output = run_program(proc, program)
if program_output:
execution_time = extract_execution_time(program_output)
results = close_instance(proc)
passed_programs.append(program)
f.write("|" + program + "|" + ram_size + "|" + execution_time + "|" + "|".join(results) + "|\n")
else:
kill_instance(proc)
f.write("|" + program + "|" + ram_size + "|-|" + "|".join(["-" for s in stats]) + "|\n")
return passed_programs
def main():
passed_tests = []
# Create sys161.conf backup
if not os.path.exists("../root/sys161.conf.backup"):
shutil.copyfile("../root/sys161.conf", "../root/sys161.conf.backup")
else:
shutil.copyfile("../root/sys161.conf.backup", "../root/sys161.conf")
# Init .md file
f = open("testresults.md", "w")
# Program tests header
f.write("# Programs\n")
f.write("| Program name | Ram size | Execution time | " + " | ".join(stats) + "|\n")
f.write("|".join(["-" for _ in range(len(stats) + 3)]) + "\n")
# Program tests
passed_programs = run_program_tests(f, "512K")
# Change ram size
fin = open("../root/sys161.conf.backup", "rt")
fout = open("../root/sys161.conf", "wt")
for line in fin:
fout.write(line.replace('31 mainboard ramsize=512K cpus=1', '31 mainboard ramsize=4M cpus=1'))
fin.close()
fout.close()
run_program_tests(f, "4M")
f.write("\n")
# Reset ram size
shutil.copyfile("../root/sys161.conf.backup", "../root/sys161.conf")
# Generic tests header
f.write("# Tests\n")
f.write("|Test name|Passed|\n")
f.write("|-|-|\n")
for test in tests:
proc = open_instance()
success = run_cmd(proc, test)
if success:
passed_tests.append(test)
close_instance(proc)
f.write("|" + test+"|" + "True" + "|\n")
else:
kill_instance(proc)
f.write("|" + test+"|" + "False" + "|\n")
f.write("\n")
# Stability test header
f.write("# Stability test\n")
f.write("|" + " | ".join(stats) + "|\n")
f.write("|" + "|".join(["-" for s in stats]) + "|\n")
# Stability test
proc = open_instance()
failures = 0
for _ in range(10):
for program in passed_programs:
success = run_program(proc, program)
if not success:
failures += 1
for test in passed_tests:
success = run_cmd(proc, test)
if not success:
failures += 1
results = close_instance(proc)
f.write("|" + "|".join(results) + "|\n")
print("\n")
print("Failures: " + str(failures))
f.close()
if __name__ == '__main__':
main()