Skip to content

Commit 9e692ce

Browse files
committed
Added support for manual addition of VHDL configurations.
1 parent b7fcc7f commit 9e692ce

16 files changed

Lines changed: 201 additions & 14 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2023, Lars Asplund lars.anders.asplund@gmail.com
6+
7+
architecture arch1 of ent is
8+
begin
9+
arch <= "arch1";
10+
end;
11+
12+
configuration cfg1 of tb_with_vhdl_configuration is
13+
for tb
14+
for ent_inst : ent
15+
use entity work.ent(arch1);
16+
end for;
17+
end for;
18+
end;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2023, Lars Asplund lars.anders.asplund@gmail.com
6+
7+
architecture arch2 of ent is
8+
begin
9+
arch <= "arch2";
10+
end;
11+
12+
configuration cfg2 of tb_with_vhdl_configuration is
13+
for tb
14+
for ent_inst : ent
15+
use entity work.ent(arch2);
16+
end for;
17+
end for;
18+
end;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2023, Lars Asplund lars.anders.asplund@gmail.com
6+
7+
entity ent is
8+
port(arch : out string(1 to 5));
9+
end;

tests/acceptance/artificial/vhdl/run.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,27 @@ def configure_tb_assert_stop_level(ui):
9494
test.set_sim_option("vhdl_assert_stop_level", vhdl_assert_stop_level)
9595

9696

97+
def configure_tb_with_vhdl_configuration(ui):
98+
def make_post_check(expected_arch):
99+
def post_check(output_path):
100+
arch = (Path(output_path) / "result.txt").read_text()
101+
if arch[:-1] != expected_arch:
102+
raise RuntimeError(f"Error! Got {arch[: -1]}, expected {expected_arch}")
103+
104+
return True
105+
106+
return post_check
107+
108+
tb = ui.library("lib").entity("tb_with_vhdl_configuration")
109+
tb.add_config(name="cfg1", post_check=make_post_check("arch1"), vhdl_configuration_name="cfg1")
110+
tb.add_config(name="cfg2", post_check=make_post_check("arch2"), vhdl_configuration_name="cfg2")
111+
112+
97113
configure_tb_with_generic_config()
98114
configure_tb_same_sim_all_pass(vu)
99115
configure_tb_set_generic(vu)
100116
configure_tb_assert_stop_level(vu)
117+
configure_tb_with_vhdl_configuration(vu)
101118
lib.entity("tb_no_generic_override").set_generic("g_val", False)
102119
lib.entity("tb_ieee_warning").test("pass").set_sim_option("disable_ieee_warnings", True)
103120
lib.entity("tb_other_file_tests").scan_tests_from_file(str(root / "other_file_tests.vhd"))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2023, Lars Asplund lars.anders.asplund@gmail.com
6+
7+
library vunit_lib;
8+
context vunit_lib.vunit_context;
9+
10+
use std.textio.all;
11+
12+
entity tb_with_vhdl_configuration is
13+
generic(runner_cfg : string);
14+
end entity;
15+
16+
architecture tb of tb_with_vhdl_configuration is
17+
component ent
18+
port(arch : out string(1 to 5));
19+
end component;
20+
21+
signal arch : string(1 to 5);
22+
23+
begin
24+
test_runner : process
25+
file result_fptr : text;
26+
variable result_line : line;
27+
begin
28+
test_runner_setup(runner, runner_cfg);
29+
30+
file_open(result_fptr, join(output_path(runner_cfg), "result.txt"), write_mode);
31+
write(result_line, arch);
32+
writeline(result_fptr, result_line);
33+
file_close(result_fptr);
34+
35+
info(arch);
36+
37+
test_runner_cleanup(runner);
38+
wait;
39+
end process;
40+
41+
ent_inst : ent
42+
port map(
43+
arch => arch
44+
);
45+
46+
end architecture;

tests/acceptance/test_artificial.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,12 @@ 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",
251+
),
252+
(
253+
"passed",
254+
"lib.tb_with_vhdl_configuration.cfg2",
255+
),
248256
)

tests/unit/test_incisive_interface.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from vunit.ostools import renew_path, write_file, read_file
2222
from vunit.test.bench import Configuration
2323
from vunit.vhdl_standard import VHDL
24+
from tests.common import create_tempdir
25+
from tests.unit.test_test_bench import Entity
2426

2527

2628
class TestIncisiveInterface(unittest.TestCase):
@@ -956,6 +958,21 @@ def test_simulate_gui(self, run_command, find_cds_root_irun, find_cds_root_virtu
956958
],
957959
)
958960

961+
@mock.patch("vunit.sim_if.incisive.IncisiveInterface.find_cds_root_virtuoso")
962+
@mock.patch("vunit.sim_if.incisive.IncisiveInterface.find_cds_root_irun")
963+
def test_configuration_and_entity_selection(self, find_cds_root_irun, find_cds_root_virtuoso):
964+
find_cds_root_irun.return_value = "cds_root_irun"
965+
find_cds_root_virtuoso.return_value = None
966+
967+
with create_tempdir() as tempdir:
968+
design_unit = Entity("tb_entity", file_name=str(Path(tempdir) / "file.vhd"))
969+
design_unit.generic_names = ["runner_cfg"]
970+
config = Configuration("name", design_unit, vhdl_configuration_name="cfg")
971+
simif = IncisiveInterface(prefix="prefix", output_path=self.output_path)
972+
self.assertEqual(simif._select_vhdl_top(config), "cfg") # pylint: disable=protected-access
973+
config = Configuration("name", design_unit)
974+
self.assertEqual(simif._select_vhdl_top(config), "lib.tb_entity:arch") # pylint: disable=protected-access
975+
959976
def setUp(self):
960977
self.output_path = str(Path(__file__).parent / "test_incisive_out")
961978
renew_path(self.output_path)
@@ -985,4 +1002,5 @@ def make_config(sim_options=None, generics=None, verilog=False):
9851002

9861003
cfg.sim_options = {} if sim_options is None else sim_options
9871004
cfg.generics = {} if generics is None else generics
1005+
cfg.vhdl_configuration_name = None
9881006
return cfg

vunit/configuration.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ def __init__( # pylint: disable=too-many-arguments
3939
pre_config=None,
4040
post_check=None,
4141
attributes=None,
42+
vhdl_configuration_name=None,
4243
):
4344
self.name = name
4445
self._design_unit = design_unit
4546
self.generics = {} if generics is None else generics
4647
self.sim_options = {} if sim_options is None else sim_options
4748
self.attributes = {} if attributes is None else attributes
49+
self.vhdl_configuration_name = vhdl_configuration_name
4850

4951
self.tb_path = str(Path(design_unit.original_file_name).parent)
5052

@@ -64,6 +66,7 @@ def copy(self):
6466
pre_config=self.pre_config,
6567
post_check=self.post_check,
6668
attributes=self.attributes.copy(),
69+
vhdl_configuration_name=self.vhdl_configuration_name,
6770
)
6871

6972
@property
@@ -102,6 +105,12 @@ def set_attribute(self, name, value):
102105
else:
103106
raise AttributeException
104107

108+
def set_vhdl_configuration_name(self, name):
109+
"""
110+
Set VHDL configuration name
111+
"""
112+
self.vhdl_configuration_name = name
113+
105114
def set_generic(self, name, value):
106115
"""
107116
Set generic
@@ -248,6 +257,7 @@ def add_config( # pylint: disable=too-many-arguments
248257
post_check=None,
249258
sim_options=None,
250259
attributes=None,
260+
vhdl_configuration_name=None,
251261
):
252262
"""
253263
Add a configuration copying unset fields from the default configuration:
@@ -283,4 +293,7 @@ def add_config( # pylint: disable=too-many-arguments
283293
raise AttributeException
284294
config.attributes.update(attributes)
285295

296+
if vhdl_configuration_name is not None:
297+
config.vhdl_configuration_name = vhdl_configuration_name
298+
286299
configs[config.name] = config

vunit/sim_if/activehdl.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,14 @@ def _create_load_function(self, config, output_path):
239239
set_generic_name_str,
240240
"-lib",
241241
config.library_name,
242-
config.entity_name,
243242
]
244243

245-
if config.architecture_name is not None:
246-
vsim_flags.append(config.architecture_name)
244+
if config.vhdl_configuration_name is None:
245+
vsim_flags.append(config.entity_name)
246+
if config.architecture_name is not None:
247+
vsim_flags.append(config.architecture_name)
248+
else:
249+
vsim_flags.append(config.vhdl_configuration_name)
247250

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

vunit/sim_if/ghdl.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ def _get_command(self, config, output_path, elaborate_only, ghdl_e, wave_file):
279279
if config.sim_options.get("enable_coverage", False):
280280
# Enable coverage in linker
281281
cmd += ["-Wl,-lgcov"]
282-
cmd += [config.entity_name, config.architecture_name]
282+
283+
if config.vhdl_configuration_name is not None:
284+
cmd += [config.vhdl_configuration_name]
285+
else:
286+
cmd += [config.entity_name, config.architecture_name]
283287

284288
sim = config.sim_options.get("ghdl.sim_flags", [])
285289
for name, value in config.generics.items():

0 commit comments

Comments
 (0)