-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·193 lines (164 loc) · 6.22 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
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
#!/usr/bin/env python
import atexit
import subprocess
import argparse
import tempfile
import glob
import time
import sys
import os
import tests.test_net
import tests.test_tracing
from operator import attrgetter
from tests.testing import *
os.environ["LC_ALL"]="C"
os.environ["LANG"]="C"
blacklist= [
"tst-dns-resolver.so",
"tst-feexcept.so",
]
add_tests([
SingleCommandTest('java_isolated', '/java_isolated.so -cp /tests/java/tests.jar:/tests/java/isolates.jar \
-Disolates.jar=/tests/java/isolates.jar org.junit.runner.JUnitCore io.osv.AllTestsThatTestIsolatedApp'),
SingleCommandTest('java_non_isolated', '/java.so -cp /tests/java/tests.jar:/tests/java/isolates.jar \
-Disolates.jar=/tests/java/isolates.jar org.junit.runner.JUnitCore io.osv.AllTestsThatTestNonIsolatedApp'),
SingleCommandTest('java-perms', '/java_isolated.so -cp /tests/java/tests.jar io.osv.TestDomainPermissions'),
])
class TestRunnerTest(SingleCommandTest):
def __init__(self, name):
super(TestRunnerTest, self).__init__(name, '/tests/%s' % name)
# Not all files in build/release/tests/tst-*.so may be on the test image
# (e.g., some may have actually remain there from old builds) - so lets take
# the list of tests actually in the image form the image's manifest file.
test_files = []
is_comment = re.compile("^[ \t]*(|#.*|\[manifest])$")
is_test = re.compile("^/tests/tst-.*.so")
with open('modules/tests/usr.manifest', 'r') as f:
for line in f:
line = line.rstrip();
if is_comment.match(line): continue;
components = line.split(": ", 2);
guestpath = components[0].strip();
hostpath = components[1].strip()
if is_test.match(guestpath):
test_files.append(guestpath);
add_tests((TestRunnerTest(os.path.basename(x)) for x in test_files))
def run_test(test):
sys.stdout.write(" TEST %-35s" % test.name)
sys.stdout.flush()
start = time.time()
try:
test.set_run_py_args(run_py_args)
test.run()
except:
sys.stdout.write("Test %s FAILED\n" % test.name)
sys.stdout.flush()
raise
end = time.time()
duration = end - start
sys.stdout.write(" OK (%.3f s)\n" % duration)
sys.stdout.flush()
def is_not_skipped(test):
return test.name not in blacklist
def run_tests_in_single_instance():
run(filter(lambda test: not isinstance(test, TestRunnerTest), tests))
blacklist_tests = ' '.join(blacklist)
args = run_py_args + ["-s", "-e", "/testrunner.so -b %s" % (blacklist_tests)]
if subprocess.call(["./scripts/run.py"] + args):
exit(1)
def run(tests):
for test in sorted(tests, key=attrgetter('name')):
if is_not_skipped(test):
run_test(test)
else:
sys.stdout.write(" TEST %-35s SKIPPED\n" % test.name)
sys.stdout.flush()
def pluralize(word, count):
if count == 1:
return word
return word + 's'
def make_export_and_conf():
export_dir = tempfile.mkdtemp(prefix='share')
os.chmod(export_dir, 0777)
(conf_fd, conf_path) = tempfile.mkstemp(prefix='export')
conf = os.fdopen(conf_fd, "w")
conf.write("%s 127.0.0.1(insecure,rw)\n" % export_dir)
conf.flush()
conf.close()
return (conf_path, export_dir)
proc = None
def kill_unfsd():
global proc
subprocess.call(["sudo", "kill", str(proc.pid + 1)])
proc.wait()
UNFSD = "./modules/nfs-tests/unfsd.bin"
def run_tests():
global proc
start = time.time()
if cmdargs.nfs:
pass
elif cmdargs.name:
tests_to_run = list((t for t in tests if re.match('^' + cmdargs.name + '$', t.name)))
if not tests_to_run:
print('No test matches: ' + cmdargs.name)
exit(1)
else:
tests_to_run = tests
if cmdargs.nfs:
if not os.path.exists(UNFSD):
print("Please do:\n\tmake nfs-server")
sys.exit(1)
(conf_path, export_dir) = make_export_and_conf()
proc = subprocess.Popen([ "sudo",
os.path.join(os.getcwd(), UNFSD),
"-t",
"-d",
"-s",
"-l", "127.0.0.1",
"-e", conf_path ],
stdin = sys.stdin,
stdout = subprocess.PIPE,
stderr = sys.stderr,
shell = False)
atexit.register(kill_unfsd)
tests_to_run = [ SingleCommandTest('nfs-test',
"/tst-nfs.so --server 192.168.122.1 --share %s" %
export_dir) ]
line = proc.stdout.readline()
while line:
print(line)
if "/tmp" in line:
break
line = proc.stdout.readline()
run(tests_to_run)
kill_unfsd()
elif cmdargs.single:
if tests_to_run != tests:
print('Cannot restrict the set of tests when --single option is used')
exit(1)
run_tests_in_single_instance()
else:
run(tests_to_run)
end = time.time()
duration = end - start
print(("OK (%d %s run, %.3f s)" % (len(tests_to_run), pluralize("test", len(tests_to_run)), duration)))
def main():
while True:
run_tests()
if not cmdargs.repeat:
break
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog='test')
parser.add_argument("-v", "--verbose", action="store_true", help="verbose test output")
parser.add_argument("-r", "--repeat", action="store_true", help="repeat until test fails")
parser.add_argument("-s", "--single", action="store_true", help="run as much tests as possible in a single OSv instance")
parser.add_argument("-n", "--nfs", action="store_true", help="run nfs test in a single OSv instance")
parser.add_argument("--name", action="store", help="run all tests whose names match given regular expression")
parser.add_argument("--run_options", action="store", help="pass extra options to run.py")
cmdargs = parser.parse_args()
set_verbose_output(cmdargs.verbose)
if cmdargs.run_options != None:
run_py_args = cmdargs.run_options.split()
else:
run_py_args = []
main()