-
Notifications
You must be signed in to change notification settings - Fork 0
/
gentest-common.py
executable file
·49 lines (42 loc) · 1.17 KB
/
gentest-common.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
#!/usr/bin/env python3
import os
from random import randint
import sys
progname = 'xxx'
def ew(msg):
sys.stderr.write('%s\n' % msg)
def syscmd(cmd):
ew(cmd)
rc = os.system(cmd)
return rc
def check_rc(rc):
if rc != 0:
ew('Failed running %s' % progname)
sys.exit(rc | (rc >> 8))
def rundiff(fn_in):
fn_out_naive = '%s-auto-naive.out' % progname
fn_out = '%s-auto.out' % progname
rc1 = syscmd('./bin/%s -naive %s %s' % (progname, fn_in, fn_out_naive))
rc2 = syscmd('./bin/%s %s %s' % (progname, fn_in, fn_out))
check_rc(rc1 | rc2)
rcdiff = syscmd('diff %s %s' % (fn_out_naive, fn_out))
if rcdiff != 0:
ew('Inconsistent')
sys.exit(1)
if __name__ == '__main__':
large = False
fn_in = '%s-auto.in' % progname
ai = 1
T = int(sys.argv[ai]); ai += 1
for t in range(T):
ew('Tested %d/%d' % (t, T))
f = open(fn_in, 'w')
f.write('1\n')
f.close()
if large:
fn_out = '%s-auto.out' % progname
rc = syscmd('./bin/%s %s %s' % (progname, fn_in, fn_out))
check_rc(rc)
else:
rundiff(fn_in)
sys.exit(0)