예제 #1
0
    def run_case(self, testcase: DataDrivenTestCase) -> None:
        """Perform a runtime checking transformation test case."""
        with use_custom_builtins(
                os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
            expected_output = remove_comment_lines(testcase.output)
            try:
                ir = build_ir_for_single_file(testcase.input)
            except CompileError as e:
                actual = e.messages
            else:
                actual = []
                for fn in ir:
                    if (fn.name == TOP_LEVEL_NAME
                            and not testcase.name.endswith('_toplevel')):
                        continue
                    insert_uninit_checks(fn)
                    insert_exception_handling(fn)
                    insert_ref_count_opcodes(fn)
                    actual.extend(format_func(fn))
                    if testcase.name.endswith('_freq'):
                        common = frequently_executed_blocks(fn.blocks[0])
                        actual.append('hot blocks: %s' %
                                      sorted(b.label for b in common))

            assert_test_output(testcase, actual, 'Invalid source code output',
                               expected_output)
예제 #2
0
    def run_case(self, testcase: DataDrivenTestCase) -> None:
        """Perform a runtime checking transformation test case."""
        options = infer_ir_build_options_from_test_name(testcase.name)
        if options is None:
            # Skipped test case
            return
        with use_custom_builtins(
                os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
            expected_output = remove_comment_lines(testcase.output)
            expected_output = replace_native_int(expected_output)
            expected_output = replace_word_size(expected_output)
            try:
                ir = build_ir_for_single_file(testcase.input, options)
            except CompileError as e:
                actual = e.messages
            else:
                actual = []
                for fn in ir:
                    if (fn.name == TOP_LEVEL_NAME
                            and not testcase.name.endswith('_toplevel')):
                        continue
                    insert_uninit_checks(fn)
                    insert_ref_count_opcodes(fn)
                    actual.extend(format_func(fn))

            assert_test_output(testcase, actual, 'Invalid source code output',
                               expected_output)
    def run_case(self, testcase: DataDrivenTestCase) -> None:
        # Kind of hacky. Not sure if we need more structure here.
        options = CompilerOptions(strip_asserts='StripAssert' in testcase.name)
        """Perform a runtime checking transformation test case."""
        with use_custom_builtins(
                os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
            expected_output = remove_comment_lines(testcase.output)
            expected_output = replace_native_int(expected_output)
            expected_output = replace_word_size(expected_output)
            name = testcase.name
            # If this is specific to some bit width, always pass if platform doesn't match.
            if name.endswith('_64bit') and IS_32_BIT_PLATFORM:
                return
            if name.endswith('_32bit') and not IS_32_BIT_PLATFORM:
                return
            try:
                ir = build_ir_for_single_file(testcase.input, options)
            except CompileError as e:
                actual = e.messages
            else:
                actual = []
                for fn in ir:
                    if (fn.name == TOP_LEVEL_NAME
                            and not name.endswith('_toplevel')):
                        continue
                    actual.extend(format_func(fn))

            assert_test_output(testcase, actual, 'Invalid source code output',
                               expected_output)
예제 #4
0
def assert_func_ir_valid(fn: FuncIR) -> None:
    errors = check_func_ir(fn)
    if errors:
        raise IrCheckException(
            "Internal error: Generated invalid IR: \n"
            + "\n".join(format_func(fn, [(e.source, e.desc) for e in errors])),
        )
예제 #5
0
    def run_case(self, testcase: DataDrivenTestCase) -> None:
        """Perform a data-flow analysis test case."""

        with use_custom_builtins(
                os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
            testcase.output = replace_native_int(testcase.output)
            try:
                ir = build_ir_for_single_file(testcase.input)
            except CompileError as e:
                actual = e.messages
            else:
                actual = []
                for fn in ir:
                    if (fn.name == TOP_LEVEL_NAME
                            and not testcase.name.endswith('_toplevel')):
                        continue
                    exceptions.insert_exception_handling(fn)
                    actual.extend(format_func(fn))
                    cfg = dataflow.get_cfg(fn.blocks)
                    args = set(fn.arg_regs)  # type: Set[Value]
                    name = testcase.name
                    if name.endswith('_MaybeDefined'):
                        # Forward, maybe
                        analysis_result = dataflow.analyze_maybe_defined_regs(
                            fn.blocks, cfg, args)
                    elif name.endswith('_Liveness'):
                        # Backward, maybe
                        analysis_result = dataflow.analyze_live_regs(
                            fn.blocks, cfg)
                    elif name.endswith('_MustDefined'):
                        # Forward, must
                        analysis_result = dataflow.analyze_must_defined_regs(
                            fn.blocks,
                            cfg,
                            args,
                            regs=all_values(fn.arg_regs, fn.blocks))
                    elif name.endswith('_BorrowedArgument'):
                        # Forward, must
                        analysis_result = dataflow.analyze_borrowed_arguments(
                            fn.blocks, cfg, args)
                    else:
                        assert False, 'No recognized _AnalysisName suffix in test case'

                    names = generate_names_for_ir(fn.arg_regs, fn.blocks)

                    for key in sorted(analysis_result.before.keys(),
                                      key=lambda x: (x[0].label, x[1])):
                        pre = ', '.join(
                            sorted(names[reg]
                                   for reg in analysis_result.before[key]))
                        post = ', '.join(
                            sorted(names[reg]
                                   for reg in analysis_result.after[key]))
                        actual.append('%-8s %-23s %s' %
                                      ((key[0].label, key[1]), '{%s}' % pre,
                                       '{%s}' % post))
            assert_test_output(testcase, actual, 'Invalid source code output')
예제 #6
0
 def test_pprint(self) -> None:
     block_1 = self.basic_block([Return(value=NONE_VALUE)])
     goto = Goto(label=block_1)
     block_2 = self.basic_block([goto])
     fn = FuncIR(
         decl=self.func_decl(name="func_1"),
         arg_regs=[],
         # block_1 omitted
         blocks=[block_2],
     )
     errors = [(goto, "Invalid control operation target: 1")]
     formatted = format_func(fn, errors)
     assert formatted == [
         "def func_1():",
         "L0:",
         "    goto L1",
         "  ERR: Invalid control operation target: 1",
     ]