Skip to content

Commit

Permalink
Add disable_coverage compile_option. Closes VUnit#330.
Browse files Browse the repository at this point in the history
  • Loading branch information
Olof Kraigher committed Apr 25, 2018
1 parent c1b2148 commit d86c49d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 42 deletions.
5 changes: 3 additions & 2 deletions vunit/modelsim_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ def add_simulator_specific(self, project):

# Add coverage options
for source_file in project.get_source_files_in_order():
source_file.add_compile_option("modelsim.vcom_flags", ["+cover=" + self._coverage])
source_file.add_compile_option("modelsim.vlog_flags", ["+cover=" + self._coverage])
if not source_file.compile_options.get("disable_coverage", False):
source_file.add_compile_option("modelsim.vcom_flags", ["+cover=" + self._coverage])
source_file.add_compile_option("modelsim.vlog_flags", ["+cover=" + self._coverage])

def setup_library_mapping(self, project):
"""
Expand Down
5 changes: 3 additions & 2 deletions vunit/rivierapro_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ def add_simulator_specific(self, project):

# Add coverage options
for source_file in project.get_source_files_in_order():
source_file.add_compile_option("rivierapro.vcom_flags", ['-coverage', self._coverage])
source_file.add_compile_option("rivierapro.vlog_flags", ['-coverage', self._coverage])
if not source_file.compile_options.get("disable_coverage", False):
source_file.add_compile_option("rivierapro.vcom_flags", ['-coverage', self._coverage])
source_file.add_compile_option("rivierapro.vlog_flags", ['-coverage', self._coverage])

def setup_library_mapping(self, project):
"""
Expand Down
3 changes: 2 additions & 1 deletion vunit/simulator_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def _extract_compile_options(self):
"""
Return all supported compile options
"""
result = {}
result = dict((opt.name, opt) for opt in
[BooleanOption("disable_coverage")])
for sim_class in self.supported_simulators():
for opt in sim_class.compile_options:
assert hasattr(opt, "name")
Expand Down
51 changes: 30 additions & 21 deletions vunit/test/unit/test_modelsim_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,38 @@ def test_compile_project_vhdl_extra_flags(self, process, check_output):
@mock.patch("vunit.simulator_interface.check_output", autospec=True, return_value="")
@mock.patch("vunit.modelsim_interface.Process", autospec=True)
def test_compile_project_vhdl_coverage(self, process, check_output):
write_file("modelsim.ini", """
for coverage_off in [False, True]:
check_output.reset_mock()

write_file("modelsim.ini", """
[Library]
""")
modelsim_ini = join(self.output_path, "modelsim.ini")
simif = ModelSimInterface(prefix="prefix",
output_path=self.output_path,
coverage="best",
persistent=False)
project = Project()
project.add_library("lib", "lib_path")
write_file("file.vhd", "")
project.add_source_file("file.vhd", "lib", file_type="vhdl")
simif.compile_project(project)
process.assert_called_once_with([join("prefix", "vlib"), "-unix", "lib_path"], env=simif.get_env())
check_output.assert_called_once_with([join('prefix', 'vcom'),
'-quiet',
'-modelsimini',
modelsim_ini,
'+cover=best',
'-2008',
'-work',
'lib',
'file.vhd'], env=simif.get_env())
modelsim_ini = join(self.output_path, "modelsim.ini")
simif = ModelSimInterface(prefix="prefix",
output_path=self.output_path,
coverage="best",
persistent=False)
project = Project()
project.add_library("lib", "lib_path")
write_file("file.vhd", "")
source_file = project.add_source_file("file.vhd", "lib", file_type="vhdl")

if coverage_off:
source_file.set_compile_option("disable_coverage", True)
covargs = []
else:
covargs = ['+cover=best']

simif.compile_project(project)
process.assert_called_once_with([join("prefix", "vlib"), "-unix", "lib_path"], env=simif.get_env())
check_output.assert_called_once_with([join('prefix', 'vcom'),
'-quiet',
'-modelsimini',
modelsim_ini] + covargs + [
'-2008',
'-work',
'lib',
'file.vhd'], env=simif.get_env())

@mock.patch("vunit.simulator_interface.check_output", autospec=True, return_value="")
@mock.patch("vunit.modelsim_interface.Process", autospec=True)
Expand Down
36 changes: 20 additions & 16 deletions vunit/test/unit/test_rivierapro_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import unittest
from os.path import join, dirname, exists
import os
from itertools import product
from shutil import rmtree
from vunit.rivierapro_interface import RivieraProInterface
from vunit.test.mock_2or3 import mock
Expand Down Expand Up @@ -207,7 +208,7 @@ def test_compile_project_verilog_define(self, process, check_output):
def test_compile_project_coverage(self, process, check_output):
library_cfg = join(self.output_path, "library.cfg")

for file_type in ["vhdl", "verilog"]:
for file_type, coverage_off in product(["vhdl", "verilog"], [False, True]):
check_output.reset_mock()

simif = RivieraProInterface(prefix="prefix",
Expand All @@ -223,7 +224,14 @@ def test_compile_project_coverage(self, process, check_output):
file_name = "file.v"

write_file(file_name, "")
project.add_source_file(file_name, "lib", file_type=file_type)
source_file = project.add_source_file(file_name, "lib", file_type=file_type)

if coverage_off:
covargs = []
source_file.set_compile_option("disable_coverage", True)
else:
covargs = ['-coverage', 'bes']

simif.compile_project(project)
process.assert_any_call([join("prefix", "vlib"), "lib", "lib_path"],
cwd=self.output_path, env=simif.get_env())
Expand All @@ -235,25 +243,21 @@ def test_compile_project_coverage(self, process, check_output):
[join('prefix', 'vcom'),
'-quiet',
'-j',
self.output_path,
'-coverage',
'bes',
'-2008',
'-work',
'lib',
'file.vhd'], env=simif.get_env())
self.output_path] + covargs + [
'-2008',
'-work',
'lib',
'file.vhd'], env=simif.get_env())
elif file_type == "verilog":
check_output.assert_called_once_with(
[join('prefix', 'vlog'),
'-quiet',
'-lc',
library_cfg,
'-coverage',
'bes',
'-work',
'lib',
'file.v',
'-l', 'lib'],
library_cfg] + covargs + [
'-work',
'lib',
'file.v',
'-l', 'lib'],
env=simif.get_env())
else:
assert False
Expand Down
5 changes: 5 additions & 0 deletions vunit/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
differing options available, generic options may be specified through this interface.
The following compilation options are known.
``disable_coverage``
Disable coverage.
Do not add coverage compile flags when running with ``--coverage``. Default is False.
Boolean
``ghdl.flags``
Extra arguments passed to ``ghdl -a`` command during compilation.
Must be a list of strings.
Expand Down

0 comments on commit d86c49d

Please sign in to comment.