-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_test.py
executable file
·105 lines (85 loc) · 3.4 KB
/
base_test.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
import os
from typing import Dict, List
from alive_progress import alive_bar
import dace
from dace.sdfg import SDFG
from dace.transformation import dataflow, interstate, subgraph
import fuzzyflow as ff
def _test_from_basedir(datadir: str, category_name: str):
verify_dict = dict()
testdirs = os.listdir(datadir)
bartitle = f'Testing {category_name}'
with alive_bar(len(testdirs), title=bartitle) as bar:
for dir in testdirs:
bar.text(os.path.basename(dir))
# Ignore z_ prefixed directories.
if dir.startswith('z_'):
bar()
continue
valid = True
offending_file = None
print('Verifying', dir)
testdir = os.path.join(datadir, dir)
dbg_save_dir = os.path.join(testdir, 'dbg')
if not os.path.exists(dbg_save_dir):
os.makedirs(dbg_save_dir)
test_sdfgs: Dict[str, SDFG] = dict()
test_files: List[str] = []
for file in os.listdir(testdir):
# Ignore the debug directory.
if file == 'dbg':
continue
if file.endswith('.sdfg'):
sdfg = SDFG.from_file(os.path.join(testdir, file))
sdfg_name = file.split('.')[0]
test_sdfgs[sdfg_name] = sdfg
else:
test_files.append(file)
for sdfg_name, _ in test_sdfgs.items():
for file in test_files:
if file.startswith(sdfg_name):
testfile = os.path.join(testdir, file)
xform, _ = ff.load_transformation_from_file(
testfile, sdfg
)
verifier = ff.TransformationVerifier(
xform, sdfg, ff.CutoutStrategy.SIMPLE
)
valid = valid and verifier.verify(
n_samples=100,
debug_save_path=os.path.join(
dbg_save_dir, file.split('.')[0]
),
enforce_finiteness=True
)
if not valid:
offending_file = file
break
if not valid:
break
if not valid:
print(dir, 'is invalid!')
if offending_file is not None:
print('Offending file is', offending_file)
else:
print(dir, 'verified')
verify_dict[os.path.basename(dir)] = valid
bar()
print('+---------------------------------------+')
print('| Verification completed |')
print('+---------------------------------------+')
row_format = ('| {:<30} {:>5} |')
for k in verify_dict:
print(row_format.format(k, ('🟢' if verify_dict[k] else '❌')))
print('+---------------------------------------+')
def test_multistate():
datadir = './tests/data/multistate'
_test_from_basedir(datadir, 'multistate transformations')
def test_singlestate():
datadir = './tests/data/singlestate'
_test_from_basedir(datadir, 'singlestate transformations')
def main():
test_singlestate()
test_multistate()
if __name__ == '__main__':
main()