Skip to content

Commit 3e16fc5

Browse files
committed
support GHDL in example 'coverage'
1 parent 8ecaaf1 commit 3e16fc5

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

examples/vhdl/coverage/run.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,32 @@
55
# Copyright (c) 2014-2020, Lars Asplund lars.anders.asplund@gmail.com
66

77
from pathlib import Path
8+
from os import getcwd
89
from vunit import VUnit
9-
10-
11-
def post_run(results):
12-
results.merge_coverage(file_name="coverage_data")
13-
10+
from subprocess import call
1411

1512
VU = VUnit.from_argv()
1613

1714
LIB = VU.add_library("lib")
1815
LIB.add_source_files(Path(__file__).parent / "*.vhd")
1916

17+
LIB.set_sim_option("enable_coverage", True)
18+
2019
LIB.set_compile_option("rivierapro.vcom_flags", ["-coverage", "bs"])
2120
LIB.set_compile_option("rivierapro.vlog_flags", ["-coverage", "bs"])
2221
LIB.set_compile_option("modelsim.vcom_flags", ["+cover=bs"])
2322
LIB.set_compile_option("modelsim.vlog_flags", ["+cover=bs"])
24-
LIB.set_sim_option("enable_coverage", True)
23+
LIB.set_compile_option("ghdl.flags", ["-g", "-O2", "-fprofile-arcs", "-ftest-coverage"])
24+
LIB.set_sim_option("ghdl.elab_flags", ["-Wl,-lgcov", "-Wl,--coverage"])
25+
26+
27+
def post_run(results):
28+
if VU.get_simulator_name() != "ghdl":
29+
results.merge_coverage(file_name="coverage_data")
30+
try:
31+
call(["gcovr", "-r", getcwd()])
32+
except Exception:
33+
pass
34+
2535

2636
VU.main(post_run=post_run)

tests/acceptance/test_external_run_scripts.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ def test_vhdl_third_party_integration_example_project(self):
119119
def test_vhdl_check_example_project(self):
120120
self.check(join(ROOT, "examples", "vhdl", "check", "run.py"))
121121

122+
@unittest.skipIf(
123+
simulator_check(lambda simclass: not simclass.supports_coverage()),
124+
"This simulator/backend does not support coverage",
125+
)
126+
def test_vhdl_coverage_example_project(self):
127+
self.check(join(ROOT, "examples", "vhdl", "coverage", "run.py"))
128+
122129
def test_vhdl_generate_tests_example_project(self):
123130
self.check(join(ROOT, "examples", "vhdl", "generate_tests", "run.py"))
124131
check_report(

0 commit comments

Comments
 (0)