Skip to content

Commit

Permalink
pre_config: pass optional simulator_output_path argument (VUnit#237)
Browse files Browse the repository at this point in the history
* pre_config: pass optional simulator_output_path argument

Fixes VUnit#236.

* fix pylint issues

* document simulator_output_path
  • Loading branch information
Clemens Buchacher authored and kraigher committed Apr 3, 2017
1 parent f163bde commit 86b7c8d
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions vunit/activehdl_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def supports_vhdl_package_generics(cls):
return False

def __init__(self, prefix, library_cfg="library.cfg", gui=False):
SimulatorInterface.__init__(self)
self._library_cfg = abspath(library_cfg)
self._prefix = prefix
self._gui = gui
Expand Down
1 change: 1 addition & 0 deletions vunit/ghdl_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def find_prefix_from_path(cls):
return cls.find_toolchain(["ghdl"])

def __init__(self, prefix, gui=False, gtkwave_fmt=None, gtkwave_args="", backend="llvm"):
SimulatorInterface.__init__(self)
self._prefix = prefix
self._project = None

Expand Down
1 change: 1 addition & 0 deletions vunit/incisive_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def supports_vhdl_2008_contexts():

def __init__(self, # pylint: disable=too-many-arguments
prefix, output_path, gui=False, log_level=None, cdslib=None, hdlvar=None):
SimulatorInterface.__init__(self)
self._prefix = prefix
self._libraries = []
self._output_path = output_path
Expand Down
1 change: 1 addition & 0 deletions vunit/modelsim_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def supports_vhdl_package_generics(cls):
return True

def __init__(self, prefix, modelsim_ini="modelsim.ini", persistent=False, gui=False, coverage=None):
SimulatorInterface.__init__(self)
VsimSimulatorMixin.__init__(self, prefix, persistent, gui, modelsim_ini)
self._libraries = []
self._coverage = coverage
Expand Down
1 change: 1 addition & 0 deletions vunit/rivierapro_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def supports_vhdl_package_generics(cls):
return True

def __init__(self, prefix, library_cfg="library.cfg", persistent=False, gui=False):
SimulatorInterface.__init__(self)
VsimSimulatorMixin.__init__(self, prefix, persistent, gui, library_cfg)
self._create_library_cfg()
self._libraries = []
Expand Down
6 changes: 4 additions & 2 deletions vunit/simulator_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,7 @@ def create(self):
if not exists(self.simulator_output_path):
os.makedirs(self.simulator_output_path)

return self._simulator_class.from_args(self.simulator_output_path,
self._args)
simulator_if = self._simulator_class.from_args(self.simulator_output_path,
self._args)
simulator_if.set_output_path(self.simulator_output_path)
return simulator_if
9 changes: 9 additions & 0 deletions vunit/simulator_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class SimulatorInterface(object):
compile_options = []
sim_options = []

def __init__(self):
self.output_path = None

@staticmethod
def add_arguments(parser):
"""
Expand Down Expand Up @@ -193,6 +196,12 @@ def compile_source_files(self, project, continue_on_error=False):
def compile_source_file_command(self, source_file): # pylint: disable=unused-argument
raise NotImplementedError

def set_output_path(self, output_path):
self.output_path = output_path

def get_output_path(self):
return self.output_path

@staticmethod
def get_env():
"""
Expand Down
25 changes: 20 additions & 5 deletions vunit/test/unit/test_test_suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ class TestTestSuites(TestCase):
"""

def test_call_pre_config_none(self):
self.assertEqual(call_pre_config(None, "output_path"), True)
self.assertEqual(call_pre_config(None, "output_path", "simulator_output_path"), True)

def test_call_pre_config_false(self):
def pre_config():
return False
self.assertEqual(call_pre_config(pre_config, "output_path"), False)
self.assertEqual(call_pre_config(pre_config, "output_path", "simulator_output_path"), False)

def test_call_pre_config_true(self):
def pre_config():
return True
self.assertEqual(call_pre_config(pre_config, "output_path"), True)
self.assertEqual(call_pre_config(pre_config, "output_path", "simulator_output_path"), True)

def test_call_pre_config_no_return(self):
def pre_config():
pass
self.assertEqual(call_pre_config(pre_config, "output_path"), False)
self.assertEqual(call_pre_config(pre_config, "output_path", "simulator_output_path"), False)

def test_call_pre_config_with_output_path(self):

Expand All @@ -47,4 +47,19 @@ def pre_config(output_path):
self.assertEqual(output_path, "output_path")
raise WasHere

self.assertRaises(WasHere, call_pre_config, pre_config, "output_path")
self.assertRaises(WasHere, call_pre_config, pre_config, "output_path", "simulator_output_path")

def test_call_pre_config_with_simulator_output_path(self):

class WasHere(Exception):
pass

def pre_config(output_path, simulator_output_path):
"""
Pre config with output path
"""
self.assertEqual(output_path, "output_path")
self.assertEqual(simulator_output_path, "simulator_output_path")
raise WasHere

self.assertRaises(WasHere, call_pre_config, pre_config, "output_path", "simulator_output_path")
13 changes: 9 additions & 4 deletions vunit/test_suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def run(self, output_path):
"""
Run the test case using the output_path
"""
if not call_pre_config(self._config.pre_config, output_path):
if not call_pre_config(self._config.pre_config, output_path,
self._simulator_if.get_output_path()):
return False

enabled_test_cases = [self._test_case]
Expand Down Expand Up @@ -118,7 +119,8 @@ def run(self, output_path):
"""
Run the test suite using output_path
"""
if not call_pre_config(self._config.pre_config, output_path):
if not call_pre_config(self._config.pre_config, output_path,
self._simulator_if.get_output_path()):
return False

enabled_test_cases = [encode_test_case(test_case) for test_case in self._test_cases]
Expand Down Expand Up @@ -245,13 +247,16 @@ def encode_dict_value(value):
return str(value)


def call_pre_config(pre_config, output_path):
def call_pre_config(pre_config, output_path, simulator_output_path):
"""
Call pre_config if available. Setting optional output_path
"""
if pre_config is not None:
args = inspect.getargspec(pre_config).args # pylint: disable=deprecated-method
if "output_path" in args:
if args == ["output_path", "simulator_output_path"]:
if not pre_config(output_path, simulator_output_path):
return False
elif "output_path" in args:
if not pre_config(output_path):
return False
else:
Expand Down
8 changes: 6 additions & 2 deletions vunit/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,8 +1337,12 @@ def add_config(self, # pylint: disable=too-many-arguments
:param generics: A `dict` containing the generics to be set in addition to the default configuration
:param parameters: A `dict` containing the parameters to be set in addition to the default configuration
:param pre_config: A function to be called before test execution, replaces the default if not None
The function may accept a string which is the filesystem path to the
directory where test outputs are stored.
The function accepts an optional first argument `output_path` which is the filesystem path to the
directory where test outputs are stored. An optional second argument
`simulator_output_path` is the filesystem path to the simulator working directory.
Please note that `simulator_output_path` is shared by all test runs. The user must take
care that test runs do not read or write the same files asynchronously. It is therefore
recommended to use `output_path` in favor of `simulator_output_path`.
The function must return `True` or the test will fail
:param post_check: A function to be called after test execution, replaces the default if not None
The function must accept a string which is the filesystem path to the
Expand Down

0 comments on commit 86b7c8d

Please sign in to comment.