-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.py
executable file
·61 lines (59 loc) · 3.07 KB
/
run_tests.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
#!/usr/bin/env python3
import subprocess, csv, os.path, sys, re, random, glob
from random import randrange
random.seed()
re_time = re.compile('^time (ours|naive): ((?:\\d)+)μs$', flags=re.MULTILINE)
re_max_genes = re.compile('^max_gene: ((?:\\d)+)$', flags=re.MULTILINE)
n_form = 10
mat_dir = 'mats'
results_existed = os.path.exists('results.csv')
with open('results.csv', 'a+', newline='') as ofile:
writer = csv.DictWriter(ofile, ['mat file', 'num clauses', 'max literals',
'max genes', 'not probability',
'our time', 'naive time'])
if not results_existed:
writer.writeheader()
for i in range(20):
fields = {'num clauses': 1 + randrange(80),
'max literals': 1 + randrange(80),
'max genes': random.choice([None, randrange(80, 23000, 1)]),
# miniumum number of genes because duplicate genes are pointless
'not probability': random.uniform(0.0, 1.0)}
for mat in map(os.path.basename, glob.iglob(os.path.join(mat_dir, '*.mat'))):
fields['mat file'] = os.path.splitext(mat)[0]
form_file = os.path.join('forms',
''.join([os.path.splitext(mat)[0], '_',
str(i), '.txt']))
cmd = [os.path.join('.', 'formula'), os.path.join(mat_dir, mat),
'-o', form_file, '-n', str(10),
'-c', str(fields['num clauses']),
'-p', str(fields['not probability']),
'-l', str(fields['max literals'])]
if fields['max genes']:
cmd.extend(['-g', str(fields['max genes'])])
res = subprocess.run(cmd, capture_output=True)
print(res.stdout.decode())
if res.returncode:
print(cmd)
print(f'{res.returncode} when generating formula for {mat}',
file=sys.stderr)
print(res.stderr.decode(), file=sys.stderr)
else:
fields['max genes'] = int(re_max_genes.search(res.stdout.decode())[1])
cmd = [os.path.join('.', 'test'), 'query', form_file,
os.path.join(mat_dir, mat)]
res = subprocess.run(cmd, capture_output=True)
if res.returncode:
print(f'Error {res.returncode} when testing {mat}',
file=sys.stderr)
print(res.stderr.decode(), file=sys.stderr)
else:
print(res.stdout.decode())
matches = re_time.findall(res.stdout.decode())
print(matches)
if len(matches) == 2:
fields['our time'] = matches[0][1]
fields['naive time'] = matches[1][1]
writer.writerow(fields)
else:
print(f'Expected 2, got {len(matches)}')