forked from antmicro/verilator-verification-features-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-tests
executable file
·116 lines (93 loc) · 3.79 KB
/
gen-tests
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
111
112
113
114
115
116
#!/usr/bin/env python3
from jinja2 import Template
import os
import sys
import yaml
repo_dir = os.path.dirname(sys.argv[0])
tmpl_dir = f'{repo_dir}/templates'
test_dir = f'{repo_dir}/tests'
with open(f'{tmpl_dir}/suite.robot', 'r') as t:
suite_tmpl = Template(t.read())
with open(f'{tmpl_dir}/default.robot', 'r') as t:
default_tmpl = Template(t.read())
branch_filter = sys.argv[1:]
def skip_branch(branch):
return len(branch_filter) > 0 and branch not in branch_filter
def skip_suite(suite):
return suite in ["unsupported-signal-strengths", "functional-coverage"]
def new_section():
print('==============================================================================')
class Test:
def __init__(self, suite, name, tmpl, branch):
self.suite = suite
self.name = name
self.tmpl = tmpl
self.root = f'{repo_dir}/verilator/{branch}'
self.tags = [f"Branch: '{branch}'"]
def render(self):
return self.tmpl.render(verilator_root=self.root, suite=self.suite, test=self.name, tags=' '.join(self.tags))
def makedirs(self):
os.makedirs(f'out/{self.suite}/{self.name}', exist_ok=True)
default_branch = None
suite_to_branch = {}
with open('branches.yml', 'r') as f:
for branch, suites in yaml.safe_load(f).items():
for suite in suites:
if suite == 'default':
assert default_branch == None, 'Multiple default branches'
default_branch = branch
else:
suite_to_branch[suite] = branch
suites = {}
for suite_name in os.listdir(test_dir):
if skip_suite(suite_name): continue
suite_dir = f'{test_dir}/{suite_name}'
if suite_name == "uvm-tests":
test_list = ["uvm_sequence", "uvm_resource_db", "uvm_test_run_test"]
class_list = ["uvm_agent", "uvm_component", "uvm_driver", "uvm_env",
"uvm_monitor", "uvm_scoreboard", "uvm_sequencer", "uvm_test"]
test_list = test_list + [complexity + "_" + class_name for class_name in class_list
for complexity in ["simple", "complex"]]
else:
test_list = os.listdir(suite_dir)
for test_name in test_list:
# Get branch for this test
try:
branch = suite_to_branch[suite_name]
except KeyError:
branch = default_branch
if skip_branch(branch): continue
# Load suite template or use default
template = default_tmpl
tmpl_path = f'{tmpl_dir}/{suite_name}.robot'
if os.path.exists(tmpl_path):
with open(tmpl_path, 'r') as t:
template = Template(t.read())
# Lazily create suite dict
if suite_name not in suites:
suite = suites[suite_name] = {}
# Finally, create test
print(f"Adding test '{suite_name}/{test_name}' (branch: '{branch}'",
f", template: '{tmpl_path}'" if template != default_tmpl else "", ")", sep="")
suite[test_name] = Test(suite_name, test_name, template, branch)
new_section()
with open('tags.yml', 'r') as f:
for tag, suite_to_test in yaml.safe_load(f).items():
for suite_name, test_names in suite_to_test.items():
try:
suite = suites[suite_name]
print(f"Tagging with '{tag}' in suite '{suite_name}': {', '.join(test_names)}")
for test_name in test_names:
test = suite[test_name]
test.tags.append(tag)
except KeyError: pass
new_section()
print('Generating suites:')
for suite_name, suite in suites.items():
print(f' - {suite_name}')
tests = []
for test in suite.values():
tests.append(test.render())
test.makedirs()
with open(f'{suite_name}.robot', 'w') as t:
t.write(suite_tmpl.render(test_cases='\n'.join(tests)))