-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner.py
75 lines (64 loc) · 2.27 KB
/
runner.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
from typing import List
import uuid
from os import chdir
import logging
import json
from .cmd import cmd
from .storage import put_object
from shlex import quote, split
from timeit import default_timer as timer
def run_benchmark(args: dict):
job_id = str(uuid.uuid4())
logging.info('Running benchmark {}'.format(job_id))
chdir('projects/{}'.format(quote(args.project)))
# FIXME use filterFunctions
# for fun in get_functions():
# if fun.startswith(args.test) == False:
# # https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux
# # NOTE: this only works on GNU sed
# cmd("find test -type f -exec sed -i -e 's/\(" +
# fun + "\\b.*\)public/\\1private/' \{\} \;")
output_filename = '{}-output.json'.format(job_id)
output = ''
with open(output_filename, 'a+') as f:
f.close()
tool_cmd = 'timeout -k 10 {} {}'.format(args.timeout, args.extra_args)
if args.preprocess != '':
cmd(args.preprocess)
start_time = timer()
status, stdout, stderr = cmd(split(quote(tool_cmd)))
end_time = timer()
with open(output_filename) as f:
output = f.read()
f.close()
result = {
'job_id': job_id,
'tool': args.tool,
'project': args.project,
'test': args.test,
'preprocess': args.preprocess,
'postprocess': args.postprocess,
'extra_args': args.extra_args,
'tool_cmd': tool_cmd,
'mutant': args.mutant,
'time': end_time - start_time,
'status': status,
'output': output,
'stdout': stdout,
'stderr': stderr,
}
if args.postprocess != '':
cmd(args.postprocess)
put_object('{}{}.json'.format(args.prefix, job_id),
json.dumps(result), args.local)
logging.info("Done")
def get_contract(test: str) -> str:
logging.info('Getting contract for test {}'.format(test))
status, stdout, stderr = cmd(
"grep -r -l {} test | sed 's/.*\/\(.*\)\.t\.sol/\\1/g'".format(quote(test)))
return stdout
def get_functions() -> List[str]:
logging.info('Getting functions')
status, stdout, stderr = cmd(
"grep -ro 'test_[a-zA-Z0-9_]*' test | sed 's/.*://g'")
return stdout.split('\n')