-
Notifications
You must be signed in to change notification settings - Fork 247
/
test_edalizer.py
236 lines (195 loc) · 6.49 KB
/
test_edalizer.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Copyright FuseSoC contributors
# Licensed under the 2-Clause BSD License, see LICENSE for details.
# SPDX-License-Identifier: BSD-2-Clause
def test_apply_filters(caplog):
import logging
from fusesoc.edalizer import Edalizer
input_edam = {
"files": [
{"name": "qip_file.qip", "file_type": "QIP"},
{"name": "sv_file.sv"},
{"name": "tcl_file.tcl"},
{"name": "vlog_file.v"},
{"name": "vlog05_file.v", "file_type": "verilogSource-2005"},
{"name": "vlog_incfile.v", "is_include_file": True},
],
"filters": ["autotype"],
}
ref_edam = {
"files": [
{"name": "qip_file.qip", "file_type": "QIP"},
{"name": "sv_file.sv", "file_type": "systemVerilogSource"},
{"name": "tcl_file.tcl", "file_type": "tclSource"},
{"name": "vlog_file.v", "file_type": "verilogSource"},
{"name": "vlog05_file.v", "file_type": "verilogSource-2005"},
{
"name": "vlog_incfile.v",
"file_type": "verilogSource",
"is_include_file": True,
},
],
"filters": ["autotype"],
}
# Filter from core
edalizer = Edalizer(
toplevel=None,
flags=None,
work_root=None,
core_manager=None,
)
edalizer.edam = input_edam
edalizer.apply_filters([])
assert edalizer.edam == ref_edam
# No filters
edalizer.edam = {}
edalizer.apply_filters([])
assert edalizer.edam == {}
# Non-existent filter
edalizer.edam = {}
with caplog.at_level(logging.WARNING):
edalizer.apply_filters(["doesnotexist"])
assert "Ignoring unknown EDAM filter 'doesnotexist'" in caplog.text
assert edalizer.edam == {}
def test_tool_or_flow():
import os
from fusesoc.config import Config
from fusesoc.coremanager import CoreManager
from fusesoc.edalizer import Edalizer
from fusesoc.librarymanager import Library
from fusesoc.vlnv import Vlnv
tests_dir = os.path.dirname(__file__)
cores_dir = os.path.join(tests_dir, "capi2_cores", "misc")
lib = Library("edalizer", cores_dir)
cm = CoreManager(Config())
cm.add_library(lib, [])
core = cm.get_core(Vlnv("::flow"))
ref_edam = {
"version": "0.2.1",
"dependencies": {"::flow:0": []},
"files": [],
"filters": [],
"hooks": {},
"name": "flow_0",
"parameters": {},
"toplevel": "unused",
"vpi": [],
"flow_options": {},
}
edam = Edalizer(
toplevel=core.name,
flags={"target": "nothing"},
core_manager=cm,
work_root=".",
).run()
assert edam == ref_edam
edam = Edalizer(
toplevel=core.name,
flags={"target": "flowonly"},
core_manager=cm,
work_root=".",
).run()
assert edam == ref_edam
edam = Edalizer(
toplevel=core.name,
flags={"target": "emptyflowoptions"},
core_manager=cm,
work_root=".",
).run()
assert edam == ref_edam
edam = Edalizer(
toplevel=core.name,
flags={"target": "toolonly"},
core_manager=cm,
work_root=".",
).run()
assert edam == ref_edam
edam = Edalizer(
toplevel=core.name,
flags={"target": "flowandtool"},
core_manager=cm,
work_root=".",
).run()
assert edam == ref_edam
edam = Edalizer(
toplevel=core.name,
flags={"target": "flowoptions"},
core_manager=cm,
work_root=".",
).run()
ref_edam["flow_options"] = {
"tool1": {"someoption": "somevalue"},
"tool2": {"otheroption": ["detroit", 442]},
}
assert edam == ref_edam
def test_generators():
import os
import shutil
import tempfile
from fusesoc.config import Config
from fusesoc.coremanager import CoreManager
from fusesoc.edalizer import Edalizer
from fusesoc.librarymanager import Library
from fusesoc.vlnv import Vlnv
tests_dir = os.path.dirname(__file__)
cores_dir = os.path.join(tests_dir, "capi2_cores", "misc", "generate")
lib = Library("edalizer", cores_dir)
cm = CoreManager(Config())
cm.add_library(lib, [])
core = cm.get_core(Vlnv("::generate"))
build_root = tempfile.mkdtemp(prefix="export_")
export_root = os.path.join(build_root, "exported_files")
edalizer = Edalizer(
toplevel=core.name,
flags={"tool": "icarus"},
core_manager=cm,
work_root=os.path.join(build_root, "work"),
export_root=export_root,
system_name=None,
)
edalizer.run()
ref_edam = {
"version": "0.2.1",
"name": "generate_0",
"toplevel": "na",
"dependencies": {
"::generators:0": [],
"::generate:0": [
"::generators:0",
"::generate-testgenerate_without_params:0",
"::generate-testgenerate_with_params:0",
"::generate-testgenerate_with_override:0",
"::generate-testgenerate_with_cache:0",
],
"::generate-testgenerate_without_params:0": [],
"::generate-testgenerate_with_params:0": [],
"::generate-testgenerate_with_override:0": [],
"::generate-testgenerate_with_cache:0": [],
},
"parameters": {"p": {"datatype": "str", "paramtype": "vlogparam"}},
"tool_options": {"icarus": {}},
"flow_options": {},
"hooks": {},
"files": [],
"filters": [],
"vpi": [],
}
assert ref_edam == edalizer.edam
edalizer.export()
name_to_core = {str(core.name): core for core in edalizer.cores}
for flavour in ["testgenerate_with_params", "testgenerate_without_params"]:
core_name = f"::generate-{flavour}:0"
assert core_name in name_to_core
core = name_to_core[core_name]
# ttptttg temporary directory should be removed by now
assert not os.path.isdir(core.core_root)
# Test generator input cache and file_input_params
core_name = f"::generate-testgenerate_with_cache:0"
assert core_name in name_to_core
core = name_to_core[core_name]
assert os.path.isdir(core.core_root)
hash = ""
with open(os.path.join(core.core_root, ".fusesoc_file_input_hash")) as f:
hash = f.read()
# SHA256 hash of test file content
assert hash == "da265f9dccc9d9e64d059f677508f9550b403c99e6ce5df07c6fb1d711d0ee99"
shutil.rmtree(core.core_root, ignore_errors=True)