-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbenchmark.py
61 lines (50 loc) · 1.72 KB
/
benchmark.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
import argparse
import os
import dangsan
import lowfat
import hextype
import hexvasan
import clang
import typesan
import valgrind
tools = [dangsan, lowfat, hextype, hexvasan, clang.asan, clang.msan,
clang.ubsan, clang.cfi.all, clang.cfi.cast,
clang.cfi.fwdedge, typesan, valgrind.memcheck]
def add_arguments(parser):
subparsers = parser.add_subparsers(dest='command')
for tool in tools:
subparser = subparsers.add_parser(tool.command)
subparser.add_argument('--setup', type=str, choices=tool.configs)
subparser.add_argument('--test', type=str, choices=tool.configs)
subparser.add_argument('--run', type=str, choices=tool.configs)
subparser.add_argument('--clean', type=str, choices=tool.configs)
def parse_arguments(args):
tool = next(tool for tool in tools if tool.command == args.command)
if tool:
if args.setup:
config = args.setup
workdir = '-'.join([args.command, config])
if not os.path.exists(workdir):
os.mkdir(workdir)
os.chdir(workdir)
tool.setup(config)
elif args.test:
config = args.test
workdir = '-'.join([args.command, config])
os.chdir(workdir)
tool.test(config)
elif args.run:
config = args.run
workdir = '-'.join([args.command, config])
os.chdir(workdir)
tool.run(config)
elif args.clean:
if raw_input('are you sure? (y/n)') == 'y':
tool.clean(args.clean)
def main():
parser = argparse.ArgumentParser()
add_arguments(parser)
args = parser.parse_args()
parse_arguments(args)
if __name__ == '__main__':
main()