-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·144 lines (123 loc) · 3.74 KB
/
run.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
#!/usr/bin/env python3
import os
import sys
import csv
import glob
import time
import json
import logging
import resource
import threading
import subprocess
# constants ------------------------------------------------
THREADS=1
TIMEOUT=900
INSTR_MAX=4000000000000000000
# globals --------------------------------------------------
dirs = glob.glob(f'_build/tests')
table = [['test', 'spec', 'Twasp', 'Tloop', 'Tsolver', 'paths', 'Cov']]
errors = list()
# helpers --------------------------------------------------
cmd = lambda p, r : [
'wasp',
p,
'-e',
f'(invoke \"__original_main\")',
'-b',
'-m',
str(INSTR_MAX),
'--workspace', r,
'--smt-assume'
]
def limit_ram() -> None:
limit = 15 * 1024 * 1024 * 1024
resource.setrlimit(resource.RLIMIT_AS, (limit, limit))
def run(test: str, out_dir: str):
try:
out = subprocess.check_output(
cmd(test, out_dir),
timeout=TIMEOUT,
stderr=subprocess.STDOUT,
preexec_fn=limit_ram
)
except (subprocess.CalledProcessError, \
subprocess.TimeoutExpired) as e:
logging.error('crashed')
return None
return out
#-----------------------------------------------------------
# main -----------------------------------------------------
fmt = '%(asctime)s: %(message)s'
date_fmt = '%H:%M:%S'
logging.basicConfig(format=fmt, level=logging.INFO, \
datefmt=date_fmt)
def main(argv):
tests = []
lock = threading.Lock()
def run_benchmark(test):
out_dir = os.path.join('output', os.path.basename(test))
t0 = time.time()
run(test, out_dir)
delta = time.time() - t0
report_file = os.path.join(out_dir, 'report.json')
if not os.path.exists(report_file):
lock.acquire()
errors.append(test)
lock.release()
logging.info(f'Crashed/Timeout {os.path.basename(test)}')
return
with open(report_file, 'r') as f:
try:
report = json.load(f)
except json.decoder.JSONDecodeError:
logging.info(f'Thread {i}: Can not read report \'{report_file}\'.')
return
if not report['specification']:
lock.acquire()
errors.append(test)
lock.release()
logging.info(f'Test {os.path.basename(test)} ' \
f'({report["specification"]}, ' \
f'T={round(delta,2)}s, L={float(report["loop_time"])}, S={float(report["solver_time"])}' \
f'{report["paths_explored"]})')
lock.acquire()
table.append([
f'{test}',
report['specification'],
round(delta, 2),
float(report['loop_time']),
float(report['solver_time']),
report['paths_explored'],
report['coverage']
])
lock.release()
def t_loop(i):
while True:
try:
lock.acquire()
test = tests.pop()
except IndexError:
break
finally:
lock.release()
run_benchmark(test)
if argv == []:
for dir in dirs:
tests = tests + glob.glob(f'{dir}/*.wat')
else:
tests = argv
threads = []
for i in range(THREADS):
t = threading.Thread(target=t_loop, args=(i,))
threads.append(t)
t.start()
for t in threads:
t.join()
with open('table.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerows(table)
for err in errors:
logging.info('Failed Test: ' + err)
if __name__ == '__main__':
main(sys.argv[1:])
#-----------------------------------------------------------