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 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. 3
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. 4
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. 5
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. 6
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
        ]