Esempio n. 1
0
    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]
Esempio n. 2
0
 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"])
Esempio n. 3
0
    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]
Esempio n. 4
0
    def test_adds_tb_path_generic(self):
        design_unit = Entity('tb_entity_with_tb_path')
        design_unit.generic_names = ["runner_cfg"]
        config = Configuration('name', design_unit)

        design_unit_tb_path = Entity('tb_entity_without_tb_path')
        design_unit_tb_path.generic_names = ["runner_cfg", "tb_path"]
        config_tb_path = Configuration('name', design_unit_tb_path)

        self.assertEqual(config_tb_path.generics["tb_path"],
                         (out() + "/").replace("\\", "/"))
        self.assertNotIn("tb_path", config.generics)
Esempio n. 5
0
    def test_warning_on_setting_missing_generic(self, mock_logger):
        design_unit = Entity('tb_entity')
        design_unit.generic_names = ["runner_cfg"]
        config = Configuration('name', design_unit)

        config.set_generic("name123", "value123")
        warning_calls = mock_logger.warning.call_args_list
        self.assertEqual(len(warning_calls), 1)
        call_args = warning_calls[0][0]
        self.assertIn("lib", call_args)
        self.assertIn("tb_entity", call_args)
        self.assertIn("name123", call_args)
        self.assertIn("value123", call_args)
Esempio n. 6
0
    def test_elaborate_e_project(self):
        design_unit = Entity("tb_entity", file_name=str(Path("tempdir") / "file.vhd"))
        design_unit.original_file_name = str(Path("tempdir") / "other_path" / "original_file.vhd")
        design_unit.generic_names = ["runner_cfg", "tb_path"]

        config = Configuration("name", design_unit, sim_options={"ghdl.elab_e": True})

        simif = GHDLInterface(prefix="prefix", output_path="")
        simif._vhdl_standard = VHDL.standard("2008")  # pylint: disable=protected-access
        simif._project = Project()  # pylint: disable=protected-access
        simif._project.add_library("lib", "lib_path")  # pylint: disable=protected-access

        self.assertEqual(
            simif._get_command(  # pylint: disable=protected-access
                config, str(Path("output_path") / "ghdl"), True, True, None
            ),
            [
                str(Path("prefix") / "ghdl"),
                "-e",
                "--std=08",
                "--work=lib",
                "--workdir=lib_path",
                "-Plib_path",
                "-o",
                str(Path("output_path") / "ghdl" / "tb_entity-arch"),
                "tb_entity",
                "arch",
            ],
        )
Esempio n. 7
0
 def test_adds_tb_path_generic(self, tempdir):
     design_unit_tb_path = Entity('tb_entity_without_tb_path',
                                  file_name=join(tempdir, "file.vhd"))
     design_unit_tb_path.generic_names = ["runner_cfg", "tb_path"]
     config_tb_path = Configuration('name', design_unit_tb_path)
     self.assertEqual(config_tb_path.generics["tb_path"],
                      (tempdir + "/").replace("\\", "/"))
Esempio n. 8
0
    def test_error_on_setting_illegal_value_sim_option(self):
        design_unit = Entity('tb_entity')
        design_unit.generic_names = ["runner_cfg"]
        config = Configuration('name', design_unit)

        self.assertRaises(ValueError, config.set_sim_option,
                          "vhdl_assert_stop_level", "illegal")
Esempio n. 9
0
    def test_elaborate_e_project(self):
        design_unit = Entity('tb_entity', file_name=join("tempdir", "file.vhd"))
        design_unit.original_file_name = join("tempdir", "other_path", "original_file.vhd")
        design_unit.generic_names = ["runner_cfg", "tb_path"]

        config = Configuration("name", design_unit, sim_options={"ghdl.elab_e": True})

        simif = GHDLInterface(prefix="prefix", output_path="")
        simif._vhdl_standard = VHDL.standard("2008")  # pylint: disable=protected-access
        simif._project = Project()  # pylint: disable=protected-access
        simif._project.add_library("lib", "lib_path")  # pylint: disable=protected-access

        self.assertEqual(
            simif._get_command(config, join('output_path', 'ghdl'), True),  # pylint: disable=protected-access
            [
                join('prefix', 'ghdl'),
                '-e',
                '--std=08',
                '--work=lib',
                '--workdir=lib_path',
                '-Plib_path',
                '-o', join('output_path', 'ghdl', 'tb_entity-arch'),
                'tb_entity', 'arch'
            ]
        )
Esempio n. 10
0
    def test_error_on_setting_unknown_sim_option(self):
        design_unit = Entity('tb_entity')
        design_unit.generic_names = ["runner_cfg"]
        config = Configuration('name', design_unit)

        self.assertRaises(ValueError, config.set_sim_option, "name123",
                          "value123")
Esempio n. 11
0
 def test_adds_tb_path_generic(self, tempdir):
     design_unit_tb_path = Entity("tb_entity_without_tb_path", file_name=str(Path(tempdir) / "file.vhd"))
     tb_path = str(Path(tempdir) / "other_path")
     design_unit_tb_path.original_file_name = str(Path(tb_path) / "original_file.vhd")
     design_unit_tb_path.generic_names = ["runner_cfg", "tb_path"]
     config_tb_path = Configuration("name", design_unit_tb_path)
     self.assertEqual(config_tb_path.generics["tb_path"], (tb_path + "/").replace("\\", "/"))
Esempio n. 12
0
def _create_config(**kwargs):
    """
    Helper function to create a config
    """
    with create_tempdir() as tempdir:
        design_unit = Entity("tb_entity", file_name=str(Path(tempdir) / "file.vhd"))
        design_unit.generic_names = ["runner_cfg"]
        yield Configuration("name", design_unit, **kwargs)
Esempio n. 13
0
    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
        ]
Esempio n. 14
0
def _create_config(**kwargs):
    """
    Helper function to create a config
    """
    with create_tempdir() as tempdir:
        design_unit = Entity('tb_entity', file_name=join(tempdir, "file.vhd"))
        design_unit.generic_names = ["runner_cfg"]
        yield Configuration('name', design_unit, **kwargs)
Esempio n. 15
0
    def discover_cocotb_tests(self, cocotb_module, cocotb_module_location):
        """
        Discover tests defined in a cocotb module and 
        """
        self._cocotb_module = cocotb_module        
        tests = []
        #Iterate every value in the module looking for cocotb tests
        for obj_name in dir(cocotb_module):
            obj = getattr(cocotb_module, obj_name)
            if isinstance(obj, Test):
                tests.append(CocoTest(obj.__name__, self.design_unit, cocotb_module, cocotb_module_location))

        default_config = Configuration(DEFAULT_NAME, self.design_unit)                  
        self._test_cases = [
            CocoTestConfigurationVisitor(test, self.design_unit, True, default_config.copy())
            for test in tests
        ]

        self._configs = OrderedDict({default_config.name: default_config})
Esempio n. 16
0
    def test_error_on_setting_unknown_sim_option(self, mock_logger):
        design_unit = Entity('tb_entity')
        design_unit.generic_names = ["runner_cfg"]
        config = Configuration('name', design_unit)

        self.assertRaises(ValueError, config.set_sim_option, "name123",
                          "value123")
        error_calls = mock_logger.error.call_args_list
        self.assertEqual(len(error_calls), 1)
        call_args = error_calls[0][0]
        self.assertIn("name123", call_args)
Esempio n. 17
0
    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
        ]
Esempio n. 18
0
    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
        ]