def test_warning_on_configuration_of_non_existent_test(self, mock_logger): project = ProjectStub() lib = project.add_library("lib") ent = lib.add_entity("tb_entity", generic_names=["runner_cfg", "name"]) ent.set_contents('if run("Test")') test_scope = create_scope("lib", "tb_entity", "Test") self.configuration.set_generic("name", "value", scope=test_scope) test_1_scope = create_scope("lib", "tb_entity", "No test 1") self.configuration.add_config(scope=test_1_scope, name="", generics=dict()) test_2_scope = create_scope("lib", "tb_entity", "No test 2") self.configuration.set_generic("name", "value", scope=test_2_scope) tests = self.test_scanner.from_project(project) warning_calls = mock_logger.warning.call_args_list self.assertEqual(len(warning_calls), 2) call_args0 = warning_calls[0][0] call_args1 = warning_calls[1][0] self.assertIn(dotjoin(*test_1_scope), call_args0) self.assertIn(dotjoin(*test_2_scope), call_args1) self.assert_has_tests(tests, ["lib.tb_entity.Test"])
def _create_tests_from_unit(self, test_list, entity, architecture_name, verilog=False): """ Derive test cases from an unit """ has_runner_cfg = verilog or ("runner_cfg" in entity.generic_names) pragmas, run_strings = self._parse(entity, architecture_name, verilog) should_run_in_same_sim = "run_all_in_same_sim" in pragmas def create_test_bench(config): """ Helper function to create a test bench """ fail_on_warning = "fail_on_warning" in pragmas return self._create_test_bench(entity, architecture_name, config, fail_on_warning, verilog) def create_name(config, run_string=None): """ Helper function to create a test name """ return create_test_name(entity, architecture_name, config.name, run_string) self._warn_on_individual_configuration(create_scope(entity.library_name, entity.name), run_strings, should_run_in_same_sim) if len(run_strings) == 0 or not has_runner_cfg: scope = create_scope(entity.library_name, entity.name) configurations = self._cfg.get_configurations(scope) for config in configurations: test_list.add_test( IndependentSimTestCase( name=create_name(config), test_case=None, test_bench=create_test_bench(config), has_runner_cfg=has_runner_cfg, pre_config=config.pre_config, post_check=config.post_check)) elif should_run_in_same_sim: scope = create_scope(entity.library_name, entity.name) configurations = self._cfg.get_configurations(scope) for config in configurations: test_list.add_suite( SameSimTestSuite(name=create_name(config), test_cases=run_strings, test_bench=create_test_bench(config), pre_config=config.pre_config, post_check=config.post_check)) else: for run_string in run_strings: scope = create_scope(entity.library_name, entity.name, run_string) configurations = self._cfg.get_configurations(scope) for config in configurations: test_list.add_test( IndependentSimTestCase( name=create_name(config, run_string), test_case=run_string, test_bench=create_test_bench(config), has_runner_cfg=has_runner_cfg, pre_config=config.pre_config, post_check=config.post_check))
def test_add_config(self): for value in range(1, 3): self.cfg.add_config(scope=create_scope("lib", "tb_entity"), name="value=%i" % value, generics=dict(value=value, global_value="local value")) self.cfg.add_config(scope=create_scope("lib", "tb_entity", "configured test"), name="specific_test_config", generics=dict()) # Local value should take precedence self.cfg.set_generic("global_value", "global value") self.assertEqual(self.cfg.get_configurations(create_scope("lib", "tb_entity")), [cfg("value=1", generics={"value": 1, "global_value": "local value"}), cfg("value=2", generics={"value": 2, "global_value": "local value"})]) self.assertEqual(self.cfg.get_configurations(create_scope("lib", "tb_entity", "test")), [cfg("value=1", generics={"value": 1, "global_value": "local value"}), cfg("value=2", generics={"value": 2, "global_value": "local value"})]) self.assertEqual(self.cfg.get_configurations(create_scope("lib", "tb_entity", "configured test")), [cfg("specific_test_config", dict(global_value="global value"))])
def test_warning_on_configuration_of_non_existent_test(self, mock_logger): project = ProjectStub() lib = project.add_library("lib") lib.add_entity("tb_entity", generic_names=["runner_cfg", "name"], contents='if run("Test")') test_scope = create_scope("lib", "tb_entity", "Test") self.configuration.set_generic("name", "value", scope=test_scope) test_1_scope = create_scope("lib", "tb_entity", "No test 1") self.configuration.add_config(scope=test_1_scope, name="", generics=dict()) test_2_scope = create_scope("lib", "tb_entity", "No test 2") self.configuration.set_generic("name", "value", scope=test_2_scope) tests = self.test_scanner.from_project(project) warning_calls = mock_logger.warning.call_args_list self.assertEqual(len(warning_calls), 2) call_args0 = warning_calls[0][0] call_args1 = warning_calls[1][0] self.assertIn(dotjoin(*test_1_scope), call_args0) self.assertIn(dotjoin(*test_2_scope), call_args1) self.assert_has_tests(tests, ["lib.tb_entity.Test"])
def _create_tests_from_unit(self, test_list, entity, architecture_name, verilog=False): """ Derive test cases from an unit """ has_runner_cfg = verilog or ("runner_cfg" in entity.generic_names) pragmas, run_strings = self._parse(entity, architecture_name, verilog) should_run_in_same_sim = "run_all_in_same_sim" in pragmas def create_test_bench(config): """ Helper function to create a test bench """ fail_on_warning = "fail_on_warning" in pragmas return self._create_test_bench(entity, architecture_name, config, fail_on_warning, verilog) self._warn_on_individual_configuration(create_scope(entity.library_name, entity.name), run_strings, should_run_in_same_sim) if len(run_strings) == 0 or not has_runner_cfg: scope = create_scope(entity.library_name, entity.name) configurations = self._cfg.get_configurations(scope) for config in configurations: test_list.add_test( IndependentSimTestCase( name=dotjoin(create_design_unit_name(entity, architecture_name), config.name, "all" if config.name in (None, "") else None), test_case=None, test_bench=create_test_bench(config), has_runner_cfg=has_runner_cfg, pre_config=config.pre_config, post_check=config.post_check, elaborate_only=self._elaborate_only)) elif should_run_in_same_sim: scope = create_scope(entity.library_name, entity.name) configurations = self._cfg.get_configurations(scope) for config in configurations: test_list.add_suite( SameSimTestSuite(name=dotjoin(create_design_unit_name(entity, architecture_name), config.name), test_cases=run_strings, test_bench=create_test_bench(config), pre_config=config.pre_config, post_check=config.post_check, elaborate_only=self._elaborate_only)) else: for run_string in run_strings: scope = create_scope(entity.library_name, entity.name, run_string) configurations = self._cfg.get_configurations(scope) for config in configurations: test_list.add_test( IndependentSimTestCase( name=dotjoin(create_design_unit_name(entity, architecture_name), config.name, run_string), test_case=run_string, test_bench=create_test_bench(config), has_runner_cfg=has_runner_cfg, pre_config=config.pre_config, post_check=config.post_check, elaborate_only=self._elaborate_only))
def test_add_config(self): for value in range(1, 3): self.cfg.add_config(scope=create_scope("lib", "tb_entity"), name="value=%i" % value, generics=dict(value=value, global_value="local value")) self.cfg.add_config(scope=create_scope("lib", "tb_entity", "configured test"), name="specific_test_config", generics=dict()) # Local value should take precedence self.cfg.set_generic("global_value", "global value") self.assertEqual( self.cfg.get_configurations(create_scope("lib", "tb_entity")), [ cfg("value=1", generics={ "value": 1, "global_value": "local value" }), cfg("value=2", generics={ "value": 2, "global_value": "local value" }) ]) self.assertEqual( self.cfg.get_configurations( create_scope("lib", "tb_entity", "test")), [ cfg("value=1", generics={ "value": 1, "global_value": "local value" }), cfg("value=2", generics={ "value": 2, "global_value": "local value" }) ]) self.assertEqual( self.cfg.get_configurations( create_scope("lib", "tb_entity", "configured test")), [cfg("specific_test_config", dict(global_value="global value"))])
def _parse(self, entity, architecture_name, verilog): """ Parse file for run strings and pragmas """ scope = create_scope(entity.library_name, entity.name) other_file = self._cfg.file_to_scan_for_tests(scope) if other_file is not None: file_name = other_file verilog = file_type_of(other_file) == "verilog" elif verilog: file_name = entity.file_name else: file_name = entity.architecture_names[architecture_name] code = ostools.read_file(file_name) pragmas = self.find_pragmas(code, file_name) # @TODO use presence of runner_cfg as tb_filter instead of tb_* has_runner_cfg = verilog or ("runner_cfg" in entity.generic_names) if has_runner_cfg: run_strings = self.find_run_strings(code, file_name, verilog) else: run_strings = [] return pragmas, run_strings
def set_pli(self, value): """ Globally Set pli :param value: A list of PLI object file names """ self._configuration.set_pli(value, scope=create_scope())
def test_sim_options(self): scope = create_scope("lib", "entity") sim_options = {"modelsim.vsim_flags": "-voptargs=+acc"} for name, value in sim_options.items(): self.cfg.set_sim_option(name=name, value=value, scope=scope) self.assertEqual(self.cfg.get_configurations(create_scope("lib")), [cfg()]) self.assertEqual(self.cfg.get_configurations(scope), [cfg(sim_options=sim_options)]) self.assertEqual( self.cfg.get_configurations(create_scope("lib", "entity", "test")), [cfg(sim_options=sim_options)])
def test_set_generic(self): scope = create_scope("lib", "tb_entity") self.assertEqual(self.cfg.get_configurations(scope), [cfg()]) self.cfg.set_generic("global_generic", "global", scope=create_scope()) self.assertEqual(self.cfg.get_configurations(scope), [cfg(generics={"global_generic": "global"})]) self.cfg.set_generic("global_generic", "library", scope=create_scope("lib")) self.assertEqual(self.cfg.get_configurations(scope), [cfg(generics={"global_generic": "library"})]) self.cfg.set_generic("global_generic", "entity", scope=create_scope("lib", "tb_entity")) self.assertEqual(self.cfg.get_configurations(scope), [cfg(generics={"global_generic": "entity"})])
def test_set_pli(self): scope = create_scope("lib", "tb_entity") self.assertEqual(self.cfg.get_configurations(scope), [cfg("")]) self.cfg.set_pli(["libglobal.so"], scope=create_scope()) self.cfg.set_pli(["libfoo.so"], scope=create_scope("lib2")) self.assertEqual(self.cfg.get_configurations(scope), [cfg(pli=["libglobal.so"])]) self.cfg.set_pli(["libfoo.so"], scope=create_scope("lib")) self.assertEqual(self.cfg.get_configurations(scope), [cfg(pli=["libfoo.so"])]) self.cfg.set_pli(["libfoo2.so"], scope=create_scope("lib", "tb_entity")) self.assertEqual(self.cfg.get_configurations(scope), [cfg(pli=["libfoo2.so"])])
def test_sim_options(self): scope = create_scope("lib", "entity") sim_options = {"vsim_extra_args": "-voptargs=+acc"} for name, value in sim_options.items(): self.cfg.set_sim_option(name=name, value=value, scope=scope) self.assertEqual(self.cfg.get_configurations(create_scope("lib")), [cfg()]) self.assertEqual(self.cfg.get_configurations(scope), [cfg(sim_options=sim_options)]) self.assertEqual(self.cfg.get_configurations(create_scope("lib", "entity", "test")), [cfg(sim_options=sim_options)])
def test_config_with_pre_config(self): scope = create_scope("lib", "entity") def pre_config(): return True self.cfg.add_config(name="name", generics=dict(), pre_config=pre_config, scope=scope) self.assertEqual(self.cfg.get_configurations(scope), [cfg("name", pre_config=pre_config)])
def test_disable_ieee_warnings(self): lib_scope = create_scope("lib") ent_scope = create_scope("lib", "entity") self.assertEqual(self.cfg.get_configurations(lib_scope), [cfg(disable_ieee_warnings=False)]) self.assertEqual(self.cfg.get_configurations(ent_scope), [cfg(disable_ieee_warnings=False)]) self.cfg.disable_ieee_warnings(ent_scope) self.assertEqual(self.cfg.get_configurations(lib_scope), [cfg(disable_ieee_warnings=False)]) self.assertEqual(self.cfg.get_configurations(ent_scope), [cfg(disable_ieee_warnings=True)]) self.cfg.disable_ieee_warnings(lib_scope) self.assertEqual(self.cfg.get_configurations(lib_scope), [cfg(disable_ieee_warnings=True)]) self.assertEqual(self.cfg.get_configurations(ent_scope), [cfg(disable_ieee_warnings=True)])
def set_parameter(self, name, value): """ Globally set value of parameter :param name: The name of the parameter :param value: The value of the parameter :example: .. code-block:: python prj.set_parameter("data_width", 16) """ self._configuration.set_generic(name, value, scope=create_scope())
def set_sim_option(self, name, value): """ Globally set simulation option :param name: |simulation_options| :param value: The value of the simulation option :example: .. code-block:: python prj.set_sim_option("ghdl.flags", ["--no-vital-checks"]) """ self._configuration.set_sim_option(name, value, scope=create_scope())
def helper(config_name, suffix): """ Add config with name and check that the test has the given suffix """ project = ProjectStub() lib = project.add_library("lib") lib.add_entity("tb_entity", generic_names=["runner_cfg"]) self.configuration = TestConfiguration() self.test_scanner = TestScanner(self.simulator_if, self.configuration) self.configuration.add_config(scope=create_scope("lib", "tb_entity"), name=config_name, generics=dict()) tests = self.test_scanner.from_project(project) self.assert_has_tests(tests, ["lib.tb_entity" + suffix])
def test_no_post_check_when_elaborate_only(self): self.cfg = TestConfiguration(elaborate_only=True) scope = create_scope("lib", "entity") def pre_config(): return True def post_check(): return True self.cfg.add_config(name="name", generics=dict(), pre_config=pre_config, post_check=post_check, scope=scope) self.assertEqual(self.cfg.get_configurations(scope), [cfg("name", pre_config=pre_config, elaborate_only=True)])
def test_warning_on_configuration_of_individual_test_with_same_sim(self, mock_logger): project = ProjectStub() lib = project.add_library("lib") lib.add_entity("tb_entity", generic_names=["runner_cfg"], contents='''\ if run("Test 1") if run("Test 2") -- vunit_pragma run_all_in_same_sim ''') test_scope = create_scope("lib", "tb_entity", "Test 1") self.configuration.set_generic("name", "value", scope=test_scope) tests = self.test_scanner.from_project(project) warning_calls = mock_logger.warning.call_args_list self.assertEqual(len(warning_calls), 1) call_args = warning_calls[0][0] self.assertIn(1, call_args) self.assertIn("lib.tb_entity", call_args) self.assert_has_tests(tests, [("lib.tb_entity", ("lib.tb_entity.Test 1", "lib.tb_entity.Test 2"))])
def disable_ieee_warnings(self): """ Globally disable ieee warnings """ self._configuration.disable_ieee_warnings(scope=create_scope())
def __init__(self, library_name, parent, project, configuration): self._library_name = library_name self._parent = parent self._project = project self._configuration = configuration self._scope = create_scope(self._library_name)
def test_more_specific_configurations(self): self.cfg.set_generic("name", "value", scope=create_scope("lib", "entity3")) self.cfg.set_generic("name", "value", scope=create_scope("lib", "entity", "test")) self.cfg.disable_ieee_warnings( scope=create_scope("lib", "entity_ieee", "test")) self.cfg.add_config(name="name", generics=dict(), scope=create_scope("lib", "entity2", "test")) self.cfg.set_sim_option("ghdl.flags", [], scope=create_scope("lib", "entity4", "test")) self.assertEqual( self.cfg.more_specific_configurations(create_scope( "lib", "entity")), [create_scope("lib", "entity", "test")]) self.assertEqual( self.cfg.more_specific_configurations( create_scope("lib", "entity2")), [create_scope("lib", "entity2", "test")]) self.assertEqual( self.cfg.more_specific_configurations( create_scope("lib", "entity3")), []) self.assertEqual( self.cfg.more_specific_configurations( create_scope("lib", "entity4")), [create_scope("lib", "entity4", "test")]) self.assertEqual( self.cfg.more_specific_configurations( create_scope("lib", "entity_ieee")), [create_scope("lib", "entity_ieee", "test")])
def test_has_default_configuration(self): scope = create_scope("lib", "tb_entity") self.assertEqual(self.cfg.get_configurations(scope), [cfg()])
def test_issue_65(self): self.cfg.set_generic(name="name", value=1, scope=create_scope()) self.cfg.set_sim_option(name="vsim_extra_args", value="-quiet", scope=create_scope())
def set_generic(self, name, value): """ Globally set generic """ self._configuration.set_generic(name.lower(), value, scope=create_scope())
def set_pli(self, value): """ Globally set pli """ self._configuration.set_pli(value, scope=create_scope())
def test_more_specific_configurations(self): self.cfg.set_generic("name", "value", scope=create_scope("lib", "entity3")) self.cfg.set_generic("name", "value", scope=create_scope("lib", "entity", "test")) self.cfg.disable_ieee_warnings(scope=create_scope("lib", "entity_ieee", "test")) self.cfg.add_config(name="name", generics=dict(), scope=create_scope("lib", "entity2", "test")) self.cfg.set_sim_option("vsim_extra_args", "", scope=create_scope("lib", "entity4", "test")) self.assertEqual(self.cfg.more_specific_configurations(create_scope("lib", "entity")), [create_scope("lib", "entity", "test")]) self.assertEqual(self.cfg.more_specific_configurations(create_scope("lib", "entity2")), [create_scope("lib", "entity2", "test")]) self.assertEqual(self.cfg.more_specific_configurations(create_scope("lib", "entity3")), []) self.assertEqual(self.cfg.more_specific_configurations(create_scope("lib", "entity4")), [create_scope("lib", "entity4", "test")]) self.assertEqual(self.cfg.more_specific_configurations(create_scope("lib", "entity_ieee")), [create_scope("lib", "entity_ieee", "test")])
def test_issue_65(self): self.cfg.set_generic(name="name", value=1, scope=create_scope()) self.cfg.set_sim_option(name="modelsim.vsim_flags", value="-quiet", scope=create_scope())
def set_sim_option(self, name, value): """ Globally set simulation option """ self._configuration.set_sim_option(name, value, scope=create_scope())
def __init__(self, library_name, entity_name, test_name, config): self._library_name = library_name self._entity_name = entity_name self._test_name = test_name self._config = config self._scope = create_scope(library_name, entity_name, test_name)