def scan_tests_from_file(self, file_name): """ Scan file for test cases and pragmas """ if not file_exists(file_name): raise ValueError("File %r does not exist" % file_name) def parse(content): """ Parse pragmas and test case names """ pragmas = _find_pragmas(content, file_name) test_case_names = _find_test_cases(content, file_name) return pragmas, test_case_names pragmas, test_case_names = cached("test_bench.parse", parse, file_name, encoding=HDL_FILE_ENCODING, database=self._database) default_config = Configuration(DEFAULT_NAME, self.design_unit) if "fail_on_warning" in pragmas: default_config.set_sim_option("vhdl_assert_stop_level", "warning") self._configs = OrderedDict({default_config.name: default_config}) self._individual_tests = "run_all_in_same_sim" not in pragmas and len(test_case_names) > 0 self.test_cases = [TestCase(name, self.design_unit, self._individual_tests, default_config.copy()) for name in test_case_names]
def test_sim_option_is_not_mutated(self): design_unit = Entity('tb_entity') design_unit.generic_names = ["runner_cfg"] config = Configuration('name', design_unit) options = ["--foo"] config.set_sim_option("ghdl.sim_flags", options) options[0] = "--bar" self.assertEqual(config.sim_options["ghdl.sim_flags"], ["--foo"])
def scan_tests_from_file(self, file_name): """ Scan file for test cases and attributes """ if not file_exists(file_name): raise ValueError("File %r does not exist" % file_name) def parse(content): """ Parse attributes and test case names """ tests, attributes = _find_tests_and_attributes(content, file_name) return tests, attributes tests, attributes = cached("test_bench.parse", parse, file_name, encoding=HDL_FILE_ENCODING, database=self._database, newline='') for attr in attributes: if _is_user_attribute(attr.name): raise RuntimeError("File global attributes are not yet supported: %s in %s line %i" % (attr.name, file_name, attr.location.lineno)) for test in tests: for attr in test.attributes: if attr.name in _VALID_ATTRIBUTES: raise RuntimeError("Attribute %s is global and cannot be associated with test %s: %s line %i" % (attr.name, test.name, file_name, attr.location.lineno)) attribute_names = [attr.name for attr in attributes] default_config = Configuration(DEFAULT_NAME, self.design_unit) if "fail_on_warning" in attribute_names: default_config.set_sim_option("vhdl_assert_stop_level", "warning") self._configs = OrderedDict({default_config.name: default_config}) explicit_tests = [test for test in tests if test.is_explicit] if explicit_tests: # All tests shall be explicit when there are at least one explicit test assert len(tests) == len(explicit_tests) self._implicit_test = None else: # There can only be one implicit test assert len(tests) == 1 self._implicit_test = tests[0] self._individual_tests = "run_all_in_same_sim" not in attribute_names and len(explicit_tests) > 0 self._test_cases = [TestConfigurationVisitor(test, self.design_unit, self._individual_tests, default_config.copy()) for test in explicit_tests]
def scan_tests_from_file(self, file_name): """ Scan file for test cases and pragmas """ if not file_exists(file_name): raise ValueError("File %r does not exist" % file_name) def parse(content): """ Parse pragmas and test case names """ pragmas = _find_pragmas(content, file_name) tests = _find_tests(content, file_name) return pragmas, tests pragmas, tests = cached("test_bench.parse", parse, file_name, encoding=HDL_FILE_ENCODING, database=self._database) default_config = Configuration(DEFAULT_NAME, self.design_unit) if "fail_on_warning" in pragmas: default_config.set_sim_option("vhdl_assert_stop_level", "warning") self._configs = OrderedDict({default_config.name: default_config}) explicit_tests = [test for test in tests if test.is_explicit] if explicit_tests: # All tests shall be explicit when there are at least one explicit test assert len(tests) == len(explicit_tests) self._implicit_test = None else: # There can only be one implicit test assert len(tests) == 1 self._implicit_test = tests[0] self._individual_tests = "run_all_in_same_sim" not in pragmas and len( explicit_tests) > 0 self._test_cases = [ TestConfigurationVisitor(test, self.design_unit, self._individual_tests, default_config.copy()) for test in explicit_tests ]
def scan_tests_from_file(self, file_name): """ Scan file for test cases and pragmas """ if not ostools.file_exists(file_name): raise ValueError("File %r does not exist" % file_name) code = ostools.read_file(file_name) pragmas = _find_pragmas(code, file_name) default_config = Configuration(DEFAULT_NAME, self.design_unit) if "fail_on_warning" in pragmas: default_config.set_sim_option("vhdl_assert_stop_level", "warning") self._configs = OrderedDict({default_config.name: default_config}) test_case_names = _find_test_cases(code, file_name) self._individual_tests = "run_all_in_same_sim" not in pragmas and len( test_case_names) > 0 self.test_cases = [ TestCase(name, self.design_unit, self._individual_tests, default_config.copy()) for name in test_case_names ]
def scan_tests_from_file(self, file_name): """ Scan file for test cases and attributes """ if not file_exists(file_name): raise ValueError("File %r does not exist" % file_name) def parse(content): """ Parse attributes and test case names """ tests, attributes = _find_tests_and_attributes(content, file_name) return tests, attributes tests, attributes = cached("test_bench.parse", parse, file_name, encoding=HDL_FILE_ENCODING, database=self._database, newline='') for attr in attributes: if _is_user_attribute(attr.name): raise RuntimeError( "File global attributes are not yet supported: %s in %s line %i" % (attr.name, file_name, attr.location.lineno)) for test in tests: for attr in test.attributes: if attr.name in _VALID_ATTRIBUTES: raise RuntimeError( "Attribute %s is global and cannot be associated with test %s: %s line %i" % (attr.name, test.name, file_name, attr.location.lineno)) attribute_names = [attr.name for attr in attributes] default_config = Configuration(DEFAULT_NAME, self.design_unit) if "fail_on_warning" in attribute_names: default_config.set_sim_option("vhdl_assert_stop_level", "warning") self._configs = OrderedDict({default_config.name: default_config}) explicit_tests = [test for test in tests if test.is_explicit] if explicit_tests: # All tests shall be explicit when there are at least one explicit test assert len(tests) == len(explicit_tests) self._implicit_test = None else: # There can only be one implicit test assert len(tests) == 1 self._implicit_test = tests[0] self._individual_tests = "run_all_in_same_sim" not in attribute_names and len( explicit_tests) > 0 self._test_cases = [ TestConfigurationVisitor(test, self.design_unit, self._individual_tests, default_config.copy()) for test in explicit_tests ]