Perform a data-flow analysis test case.
(self, testcase: DataDrivenTestCase)
| 30 | optional_out = True |
| 31 | |
| 32 | def run_case(self, testcase: DataDrivenTestCase) -> None: |
| 33 | """Perform a data-flow analysis test case.""" |
| 34 | |
| 35 | with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase): |
| 36 | try: |
| 37 | ir = build_ir_for_single_file(testcase.input) |
| 38 | except CompileError as e: |
| 39 | actual = e.messages |
| 40 | else: |
| 41 | actual = [] |
| 42 | for fn in ir: |
| 43 | if fn.name == TOP_LEVEL_NAME and not testcase.name.endswith("_toplevel"): |
| 44 | continue |
| 45 | exceptions.insert_exception_handling(fn, True) |
| 46 | actual.extend(format_func(fn)) |
| 47 | cfg = dataflow.get_cfg(fn.blocks) |
| 48 | args: set[Value] = set(fn.arg_regs) |
| 49 | name = testcase.name |
| 50 | if name.endswith("_MaybeDefined"): |
| 51 | # Forward, maybe |
| 52 | analysis_result = dataflow.analyze_maybe_defined_regs(fn.blocks, cfg, args) |
| 53 | elif name.endswith("_Liveness"): |
| 54 | # Backward, maybe |
| 55 | analysis_result = dataflow.analyze_live_regs(fn.blocks, cfg) |
| 56 | elif name.endswith("_MustDefined"): |
| 57 | # Forward, must |
| 58 | analysis_result = dataflow.analyze_must_defined_regs( |
| 59 | fn.blocks, cfg, args, regs=all_values(fn.arg_regs, fn.blocks) |
| 60 | ) |
| 61 | elif name.endswith("_BorrowedArgument"): |
| 62 | # Forward, must |
| 63 | analysis_result = dataflow.analyze_borrowed_arguments(fn.blocks, cfg, args) |
| 64 | else: |
| 65 | assert False, "No recognized _AnalysisName suffix in test case" |
| 66 | |
| 67 | names = generate_names_for_ir(fn.arg_regs, fn.blocks) |
| 68 | |
| 69 | for key in sorted( |
| 70 | analysis_result.before.keys(), key=lambda x: (x[0].label, x[1]) |
| 71 | ): |
| 72 | pre = ", ".join(sorted(names[reg] for reg in analysis_result.before[key])) |
| 73 | post = ", ".join(sorted(names[reg] for reg in analysis_result.after[key])) |
| 74 | actual.append( |
| 75 | "%-8s %-23s %s" % ((key[0].label, key[1]), "{%s}" % pre, "{%s}" % post) |
| 76 | ) |
| 77 | assert_test_output(testcase, actual, "Invalid source code output") |
nothing calls this directly
no test coverage detected