Example #1
0
 def run_pp_by_methodname(self):
     test_name = self.getTestName()
     c = HdlConvertor()
     c.verilog_pp(
         path.join(path.dirname(__file__), 'sv_pp', 'raw',
                   test_name + '.txt'),
         ['.', '..', path.join('sv_pp', 'raw')], SV)
 def test_verilog_pp_Language_is_bad(self):
     with self.assertRaises(ValueError) as context:
         c = HdlConvertor()
         c.verilog_pp("", "badlang", [])
     e = str(context.exception)
     self.assertIn(
         "'badlang' is not recognized (expected hdlConvertor.language.Language value)", e)
Example #3
0
 def assertPPError(self, file, err_msg):
     with self.assertRaises(ParseException) as context:
         f = path.join(TEST_DIR, 'sv_pp', 'src', file)
         c = HdlConvertor()
         c.verilog_pp(
             f,
             ['.', '..', path.join('sv_pp', 'src')],
             SV
         )
     self.assertEqual(err_msg, context.exception.__str__())
def _test_run(test_file, golden_file, golden_str):
    c = HdlConvertor()

    incdirs = [
        path.join('sv_pp', 'src'),
    ]

    with cd(TEST_DIR):
        # cd to have nice paths in error messages
        test_result = c.verilog_pp(test_file, Language.SYSTEM_VERILOG, incdirs)
        # windows compatiblity
        test_result = test_result.replace("sv_pp\\\\src\\\\", "sv_pp/src/")

    # with open(os.path.join(TEST_DIR, golden_file), "w") as f:
    #     f.write(test_result)

    if golden_file is not None:
        assert golden_str is None
        with open(os.path.join(TEST_DIR, golden_file)) as f:
            test_golden = f.read()
    else:
        assert golden_str is not None
        test_golden = golden_str

    return test_result, test_golden
Example #5
0
 def test_verilog_pp_Language_is_bad(self):
     with self.assertRaises(ValueError) as context:
         c = HdlConvertor()
         test_result = c.verilog_pp("", "", "badlang")
     e = str(context.exception)
     self.assertIn("badlang is not recognized (expected <enum 'Language'>)",
                   e)
Example #6
0
 def run_pp_by_methodname(self):
     test_name = self.getTestName()
     c = HdlConvertor()
     f = path.join(path.dirname(__file__), 'sv_pp', 'raw', test_name + '.txt')
     incdirs = [path.join('sv_pp', 'raw'), ]
     res = c.verilog_pp(f, Language.SYSTEM_VERILOG, incdirs)
     return res
Example #7
0
def _test_run(test_file, golden_file):
    c = HdlConvertor()
    test_result = c.verilog_pp(path.join(
        TEST_DIR, test_file), ['.', '..', path.join('sv_pp', 'src')], SV)
    with open(path.join(TEST_DIR, golden_file), 'r') as myfile:
        test_golden = myfile.read()
    myfile.close()
    return test_result, test_golden
Example #8
0
 def assertPPError(self, file, err_msg, contains=False):
     with self.assertRaises(ParseException) as context:
         f = path.join(TEST_DIR, 'sv_pp', 'src', file)
         c = HdlConvertor()
         c.verilog_pp(f, [
             path.join('sv_pp', 'src'),
         ], SV)
     e = str(context.exception)
     if contains:
         self.assertIn(err_msg, e)
     else:
         self.assertGreaterEqual(len(e), len(err_msg))
         _e = e[-len(err_msg):]
         if err_msg != _e:
             # print whole error if there is some problem
             self.assertEqual(err_msg, e)
         else:
             self.assertEqual(err_msg, _e)
Example #9
0
def _test_run(test_file, golden_file):
    c = HdlConvertor()

    incdirs = ['.', '..', path.join('sv_pp', 'src')]
    test_result = c.verilog_pp(
        test_file, incdirs, SV)

    with open(golden_file) as myfile:
        test_golden = myfile.read()

    return test_result, test_golden
Example #10
0
 def test_FILE_LINE(self):
     c = HdlConvertor()
     test_result = c.verilog_pp(
         path.join(path.dirname(__file__), 'sv_pp', 'src',
                   'test_FILE_LINE.sv'),
         ['.', '..', path.join('sv_pp', 'src')], SV)
     test_golden = "module tb();\n\ninitial\n\t$display(\"Internal error: null handle at %s, line %d.\",\n"
     test_golden += "\"" + path.join(
         path.dirname(__file__), 'sv_pp', 'src',
         'test_FILE_LINE.sv') + "\", 5);\n\n\nendmodule\n"
     self.assertEqual(test_result, test_golden)
Example #11
0
 def test_FILE_LINE(self):
     c = HdlConvertor()
     f = path.join(path.dirname(__file__), 'sv_pp', 'src', 'test_FILE_LINE.sv')
     incdirs = ['.', '..', path.join('sv_pp', 'src')]
     test_result = c.verilog_pp(f, incdirs, SV)
     expected_val = path.join(path.dirname(__file__),
                              'sv_pp', 'src', 'test_FILE_LINE.sv'
                              )
     test_golden = ("module tb();\n\ninitial\n\t$display("
                   "\"Internal error: null handle at %s, line %d.\",\n")
     test_golden += "\"" + expected_val + "\", 5);\n\n\nendmodule\n"
     self.assertEqual(test_result, test_golden)
    def run_test(self, file, incdirs):
        c = HdlConvertor()
        if not isinstance(file, list):
            file = [
                file,
            ]
        f = path.join(SRC_DIR, *file)
        res = c.verilog_pp(f, Language.VERILOG, incdirs)
        ref_file = path.join(EXPECTED_DIR, *file)
        with open(ref_file) as exp_f:
            expected = exp_f.read()

        self.assertEqual(res, expected)