Skip to content

Commit 428d8c3

Browse files
committed
Refactor to better support extensions of VHDL configurations.
1 parent ad8dbf2 commit 428d8c3

18 files changed

Lines changed: 170 additions & 67 deletions

File tree

docs/py/vunit.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ Test
3030

3131
.. autoclass:: vunit.ui.test.Test()
3232

33+
ConfigurationList
34+
-----------------
35+
36+
.. autoclass:: vunit.ui.configuration.ConfigurationList()
37+
:special-members: __iter__
38+
:inherited-members:
39+
40+
3341
Configuration
3442
-------------
3543

examples/vhdl/vhdl_configuration/run.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,30 @@
1919
# VHDL configurations are detected automatically and are treated as a special
2020
# case of the broader VUnit configuration concept. As such the configuration
2121
# can be extended beyond the capabilities of a pure VHDL configuration. For example,
22-
# by adding a post_check function. The exception is generics since VHDL doesn't allow
23-
# generics to be combined with configurations. Workarounds for this limitation can be
24-
# found in the handling_generics_limitation directory
22+
# by adding a pre_config or post_check function hooks. The exception is generics since VHDL
23+
# doesn't allow generics to be combined with configurations.
24+
# Workarounds for this limitation can be found in the handling_generics_limitation directory
2525

2626
# Get the VHDL-defined configurations from test or testbench objects using a pattern matching
2727
# configurations of interest.
2828
tb = lib.test_bench("tb_selecting_dut_with_vhdl_configuration")
29-
configurations = tb.get_configs("dff_*")
29+
configs = tb.get_configs("dff_*")
3030

3131
# Remember to run the run script with the -v flag to see the message from the dummy post_check
32-
def post_check(output_path):
33-
print("Running post-check")
32+
def make_hook(msg):
33+
def hook(output_path):
34+
print(msg)
3435

35-
return True
36+
return True
3637

38+
return hook
3739

38-
configurations.set_post_check(post_check)
40+
41+
configs.set_post_check(make_hook("Common post_check"))
42+
43+
# You can also loop over the matching configurations
44+
for config in configs:
45+
config.set_pre_config(make_hook(f"pre_config for {config.name}"))
3946

4047
# The testbenches in the handling_generics_limitation directory are examples of how the generics
4148
# limitation of VHDL configurations can be worked around. This allow us to create configurations

tests/acceptance/artificial/vhdl/run.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ def post_check(output_path):
9696
tb = ui.library("lib").test_bench("tb_with_vhdl_configuration")
9797
tb.get_configs("cfg*").set_post_check(make_post_check("arch1"))
9898
tb.test("test1").get_configs("cfg2").set_post_check(make_post_check("arch2"))
99-
tb.test("test2").get_configs("cfg2").set_post_check(make_post_check("arch2"))
99+
for config in tb.test("test2").get_configs():
100+
if config.name == "cfg2":
101+
config.set_post_check(make_post_check("arch2"))
102+
tb.test("test1").delete_config("cfg1")
103+
tb.add_config("foo")
104+
tb.delete_config("foo")
100105

101106

102107
configure_tb_with_generic_config()

tests/acceptance/test_artificial.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,6 @@ def test_exit_0_flag(self):
245245
"failed",
246246
"lib.tb_assert_stop_level.Report failure when VHDL assert stop level = failure",
247247
),
248-
(
249-
"passed",
250-
"lib.tb_with_vhdl_configuration.cfg1.test1",
251-
),
252248
(
253249
"passed",
254250
"lib.tb_with_vhdl_configuration.cfg1.test2",

tests/unit/test_configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def test_error_on_setting_illegal_value_sim_option(self):
4646
self.assertRaises(ValueError, config.set_sim_option, "vhdl_assert_stop_level", "illegal")
4747

4848
def test_error_on_both_generics_and_vhdl_configuration(self):
49-
with _create_config(vhdl_configuration_name="cfg") as config:
49+
with _create_config(vhdl_config_name="cfg") as config:
5050
self.assertRaises(GenericAndVHDLConfigurationException, config.set_generic, "foo", "bar")
5151

5252
with _create_config(generics=dict(foo=17)) as config:
53-
self.assertRaises(GenericAndVHDLConfigurationException, config.set_vhdl_configuration_name, "bar")
53+
self.assertRaises(GenericAndVHDLConfigurationException, config.set_vhdl_config_name, "bar")
5454

5555
def test_sim_option_is_not_mutated(self):
5656
with _create_config() as config:

tests/unit/test_incisive_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ def test_configuration_and_entity_selection(self, find_cds_root_irun, find_cds_r
967967
with create_tempdir() as tempdir:
968968
design_unit = Entity("tb_entity", file_name=str(Path(tempdir) / "file.vhd"))
969969
design_unit.generic_names = ["runner_cfg"]
970-
config = Configuration("name", design_unit, vhdl_configuration_name="cfg")
970+
config = Configuration("name", design_unit, vhdl_config_name="cfg")
971971
simif = IncisiveInterface(prefix="prefix", output_path=self.output_path)
972972
self.assertEqual(simif._select_vhdl_top(config), "cfg") # pylint: disable=protected-access
973973
config = Configuration("name", design_unit)
@@ -1002,5 +1002,5 @@ def make_config(sim_options=None, generics=None, verilog=False):
10021002

10031003
cfg.sim_options = {} if sim_options is None else sim_options
10041004
cfg.generics = {} if generics is None else generics
1005-
cfg.vhdl_configuration_name = None
1005+
cfg.vhdl_config_name = None
10061006
return cfg

tests/unit/test_test_suites.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def get_simulator_output_path(self, output_path):
216216

217217
for expect_runner_cfg_generic in [False, True]:
218218
config = Configuration(
219-
"name", design_unit, vhdl_configuration_name=None if expect_runner_cfg_generic else "cfg"
219+
"name", design_unit, vhdl_config_name=None if expect_runner_cfg_generic else "cfg"
220220
)
221221
sim_if = TestSimIf(output_path, gui=False, expect_runner_cfg_generic=expect_runner_cfg_generic)
222222

vunit/configuration.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ def __init__( # pylint: disable=too-many-arguments
4343
pre_config=None,
4444
post_check=None,
4545
attributes=None,
46-
vhdl_configuration_name=None,
46+
vhdl_config_name=None,
4747
):
4848
self.name = name
4949
self._design_unit = design_unit
5050
self.generics = {} if generics is None else generics
5151
self.sim_options = {} if sim_options is None else sim_options
5252
self.attributes = {} if attributes is None else attributes
53-
self.vhdl_configuration_name = vhdl_configuration_name
53+
self.vhdl_config_name = vhdl_config_name
5454

5555
self.tb_path = str(Path(design_unit.original_file_name).parent)
5656

@@ -70,7 +70,7 @@ def copy(self):
7070
pre_config=self.pre_config,
7171
post_check=self.post_check,
7272
attributes=self.attributes.copy(),
73-
vhdl_configuration_name=self.vhdl_configuration_name,
73+
vhdl_config_name=self.vhdl_config_name,
7474
)
7575

7676
@property
@@ -109,20 +109,20 @@ def set_attribute(self, name, value):
109109
else:
110110
raise AttributeException
111111

112-
def set_vhdl_configuration_name(self, name):
112+
def set_vhdl_config_name(self, name):
113113
"""
114114
Set VHDL configuration name
115115
"""
116116
if self.generics:
117117
raise GenericAndVHDLConfigurationException("Generics can't be used with VHDL configurations.")
118118

119-
self.vhdl_configuration_name = name
119+
self.vhdl_config_name = name
120120

121121
def set_generic(self, name, value):
122122
"""
123123
Set generic
124124
"""
125-
if self.vhdl_configuration_name:
125+
if self.vhdl_config_name:
126126
raise GenericAndVHDLConfigurationException("Generics can't be used with VHDL configurations.")
127127
if name not in self._design_unit.generic_names:
128128
LOGGER.warning(
@@ -210,7 +210,10 @@ def get_configuration_dicts():
210210

211211
def set_attribute(self, name, value):
212212
"""
213-
Set attribute
213+
Set attribute.
214+
215+
:param name: Attribute name.
216+
:param value: Attribute value.
214217
"""
215218
self._check_enabled()
216219
for configs in self.get_configuration_dicts():
@@ -219,7 +222,10 @@ def set_attribute(self, name, value):
219222

220223
def set_generic(self, name, value):
221224
"""
222-
Set generic
225+
Set generic.
226+
227+
:param name: Generic name.
228+
:param value: Generic value.
223229
"""
224230
self._check_enabled()
225231
for configs in self.get_configuration_dicts():
@@ -228,8 +234,10 @@ def set_generic(self, name, value):
228234

229235
def set_sim_option(self, name, value, overwrite=True):
230236
"""
231-
Set sim option
237+
Set simulation option
232238
239+
:param name: Simulation option name.
240+
:param value: Simulation option value.
233241
:param overwrite: To overwrite the option or append to the existing value
234242
"""
235243
self._check_enabled()
@@ -243,6 +251,8 @@ def set_sim_option(self, name, value, overwrite=True):
243251
def set_pre_config(self, value):
244252
"""
245253
Set pre_config function
254+
255+
:param value: pre_config function.
246256
"""
247257
self._check_enabled()
248258
for configs in self.get_configuration_dicts():
@@ -252,6 +262,8 @@ def set_pre_config(self, value):
252262
def set_post_check(self, value):
253263
"""
254264
Set post_check function
265+
266+
:param value: post_check function.
255267
"""
256268
self._check_enabled()
257269
for configs in self.get_configuration_dicts():
@@ -266,10 +278,10 @@ def add_config( # pylint: disable=too-many-arguments, too-many-branches
266278
post_check=None,
267279
sim_options=None,
268280
attributes=None,
269-
vhdl_configuration_name=None,
281+
vhdl_config_name=None,
270282
):
271283
"""
272-
Add a configuration copying unset fields from the default configuration:
284+
Add a configuration copying unset fields from the default configuration.
273285
"""
274286
self._check_enabled()
275287

@@ -291,7 +303,7 @@ def add_config( # pylint: disable=too-many-arguments, too-many-branches
291303
config.post_check = post_check
292304

293305
if generics is not None:
294-
if config.vhdl_configuration_name:
306+
if config.vhdl_config_name:
295307
raise GenericAndVHDLConfigurationException
296308
config.generics.update(generics)
297309

@@ -304,9 +316,22 @@ def add_config( # pylint: disable=too-many-arguments, too-many-branches
304316
raise AttributeException
305317
config.attributes.update(attributes)
306318

307-
if vhdl_configuration_name is not None:
319+
if vhdl_config_name is not None:
308320
if config.generics:
309321
raise GenericAndVHDLConfigurationException
310-
config.vhdl_configuration_name = vhdl_configuration_name
322+
config.vhdl_config_name = vhdl_config_name
311323

312324
configs[config.name] = config
325+
326+
def delete_config(self, name):
327+
"""
328+
Delete a configuration.
329+
"""
330+
found_config = False
331+
for configs in self.get_configuration_dicts():
332+
if name in configs:
333+
found_config = True
334+
del configs[name]
335+
336+
if not found_config:
337+
raise RuntimeError(f"Configuration name {name!s} not defined")

vunit/sim_if/activehdl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ def _create_load_function(self, config, output_path):
238238
config.library_name,
239239
]
240240

241-
if config.vhdl_configuration_name is None:
241+
if config.vhdl_config_name is None:
242242
vsim_flags.append(config.entity_name)
243243
if config.architecture_name is not None:
244244
vsim_flags.append(config.architecture_name)
245245
else:
246-
vsim_flags.append(config.vhdl_configuration_name)
246+
vsim_flags.append(config.vhdl_config_name)
247247

248248
if config.sim_options.get("enable_coverage", False):
249249
coverage_file_path = str(Path(output_path) / "coverage.acdb")

vunit/sim_if/ghdl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ def _get_command(self, config, output_path, elaborate_only, ghdl_e, wave_file):
286286
# Enable coverage in linker
287287
cmd += ["-Wl,-lgcov"]
288288

289-
if config.vhdl_configuration_name is not None:
290-
cmd += [config.vhdl_configuration_name]
289+
if config.vhdl_config_name is not None:
290+
cmd += [config.vhdl_config_name]
291291
else:
292292
cmd += [config.entity_name, config.architecture_name]
293293

0 commit comments

Comments
 (0)