Skip to content

Commit 4aea4d4

Browse files
committed
Updated run script to emulate support for post-simulation Visualizer
1 parent b2ae82b commit 4aea4d4

File tree

4 files changed

+86
-35
lines changed

4 files changed

+86
-35
lines changed

examples/vhdl/three_step_flow/run.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,56 @@
88
from pathlib import Path
99
from vunit import VUnit, VUnitCLI
1010
from os import environ
11+
from subprocess import run
1112
import logging
1213

1314
logging.basicConfig(
1415
level=logging.DEBUG, format="%(asctime)s.%(msecs)03d - %(levelname)7s - %(message)s", datefmt="%H:%M:%S"
1516
)
1617

17-
cli = VUnitCLI()
18-
1918
environ["VUNIT_SIMULATOR"] = "modelsim"
2019

21-
vu = VUnit.from_argv()
20+
cli = VUnitCLI()
21+
args = cli.parse_args()
22+
gui = args.gui
23+
args.gui = False
24+
vu = VUnit.from_args(args=args)
2225
vu.add_vhdl_builtins()
2326

27+
28+
# Support functions for setting up post-simulation Visualizer
29+
def fix_path(path):
30+
return str(path).replace("\\", "/").replace(" ", "\\ ")
31+
32+
33+
def save_design_file(obj, design_file_path):
34+
obj.set_sim_option("modelsim.vopt_flags", ["-debug", "-designfile", fix_path(design_file_path)])
35+
36+
37+
def save_db_sim_option(db_file_path):
38+
return {"modelsim.vsim_flags": [f"-qwavedb=+signal+memory+wavefile={fix_path(db_file_path)}"]}
39+
40+
41+
def save_db(obj, db_file_path):
42+
sim_option = save_db_sim_option(db_file_path)
43+
obj.set_sim_option("modelsim.vsim_flags", sim_option["modelsim.vsim_flags"])
44+
45+
46+
def post_check(design_file_path, db_file_path):
47+
def func(output_path):
48+
run(["visualizer", "-designfile", fix_path(design_file_path), "-wavefile", fix_path(db_file_path)])
49+
50+
return True
51+
52+
return func
53+
54+
55+
def setup_visualizer(obj, design_file_path, db_file_path):
56+
save_design_file(obj, design_file_path)
57+
save_db(obj, db_file_path)
58+
obj.set_post_check(post_check(design_file_path, db_file_path))
59+
60+
2461
root = Path(__file__).parent
2562

2663
lib1 = vu.add_library("lib1")
@@ -29,11 +66,23 @@
2966
lib2 = vu.add_library("lib2")
3067
lib2.add_source_files(root / "*.vhd")
3168

69+
if gui:
70+
setup_visualizer(lib1.test_bench("tb_a"), root / "lib1.tb_a.bin", root / "lib1.tb_a.db")
71+
setup_visualizer(lib2.test_bench("tb_b"), root / "lib2.tb_b.bin", root / "lib2.tb_b.db")
72+
3273
tb = lib2.test_bench("tb_example")
74+
design_file_path = root / "lib2.tb_example.bin"
75+
save_design_file(tb, design_file_path)
3376
test = tb.test("test")
3477

3578
for value in range(5):
36-
test.add_config(name=f"{value}", generics=dict(value=value))
79+
db_file_path = root / f"lib2.tb_example.{value}.test.db"
80+
test.add_config(
81+
name=f"{value}",
82+
generics=dict(value=value),
83+
sim_options=save_db_sim_option(db_file_path) if gui else None,
84+
post_check=post_check(design_file_path, db_file_path) if gui else None,
85+
)
3786

3887
vu.set_sim_option("modelsim.three_step_flow", True)
3988

examples/vhdl/three_step_flow/sub_module/tb_a.vhd

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@ entity tb_a is
1313
end entity;
1414

1515
architecture tb of tb_a is
16+
signal clk : bit;
17+
signal message : string(1 to 7);
1618
begin
1719
main : process
18-
function recurse(value : integer) return integer is
19-
begin
20-
if value <= 0 then
21-
return 0;
22-
elsif value mod 2 = 0 then
23-
return 1 + recurse(value - 1);
24-
else
25-
return recurse(value - 1);
26-
end if;
27-
end;
2820
begin
2921
test_runner_setup(runner, runner_cfg);
3022

31-
info("Running tb_a: " & to_string(recurse(17)));
23+
info("Running tb_a");
24+
25+
message <= "Running";
26+
wait until rising_edge(clk);
27+
message <= "tb_a ";
28+
wait until rising_edge(clk);
3229

3330
test_runner_cleanup(runner);
3431
end process;
32+
33+
clk <= not clk after 100 ns;
3534
end architecture;

examples/vhdl/three_step_flow/tb_b.vhd

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@ entity tb_b is
1313
end entity;
1414

1515
architecture tb of tb_b is
16+
signal clk : bit;
17+
signal message : string(1 to 7);
1618
begin
1719
main : process
18-
function recurse(value : integer) return integer is
19-
begin
20-
if value <= 0 then
21-
return 0;
22-
elsif value mod 2 = 0 then
23-
return 1 + recurse(value - 1);
24-
else
25-
return recurse(value - 1);
26-
end if;
27-
end;
2820
begin
2921
test_runner_setup(runner, runner_cfg);
3022

31-
info("Running tb_b: " & to_string(recurse(17)));
23+
info("Running tb_b");
24+
25+
message <= "Running";
26+
wait until rising_edge(clk);
27+
message <= "tb_b ";
28+
wait until rising_edge(clk);
3229

3330
test_runner_cleanup(runner);
3431
end process;
32+
33+
clk <= not clk after 100 ns;
3534
end architecture;

examples/vhdl/three_step_flow/tb_example.vhd

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,10 @@ entity tb_example is
1414
end entity;
1515

1616
architecture tb of tb_example is
17+
signal clk : bit;
18+
signal message : string(1 to 7);
1719
begin
1820
main : process
19-
function recurse(value : integer) return integer is
20-
begin
21-
if value <= 0 then
22-
return 0;
23-
else
24-
return 1 + recurse(value - 1);
25-
end if;
26-
end;
2721
begin
2822
test_runner_setup(runner, runner_cfg);
2923

@@ -32,9 +26,19 @@ begin
3226
end if;
3327

3428
info("Running " & running_test_case & " with generic value = " & to_string(value));
35-
info("Recurse = " & to_string(recurse(value)));
29+
30+
message <= "Running";
31+
wait until rising_edge(clk);
32+
message <= "test ";
33+
wait until rising_edge(clk);
34+
message(1 to 1) <= to_string(value);
35+
message(2 to 7) <= " ";
36+
wait until rising_edge(clk);
37+
3638
end loop;
3739

3840
test_runner_cleanup(runner);
3941
end process;
42+
43+
clk <= not clk after 100 ns;
4044
end architecture;

0 commit comments

Comments
 (0)