()
| 113 | |
| 114 | |
| 115 | def main(): |
| 116 | args = parse_args() |
| 117 | for opt in ('-w', '--rerun', '--verbose2'): |
| 118 | if opt in args.test_args: |
| 119 | print(f"WARNING: {opt} option should not be used to bisect!") |
| 120 | print() |
| 121 | |
| 122 | if args.input: |
| 123 | with open(args.input) as fp: |
| 124 | tests = [line.strip() for line in fp] |
| 125 | else: |
| 126 | tests = list_cases(args) |
| 127 | |
| 128 | print("Start bisection with %s tests" % len(tests)) |
| 129 | print("Test arguments: %s" % format_shell_args(args.test_args)) |
| 130 | print("Bisection will stop when getting %s or less tests " |
| 131 | "(-n/--max-tests option), or after %s iterations " |
| 132 | "(-N/--max-iter option)" |
| 133 | % (args.max_tests, args.max_iter)) |
| 134 | output = write_output(args.output, tests) |
| 135 | print() |
| 136 | |
| 137 | start_time = time.monotonic() |
| 138 | iteration = 1 |
| 139 | try: |
| 140 | while len(tests) > args.max_tests and iteration <= args.max_iter: |
| 141 | ntest = len(tests) |
| 142 | ntest = max(ntest // 2, 1) |
| 143 | subtests = random.sample(tests, ntest) |
| 144 | |
| 145 | print(f"[+] Iteration {iteration}/{args.max_iter}: " |
| 146 | f"run {len(subtests)} tests/{len(tests)}") |
| 147 | print() |
| 148 | |
| 149 | exitcode = run_tests(args, subtests) |
| 150 | |
| 151 | print("ran %s tests/%s" % (ntest, len(tests))) |
| 152 | print("exit", exitcode) |
| 153 | if exitcode: |
| 154 | print("Tests failed: continuing with this subtest") |
| 155 | tests = subtests |
| 156 | output = write_output(args.output, tests) |
| 157 | else: |
| 158 | print("Tests succeeded: skipping this subtest, trying a new subset") |
| 159 | print() |
| 160 | iteration += 1 |
| 161 | except KeyboardInterrupt: |
| 162 | print() |
| 163 | print("Bisection interrupted!") |
| 164 | print() |
| 165 | |
| 166 | print("Tests (%s):" % len(tests)) |
| 167 | for test in tests: |
| 168 | print("* %s" % test) |
| 169 | print() |
| 170 | |
| 171 | if output: |
| 172 | print("Output written into %s" % output) |
searching dependent graphs…