-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathtest.py
67 lines (67 loc) · 2.34 KB
/
test.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
import os
import sys
tests = {
'labkernel': (False, 'test_test.rs'),
'lab2': (False, 'pmm_test.rs'),
'lab3': (False, 'vm_test.rs'),
'labuser': (True, 'test_test.rs'),
'lab5': (True, 'fork_test.rs'),
'lab6': (True, 'stride_test.rs'),
'lab7': (False, 'mutex_test.rs'),
'lab8': (True, 'pipe_test.rs'),
}
if sys.argv[1] == 'clean':
os.system('rm lab*')
exit()
print('testing ' + sys.argv[1] + '...')
try:
user_test, test_file = tests[sys.argv[1]]
if user_test:
# user_test
# save process/mod.rs
os.system('\\cp os/src/process/mod.rs os/src/process/mod_backup.rs')
# replace with user test
os.system('\\cp test/usr/' + test_file +
' usr/rust/src/bin/' + test_file)
s = open('os/src/process/mod.rs').read()
s = s.replace('rust/user_shell', 'rust/' +
test_file[:test_file.find('.')])
with open('os/src/process/mod.rs', 'w') as f:
f.write(s)
# try test
c = os.system('make clean')
c = os.system('make run > ' + sys.argv[1] + '.result')
if c == 0:
print('test successfully')
else:
print('test failed')
print('see ' + sys.argv[1] + '.result')
# remove user test
os.system('rm usr/rust/src/bin/' + test_file)
# backup process/mod.rs
os.system('\\cp os/src/process/mod_backup.rs os/src/process/mod.rs')
os.system('rm os/src/process/mod_backup.rs')
# open result file
if c == 0:
os.system('cat ' + sys.argv[1] + '.result | less')
else:
# kernel test
# save init.rs
os.system('\\cp os/src/init.rs os/src/init_backup.rs')
# replace with kernel test
os.system('\\cp test/' + test_file + ' os/src/init.rs')
# try test
c = os.system('make run > ' + sys.argv[1] + '.result')
if c == 0:
print('test successfully')
else:
print('test failed')
print('see ' + sys.argv[1] + '.result')
# backup init.rs
os.system('\\cp os/src/init_backup.rs os/src/init.rs')
os.system('rm os/src/init_backup.rs')
# open result file
if c == 0:
os.system('cat ' + sys.argv[1] + '.result | less')
except:
print('Usage: python3 test.py labX/clean (X={2,3,5,6,7,8,kernel,user})')