forked from emichael/dslabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.py
executable file
·343 lines (266 loc) · 11.3 KB
/
run-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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/usr/bin/env python3
"""Runs JUnit tests with given options."""
import argparse
import platform
import shutil
import subprocess
import sys
__author__ = 'Ellis Michael (emichael@cs.washington.edu)'
RUNNER = 'dslabs.framework.testing.junit.DSLabsTestCore'
VIZ_DEBUGGER = 'dslabs.framework.testing.visualization.VizClient'
TRACE_VIZ = 'dslabs.framework.testing.visualization.SavedTraceViz'
EXCLUDE_FILTER = 'org.junit.experimental.categories.ExcludeCategories'
RUN_CATEGORY = 'dslabs.framework.testing.junit.RunTests'
SEARCH_CATEGORY = 'dslabs.framework.testing.junit.SearchTests'
BASE_COMMAND = (
'java',
'--add-opens', 'java.base/jdk.internal.reflect=ALL-UNNAMED',
'--add-opens', 'java.base/java.lang=ALL-UNNAMED',
'--add-opens', 'java.base/java.util=ALL-UNNAMED',
'--add-opens', 'java.base/java.util.concurrent.atomic=ALL-UNNAMED',
'--add-opens', 'java.base/java.time=ALL-UNNAMED',
)
if platform.system() == 'Windows':
CP_SEP = ';'
else:
CP_SEP = ':'
RUNTIME_CLASSPATH = CP_SEP.join((
'jars/framework.jar',
'jars/framework-deps.jar',
'jars/grader.jar',
'jars/grader-deps.jar',
'out/src/',
'out/tst/'
))
def make():
"""Compile the source files, exit script if unsuccessful."""
try:
subprocess.check_output(['make'], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as ex:
print("Could not compile sources.\n")
print(ex.output.decode("utf-8"))
shutil.rmtree('out')
sys.exit(3)
def run_tests(lab, part=None, no_run=False, no_search=False,
timers_disabled=False, log_level=None, single_threaded=False,
start_viz=False, do_checks=False, test_num=None, assertions=False,
save_traces=False, jvm_properties=None):
"""Run the specified tests."""
make()
command = list(BASE_COMMAND)
if assertions:
command.append('-ea')
if timers_disabled:
command.append('-DtestTimeoutsDisabled=true')
if log_level:
command.append('-DlogLevel=%s' % log_level)
if single_threaded:
command.append('-DsingleThreaded=true')
if start_viz:
command.append('-DstartViz=true')
if do_checks:
command.append('-DdoChecks=true')
if save_traces:
command.append('-DsaveTraces=true')
if jvm_properties is not None:
for prop in jvm_properties:
command.append(f'-D{prop}')
command += [
'-cp',
RUNTIME_CLASSPATH,
RUNNER
]
command += ['--lab', str(lab)]
if part is not None:
command += ['--part', str(part)]
if no_run:
command.append('--exclude-run-tests')
if no_search:
command.append('--exclude-search-tests')
if test_num:
command += ['--test-num', str(test_num)]
returncode = subprocess.call(command)
sys.exit(returncode)
def run_viz_debugger(lab, args, assertions=False, jvm_properties=None):
"""Start the visual debugger."""
make()
command = list(BASE_COMMAND)
if assertions:
command.append('-ea')
if jvm_properties is not None:
for prop in jvm_properties:
command.append(f'-D{prop}')
command += [
'-cp',
RUNTIME_CLASSPATH,
VIZ_DEBUGGER
]
command += ['--lab', str(lab)]
command += args
returncode = subprocess.call(command)
sys.exit(returncode)
def visualize_trace(trace_name, assertions=False, jvm_properties=None):
"""Visualize a trace."""
make()
command = list(BASE_COMMAND)
if assertions:
command.append('-ea')
if jvm_properties is not None:
for prop in jvm_properties:
command.append(f'-D{prop}')
command += [
'-cp',
RUNTIME_CLASSPATH,
TRACE_VIZ,
trace_name
]
returncode = subprocess.call(command)
sys.exit(returncode)
def replay_traces(trace_names=None, lab=None, part=None, log_level=None,
start_viz=False, do_checks=False, assertions=False,
jvm_properties=None):
"""Replay traces."""
make()
command = list(BASE_COMMAND)
if assertions:
command.append('-ea')
if log_level:
command.append('-DlogLevel=%s' % log_level)
if start_viz:
command.append('-DstartViz=true')
if do_checks:
command.append('-DdoChecks=true')
if jvm_properties is not None:
for prop in jvm_properties:
command.append(f'-D{prop}')
command += [
'-cp',
RUNTIME_CLASSPATH,
RUNNER,
'--replay-traces'
]
if lab is not None:
command += ['--lab', lab]
if part is not None:
command += ['--part', str(part)]
if trace_names:
command += trace_names
returncode = subprocess.call(command)
sys.exit(returncode)
def main():
"""Parse args and run tests."""
parser = argparse.ArgumentParser()
run_modes = parser.add_argument_group("Alternate run modes",
"Execute one of the following options instead of running tests.")
group = run_modes.add_mutually_exclusive_group()
parser.add_argument('-l', '--lab', help="lab to run tests for")
parser.add_argument('-p', '--part',
help="part number(s) to run tests for (comma-separated)")
parser.add_argument('-n', '--test-num',
help="specific, comma-separated test numbers to run "
"(e.g., 2,5,7 or 2.2,2.5,2.7)")
parser.add_argument('--no-run', action='store_true',
help="do not execute run tests")
parser.add_argument('--no-search', action='store_true',
help="do not execute search tests")
parser.add_argument('--checks', action='store_true',
help="run checks on equals, hashCode, idempotence of "
"handlers, etc. when running tests")
parser.add_argument('--no-timeouts', action='store_true',
help="stop tests from timing out")
parser.add_argument('-g', '--log-level',
help="level the default Java util logging should use")
parser.add_argument('-ea', '--assertions', action='store_true',
help="enable Java assertions")
parser.add_argument('--single-threaded', action='store_true',
help="run the tests using only a single thread")
parser.add_argument('-s', '--save-traces', action='store_true',
help="save traces after search test failure")
parser.add_argument('-z', '--start-viz', action='store_true',
help="start the visualization on invariant violation "
"or when the search is unable to find a "
"particular state")
group.add_argument('-d', '--debugger', nargs='*', metavar="ARG",
help="Don't run any tests, instead start the visual "
"debugger with the given args. By default, the args "
"should be: NUM_SERVERS NUM_CLIENTS WORKLOAD where "
"WORKLOAD is a comma-separated list of commands (e.g., "
"PUT:foo:bar,APPEND:foo:baz,GET:foo in the default "
"case of the KVStore); with these arguments, all "
"clients request the same workload. To give different "
"workloads for each client, the args should be: "
"NUM_SERVERS NUM_CLIENTS WORKLOAD_1 WORKLOAD_2 ... "
"WORKLOAD_NUM_CLIENTS where each WORLOAD_i is a "
"comma-separated list of commands and a workload is "
"provided for each client.")
group.add_argument('--replay-traces', nargs='*', default=None,
metavar="TRACE_NAME",
help="Replay and recheck saved traces. Can specify "
"--lab and --part to restrict which traces to run or "
"supply one or more filenames of specific traces.")
group.add_argument('--visualize-trace', metavar="TRACE_NAME",
help="immediately start the visual debugger with the "
"specified trace, regardless of whether it still causes "
"an invariant violation")
parser.add_argument('-D', action="append", type=str,
metavar="PROPERTY=VALUE", dest="jvm_properties",
help="command-line property to pass to the JVM, can be "
"repeated (e.g. -Dfoo=val1 -Dbar=val2)")
args = parser.parse_args()
def disallow_arguments(current_option, disallowed_options):
for option in disallowed_options:
arg_name = option.split('/')[-1].lstrip('-').replace('-', '_')
if getattr(args, arg_name):
parser.error(
f"argument {option} not allowed with argument "
f"{current_option}")
if args.debugger:
if args.lab is None:
parser.error("-l/--lab is required with -d/--debugger")
disallow_arguments('-d/--debugger',
('-p/--part', '--checks', '-n/--test-num', '--no-run',
'--no-search', '--no-timeouts', '-g/--log-level',
'--single-threaded', '-s/--save-traces', '-z/--start-viz'))
run_viz_debugger(args.lab, args.debugger, assertions=args.assertions,
jvm_properties=args.jvm_properties)
elif args.replay_traces is not None:
if args.part is not None and args.lab is None:
parser.error("cannot specify -p/--part without -l/--lab")
if args.lab is not None and args.replay_traces:
parser.error("cannot specify both -l/--lab and TRACE_NAME")
disallow_arguments('--replay-traces',
('-n/--test-num', '--no-run', '--no-search', '--no-timeouts',
'--single-threaded', '-s/--save-traces'))
replay_traces(trace_names=args.replay_traces,
lab=args.lab,
part=args.part,
log_level=args.log_level,
start_viz=args.start_viz,
do_checks=args.checks,
assertions=args.assertions,
jvm_properties=args.jvm_properties)
elif args.visualize_trace is not None:
disallow_arguments('--visualize-trace',
('-l/--lab', '-p/--part', '--checks', '-n/--test-num', '--no-run',
'--no-search', '--no-timeouts', '-g/--log-level',
'--single-threaded', '-s/--save-traces', '-z/--start-viz'))
visualize_trace(args.visualize_trace, assertions=args.assertions,
jvm_properties=args.jvm_properties)
else:
if args.lab is None:
parser.error("-l/--lab is required")
run_tests(args.lab,
part=args.part,
no_run=args.no_run,
no_search=args.no_search,
timers_disabled=args.no_timeouts,
log_level=args.log_level,
single_threaded=args.single_threaded,
start_viz=args.start_viz,
do_checks=args.checks,
test_num=args.test_num,
assertions=args.assertions,
save_traces=args.save_traces,
jvm_properties=args.jvm_properties)
if __name__ == '__main__':
main()