-
Notifications
You must be signed in to change notification settings - Fork 0
/
hwb_run.py
57 lines (48 loc) · 1.23 KB
/
hwb_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
# multithreaded run with timeout
import os
import glob
import json
import shlex
from subprocess import call, TimeoutExpired
import threading
import queue
# 20 seconds
TIMEOUT = 20
q = queue.Queue()
os.chdir('/build')
filenames = [filename.split('.')[0] for filename in glob.glob('*.asm')]
print('processing {} files'.format(len(filenames)))
def run_command(filename):
if os.path.isfile(filename+'.output'):
return
cmd = 'gdb {0} -batch -ex "set logging file {0}.output" -ex "set logging on" -ex r -ex "bt full" -ex "info registers" -ex quit'.format(filename)
cmd = shlex.split(cmd)
data = {
'timeout_time': TIMEOUT,
'timeout_hit': False
}
try:
call(cmd, timeout=TIMEOUT)
except TimeoutExpired:
data['timeout_hit'] = True
with open(filename+'.timeout.json', 'w') as f:
f.write(json.dumps(data))
def worker():
while True:
item = q.get()
if item is None:
break
run_command(item)
q.task_done()
threads = []
for i in range(10):
t = threading.Thread(target=worker)
t.start()
threads.append(t)
for filename in filenames:
q.put(filename)
q.join()
for i in range(2):
q.put(None)
for t in threads:
t.join()