-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·48 lines (43 loc) · 1.8 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
#!/usr/bin/env python3
import sys
import os
import argparse
import subprocess
def create_argparser():
parser = argparse.ArgumentParser(
description="Stress tests",
epilog="By @renbou with <3",
)
parser.add_argument("task", help="Which task to test",
choices=["wordnet", "2d-tree", "8-puzzle", "genome-assembly"])
parser.add_argument("sources", help="Path to source directory")
parser.add_argument("includes", help="Path to include directory")
parser.add_argument("-print", help="Print tests", default=False, action='store_true')
parser.add_argument("-rebuild", default=False, action='store_true',
help="Rebuild the image if an update is needed")
return parser
def run_with_stdout(cmd):
process = subprocess.run(
cmd,
stdout=sys.stdout,
stderr=subprocess.STDOUT,
shell=True
)
return process.returncode
def main(args):
for name in ["sources", "includes"]:
setattr(args, name, os.path.realpath(getattr(args, name)))
if not os.path.exists(getattr(args, name)):
print("Path to {} ({}) does not exist".format(name, getattr(args, name)))
sys.exit(1)
if args.rebuild:
run_with_stdout("docker image rm strezdout:1.0")
if args.rebuild or b'strezdout' not in \
subprocess.check_output("docker images --filter reference='strezdout:1.0'", shell=True):
run_with_stdout("docker build . --tag strezdout:1.0")
run_with_stdout("docker run -ti --volume {}:/src --volume {}:/include --rm strezdout:1.0 {} {}"
.format(args.sources, args.includes, args.task,
("printtests" if args.print else "lol")))
if __name__ == '__main__':
argparser = create_argparser()
main(argparser.parse_args())