forked from CaneRig/Guitar-Processor-FPGA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
110 lines (93 loc) · 2.76 KB
/
run.py
File metadata and controls
110 lines (93 loc) · 2.76 KB
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
import os
import argparse
from pathlib import Path
import shutil
from cocotb.runner import get_runner
proj_path = Path(__file__).resolve().parent
cocotb_tests_path = proj_path / 'sim' / 'cocotb'
def load_test_names() -> dict[str, str]:
test_path = proj_path / 'sim' / 'cocotb'
this_tests = test_path.glob('*/dut.sv')
return dict(map(lambda x: (str(x.parent.name), x), this_tests))
def run_test(dut_path: str, testname = '$undefined$', waves=True, gui=True):
sim = os.getenv("SIM", "icarus")
# sim = os.getenv("SIM", "questa") #modelsim
rtl_path = proj_path/'rtl'
incl_path = proj_path/'common'
build_path = proj_path/'test'
test_dir = Path(dut_path).parent
sources = [
*rtl_path.glob('utility/**/*.sv'),
*rtl_path.glob('effects/**/*.sv'),
*rtl_path.glob('generated/**/*.sv'),
]
sources = list(map(lambda x: str(x), sources))
sources.append(dut_path)
headers = [
incl_path,
]
runner = get_runner(sim)
runner.build(
verilog_sources=sources,
includes=headers,
hdl_toplevel="dut",
always=True,
build_dir=build_path
)
print(f'----------------TESTING: {testname}')
runner.test(hdl_toplevel="dut", test_module="tester", waves=waves, gui=gui, test_dir=test_dir)
def list_tests():
tests = load_test_names().keys()
print('Avalible tests: ')
for i in tests:
print('-\t', i)
def clear():
cache_files = [
*cocotb_tests_path.glob('*/dump.fst'),
*cocotb_tests_path.glob('*/results.xml')
]
cache_dirs = [
*cocotb_tests_path.glob('*/__pycache__')
]
for file in cache_files:
print('Removing:', file)
os.remove(file)
for dire in cache_dirs:
print('Removing:', dire)
shutil.rmtree(dire)
print('Removed', len(cache_files), 'files,', len(cache_dirs), 'directories')
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
'-l', '--list',
action='store_true'
)
parser.add_argument(
'-ta', '--testall',
action='store_true'
)
parser.add_argument(
'-t', '--test',
default=None
)
parser.add_argument(
'--clear',
action='store_true'
)
args = parser.parse_args()
if args.clear:
clear()
exit()
elif args.list:
list_tests()
exit()
elif args.testall:
tests = load_test_names()
for i in tests:
run_test(tests[i])
exit()
elif args.test != None:
tests = load_test_names()
run_test(tests[args.test])
exit()
print('Nothing to do')