Example #1
0
    def run_sim(self, vhdl_standard):
        output_path = join(dirname(abspath(__file__)), 'check_out')
        vhdl_path = join(dirname(abspath(__file__)), '..', 'vhdl', 'check',
                         'test')

        ui = VUnit(clean=True,
                   output_path=output_path,
                   vhdl_standard=vhdl_standard,
                   compile_builtins=False)

        ui.add_builtins('vunit_lib', mock_log=True)
        ui.add_library(r'lib')
        ui.add_source_files(join(vhdl_path, "test_support.vhd"), 'lib')
        if vhdl_standard in ('2002', '2008'):
            ui.add_source_files(join(vhdl_path, "test_count.vhd"), 'lib')
            ui.add_source_files(join(vhdl_path, "test_types.vhd"), 'lib')
        elif vhdl_standard == '93':
            ui.add_source_files(join(vhdl_path, "test_count93.vhd"), 'lib')

        if vhdl_standard == '2008':
            ui.add_source_files(join(vhdl_path, "tb_check_relation.vhd"),
                                'lib', [CheckPreprocessor()])
        else:
            ui.add_source_files(
                join(vhdl_path, "tb_check_relation93_2002.vhd"), 'lib',
                [CheckPreprocessor()])

        for file_name in glob(join(vhdl_path, "tb_*.vhd")):
            if basename(file_name) == "tb_check_relation.vhd":
                continue
            ui.add_source_files(file_name, 'lib')

        try:
            ui.main()
        except SystemExit as e:
            self.assertEqual(e.code, 0)
Example #2
0
 def setUp(self):
     self._check_preprocessor = CheckPreprocessor()
Example #3
0
class TestCheckPreprocessor(unittest.TestCase):
    """
    Test the check preprocessor
    """

    def setUp(self):
        self._check_preprocessor = CheckPreprocessor()

    def _verify_result(self, code, expected_result):
        """
        Assert that the code after preprocessing is equal to the expected_result
        """
        result = self._check_preprocessor.run(code, 'foo.vhd')
        self.assertEqual(result, expected_result)

    def test_that_only_relation_checks_are_preprocessed_so_that_parsing_is_simplified(self):
        code = """
check_relation(a /= b);
check(a /= b or c); -- Same as (a /= b) or c. Not a relation
"""
        expected_result = """
check_relation(a /= b, context_msg => %s);
check(a /= b or c); -- Same as (a /= b) or c. Not a relation
""" % make_context_msg('a', '/=', 'b')

        self._verify_result(code, expected_result)

    def test_that_generated_message_is_combined_with_a_custom_message(self):
        code = """
check_relation(age("John") >= 0, "Age must not be negative.");
"""
        expected_result = """
check_relation(age("John") >= 0, "Age must not be negative.", context_msg => %s);
""" % make_context_msg('age("John")', '>=', '0')

        self._verify_result(code, expected_result)

    def test_that_the_top_level_relation_is_correctly_identified_as_the_main_relation(self):
        code = """
check_relation(foo(a > b) = c);
check_relation((a > b) = c);
check_relation(a > (b = c));
check_relation(( (a > b))  );"""

        expected_result = """
check_relation(foo(a > b) = c, context_msg => %s);
check_relation((a > b) = c, context_msg => %s);
check_relation(a > (b = c), context_msg => %s);
check_relation(( (a > b))  , context_msg => %s);""" % (make_context_msg('foo(a > b)', '=', 'c'),
                                                       make_context_msg('(a > b)', '=', 'c'),
                                                       make_context_msg('a', '>', '(b = c)'),
                                                       make_context_msg('a', '>', 'b'))

        self._verify_result(code, expected_result)

    def test_that_parsing_is_not_fooled_by_strings_containing_characters_relevant_to_parsing(self):
        code = """
check_relation(41 = ascii(')'), "Incorrect ascii for ')'");
check_relation(9 = len("Smile :-)"), "Incorrect length of :-) message");
check_relation(8 = len("Heart => <3"), "Incorrect length of <3 message");
check_relation(a = integer'(9), "This wasn't expected");
check_relation(a = std_logic'('1'), "This wasn't expected");
check_relation(a = func('(','x'), "This wasn't expected");
check_relation(a = std_logic'('1'+'1'), "This wasn't expected");
check_relation(39 = ascii('''), "Incorrect ascii for '''");
check_relation(byte'high = 7);"""

        expected_result = """
check_relation(41 = ascii(')'), "Incorrect ascii for ')'", context_msg => %s);
check_relation(9 = len("Smile :-)"), "Incorrect length of :-) message", context_msg => %s);
check_relation(8 = len("Heart => <3"), "Incorrect length of <3 message", context_msg => %s);
check_relation(a = integer'(9), "This wasn't expected", context_msg => %s);
check_relation(a = std_logic'('1'), "This wasn't expected", context_msg => %s);
check_relation(a = func('(','x'), "This wasn't expected", context_msg => %s);
check_relation(a = std_logic'('1'+'1'), "This wasn't expected", context_msg => %s);
check_relation(39 = ascii('''), "Incorrect ascii for '''", context_msg => %s);
check_relation(byte'high = 7, context_msg => %s);""" % (make_context_msg('41', '=', "ascii(')')"),
                                                        make_context_msg('9', '=', 'len("Smile :-)")'),
                                                        make_context_msg('8', '=', 'len("Heart => <3")'),
                                                        make_context_msg('a', '=', "integer'(9)"),
                                                        make_context_msg('a', '=', "std_logic'('1')"),
                                                        make_context_msg('a', '=', "func('(','x')"),
                                                        make_context_msg('a', '=', "std_logic'('1'+'1')"),
                                                        make_context_msg('39', '=', "ascii(''')"),
                                                        make_context_msg("byte'high", '=', '7'))

        self._verify_result(code, expected_result)

    def test_that_parsing_is_not_fooled_by_embedded_comments(self):
        code = """
check_relation(42 = -- Meaning of life :-)
               hex(66));
check_relation(42 = /* Meaning of
                       life :-) */
               hex(66));
"""
        expected_result = """
check_relation(42 = -- Meaning of life :-)
               hex(66), context_msg => %s);
check_relation(42 = /* Meaning of
                       life :-) */
               hex(66), context_msg => %s);
""" % (make_context_msg('42', '=', 'hex(66)'), make_context_msg('42', '=', 'hex(66)'))

        self._verify_result(code, expected_result)

    def test_that_a_call_without_a_relational_operator_raises_an_error(self):
        code = """
check_relation(a + b - c);
"""
        self.assertRaises(SyntaxError, self._check_preprocessor.run, code, 'foo.vhd')

    def test_that_multiple_parameters_can_be_given(self):
        code = """
check_relation(a = b, level => warning);
check_relation(my_checker, a = b);
check_relation(msg => "Error!", expr => a('<') = b);"""

        expected_result = """
check_relation(a = b, level => warning, context_msg => %s);
check_relation(my_checker, a = b, context_msg => %s);
check_relation(msg => "Error!", expr => a('<') = b, context_msg => %s);""" % (make_context_msg('a', '=', 'b'),
                                                                              make_context_msg('a', '=', 'b'),
                                                                              make_context_msg("a('<')", '=', 'b'))

        self._verify_result(code, expected_result)

    def test_that_all_vhdl_2008_relational_operators_are_recognized(self):
        code = """
check_relation(a = b);
check_relation(a /= b);
check_relation(a < b);
check_relation(a <= b);
check_relation(a > b);
check_relation(a >= b);
check_relation(a ?= b);
check_relation(a ?/= b);
check_relation(a ?< b);
check_relation(a ?<= b);
check_relation(a ?> b);
check_relation(a ?>= b);"""

        expected_result = """
check_relation(a = b, context_msg => %s);
check_relation(a /= b, context_msg => %s);
check_relation(a < b, context_msg => %s);
check_relation(a <= b, context_msg => %s);
check_relation(a > b, context_msg => %s);
check_relation(a >= b, context_msg => %s);
check_relation(a ?= b, context_msg => %s);
check_relation(a ?/= b, context_msg => %s);
check_relation(a ?< b, context_msg => %s);
check_relation(a ?<= b, context_msg => %s);
check_relation(a ?> b, context_msg => %s);
check_relation(a ?>= b, context_msg => %s);""" % (make_context_msg("a", '=', 'b'),
                                                  make_context_msg("a", '/=', 'b'),
                                                  make_context_msg("a", '<', 'b'),
                                                  make_context_msg("a", '<=', 'b'),
                                                  make_context_msg("a", '>', 'b'),
                                                  make_context_msg("a", '>=', 'b'),
                                                  make_context_msg("a", '?=', 'b'),
                                                  make_context_msg("a", '?/=', 'b'),
                                                  make_context_msg("a", '?<', 'b'),
                                                  make_context_msg("a", '?<=', 'b'),
                                                  make_context_msg("a", '?>', 'b'),
                                                  make_context_msg("a", '?>=', 'b'))
        self._verify_result(code, expected_result)
Example #4
0
generate_check_match.main()

VU = VUnit.from_argv()

LIB = VU.add_library("lib")
LIB.add_source_files(
    Path(ROOT) / "vunit" / "vhdl" / "check" / "test" / "test_support.vhd"
)
VU.add_library("logging_tb_lib").add_source_files(
    Path(ROOT) / "vunit" / "vhdl" / "logging" / "test" / "test_support_pkg.vhd"
)

for file_name in glob(
    str(Path(ROOT) / "vunit" / "vhdl" / "check" / "test" / "tb_*.vhd")
):
    if VU.vhdl_standard not in ["2008", "2019"] and file_name.endswith("2008p.vhd"):
        continue

    if Path(file_name).name.startswith("tb_check_relation"):
        LIB.add_source_files(file_name, preprocessors=[CheckPreprocessor()])
    else:
        LIB.add_source_files(file_name)

TB_CHECK = LIB.entity("tb_check")
TB_CHECK.add_config(generics=dict(use_check_not_check_true=True), name="using check")
TB_CHECK.add_config(
    generics=dict(use_check_not_check_true=False), name="using check_true"
)

VU.main()
Example #5
0
 def enable_check_preprocessing(self):
     """
     Enable check preprocessing, must be called before adding any files
     """
     self._check_preprocessor = CheckPreprocessor()
Example #6
0
File: run.py Project: tivaliy/vunit
vhdl_path = join(dirname(__file__), "test")
ui = VUnit.from_argv(compile_builtins=False)
ui.add_builtins('vunit_lib', mock_log=True)
lib = ui.add_library('lib')
lib.add_source_files(join(vhdl_path, "test_support.vhd"))

if ui.vhdl_standard in ('2002', '2008'):
    lib.add_source_files(join(vhdl_path, "test_count.vhd"))
    lib.add_source_files(join(vhdl_path, "test_types.vhd"))
elif ui.vhdl_standard == '93':
    lib.add_source_files(join(vhdl_path, "test_count93.vhd"))

if ui.vhdl_standard == '2008':
    lib.add_source_files(join(vhdl_path, "tb_check_relation.vhd"),
                         [CheckPreprocessor()])
else:
    lib.add_source_files(join(vhdl_path, "tb_check_relation93_2002.vhd"),
                         [CheckPreprocessor()])

for file_name in glob(join(vhdl_path, "tb_*.vhd")):
    if basename(file_name).startswith("tb_check_relation"):
        continue
    lib.add_source_files(file_name)

tb_check = lib.entity("tb_check")
tb_check.add_config(generics=dict(use_check_not_check_true=True),
                    name="using check")
tb_check.add_config(generics=dict(use_check_not_check_true=False),
                    name="using check_true")
 def setUp(self):
     self._check_preprocessor = CheckPreprocessor()
     self.maxDiff = None