diff options
| author | TheGeogeo <57634077+TheGeogeo@users.noreply.github.com> | 2026-12-02 04:57:39 +0100 |
|---|---|---|
| committer | TheGeogeo <57634077+TheGeogeo@users.noreply.github.com> | 2026-12-02 05:19:44 +0100 |
| commit | fc0ce37ac47d4e0c57308bf24ced4a090ecbe1ea (patch) | |
| tree | df69844db97b36c526650c68fbb61cd515b6ae62 /scripts | |
| parent | 4a0aa701d04616e4b2024f90390f67b2ba576bac (diff) | |
scripts: red_green.py reports a cargo run stopped before any test ran as timed out building, not caught (review)
A mutated cargo run that times out before its first Running line was still a build: it says nothing about the tests, so it is no longer counted as caught by timeout. A stub cargo that hangs in its build or in a test binary now covers the cargo timeout path, which no test reached before.
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/red_green.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/scripts/red_green.py b/scripts/red_green.py index 8d748d534..d487d9315 100644 --- a/scripts/red_green.py +++ b/scripts/red_green.py | |||
| @@ -383,11 +383,11 @@ def cargo_once(tree: Path, crates: list[str], cargo: str, target: Path, timeout: | |||
| 383 | cmd += ["test", "--locked", "--no-fail-fast"] + [a for c in crates for a in ("-p", c)] | 383 | cmd += ["test", "--locked", "--no-fail-fast"] + [a for c in crates for a in ("-p", c)] |
| 384 | env = dict(os.environ, CARGO_TARGET_DIR=str(target)) | 384 | env = dict(os.environ, CARGO_TARGET_DIR=str(target)) |
| 385 | code, out = run_output(cmd, tree / "d3d12", env, timeout) | 385 | code, out = run_output(cmd, tree / "d3d12", env, timeout) |
| 386 | tests, unit, error = {}, "?", None | 386 | tests, unit, error, ran = {}, "?", None, False |
| 387 | for line in out.splitlines(): | 387 | for line in out.splitlines(): |
| 388 | m = UNIT.match(line) | 388 | m = UNIT.match(line) |
| 389 | if m: | 389 | if m: |
| 390 | unit = m.group(1) or "doc:" + m.group(2) | 390 | unit, ran = m.group(1) or "doc:" + m.group(2), True |
| 391 | continue | 391 | continue |
| 392 | m = CARGO_TEST.match(line) | 392 | m = CARGO_TEST.match(line) |
| 393 | if m: | 393 | if m: |
| @@ -396,8 +396,10 @@ def cargo_once(tree: Path, crates: list[str], cargo: str, target: Path, timeout: | |||
| 396 | error = line.strip() | 396 | error = line.strip() |
| 397 | no_build = code is not None and code != 0 and not tests | 397 | no_build = code is not None and code != 0 and not tests |
| 398 | crash = COMPILER_CRASH.search(out) if no_build else None | 398 | crash = COMPILER_CRASH.search(out) if no_build else None |
| 399 | # Stopped by the timeout: while building (no test binary had started) or while running the tests. | ||
| 400 | timed_out = None if code is not None else "running" if ran else "building" | ||
| 399 | return {"tests": tests, "no_build": (error or f"cargo exit {code}") if no_build and not crash else None, | 401 | return {"tests": tests, "no_build": (error or f"cargo exit {code}") if no_build and not crash else None, |
| 400 | "crash": next(g for g in crash.groups() if g) if crash else None, "timed_out": code is None} | 402 | "crash": next(g for g in crash.groups() if g) if crash else None, "timed_out": timed_out} |
| 401 | 403 | ||
| 402 | 404 | ||
| 403 | def cargo_tests(tree: Path, crates: list[str], cargo: str, target: Path, timeout: float | None) -> dict: | 405 | def cargo_tests(tree: Path, crates: list[str], cargo: str, target: Path, timeout: float | None) -> dict: |
| @@ -436,14 +438,15 @@ def drop_bytecode(tree: Path) -> None: | |||
| 436 | 438 | ||
| 437 | 439 | ||
| 438 | def python_tests(tree: Path, files: list[str], timeout: float | None) -> dict: | 440 | def python_tests(tree: Path, files: list[str], timeout: float | None) -> dict: |
| 439 | tests, no_build, timed_out = {}, [], False | 441 | tests, no_build, timed_out = {}, [], None |
| 440 | drop_bytecode(tree) | 442 | drop_bytecode(tree) |
| 441 | for f in files: | 443 | for f in files: |
| 442 | start = "tests/semantic" if f.startswith("tests/semantic/") else str(Path(f).parent) | 444 | start = "tests/semantic" if f.startswith("tests/semantic/") else str(Path(f).parent) |
| 443 | # -B only stops writing bytecode, not reading it: drop_bytecode() above keeps stale bytecode out. | 445 | # -B only stops writing bytecode, not reading it: drop_bytecode() above keeps stale bytecode out. |
| 444 | code, out = run_output([sys.executable, "-I", "-B", "-m", "unittest", "discover", "-s", start, | 446 | code, out = run_output([sys.executable, "-I", "-B", "-m", "unittest", "discover", "-s", start, |
| 445 | "-p", Path(f).name, "-v"], tree, timeout=timeout) | 447 | "-p", Path(f).name, "-v"], tree, timeout=timeout) |
| 446 | timed_out |= code is None | 448 | if code is None: |
| 449 | timed_out = "running" | ||
| 447 | found = 0 | 450 | found = 0 |
| 448 | for name, where, status in PY_TEST.findall(out): | 451 | for name, where, status in PY_TEST.findall(out): |
| 449 | if "_FailedTest" in where: | 452 | if "_FailedTest" in where: |
| @@ -460,9 +463,10 @@ def python_tests(tree: Path, files: list[str], timeout: float | None) -> dict: | |||
| 460 | def side(tree: Path, crates: list[str], py_files: list[str], cargo: str, target: Path, | 463 | def side(tree: Path, crates: list[str], py_files: list[str], cargo: str, target: Path, |
| 461 | timeout: float | None = None) -> dict: | 464 | timeout: float | None = None) -> dict: |
| 462 | """The tests of one side: the crates, and those of the Python test files that this tree has. With a timeout (the | 465 | """The tests of one side: the crates, and those of the Python test files that this tree has. With a timeout (the |
| 463 | mutated runs), a command that runs past it is stopped and the side is marked `timed_out`.""" | 466 | mutated runs), a command that runs past it is stopped and `timed_out` says when: "building" (cargo, before any |
| 467 | test binary ran) or "running".""" | ||
| 464 | py_files = [f for f in py_files if (tree / f).is_file()] | 468 | py_files = [f for f in py_files if (tree / f).is_file()] |
| 465 | result = {"tests": {}, "no_build": [], "compiler_crashed": None, "rerun_after": None, "timed_out": False} | 469 | result = {"tests": {}, "no_build": [], "compiler_crashed": None, "rerun_after": None, "timed_out": None} |
| 466 | for part in ([cargo_tests(tree, crates, cargo, target, timeout)] if crates else []) + \ | 470 | for part in ([cargo_tests(tree, crates, cargo, target, timeout)] if crates else []) + \ |
| 467 | ([python_tests(tree, py_files, timeout)] if py_files else []): | 471 | ([python_tests(tree, py_files, timeout)] if py_files else []): |
| 468 | result["tests"].update(part["tests"]) | 472 | result["tests"].update(part["tests"]) |
| @@ -576,8 +580,8 @@ def main(argv: list[str] | None = None) -> int: | |||
| 576 | help="undo each code hunk alone on green and run the tests again (caught or not)") | 580 | help="undo each code hunk alone on green and run the tests again (caught or not)") |
| 577 | p.add_argument("--mutate-max", type=int, default=10, help="the most hunks --mutate tries (10)") | 581 | p.add_argument("--mutate-max", type=int, default=10, help="the most hunks --mutate tries (10)") |
| 578 | p.add_argument("--mutate-timeout", type=float, default=600, metavar="SECONDS", | 582 | p.add_argument("--mutate-timeout", type=float, default=600, metavar="SECONDS", |
| 579 | help="stop a command of a mutated run (cargo test, one Python test file) after this long and count " | 583 | help="stop a command of a mutated run (cargo test, one Python test file) after this long: the hunk " |
| 580 | "the hunk as caught by timeout (600)") | 584 | "is caught by timeout, or timed out building if cargo had not started a test (600)") |
| 581 | a = p.parse_args(argv) | 585 | a = p.parse_args(argv) |
| 582 | try: | 586 | try: |
| 583 | repo = Path(git(Path.cwd(), "rev-parse", "--show-toplevel")) | 587 | repo = Path(git(Path.cwd(), "rev-parse", "--show-toplevel")) |
| @@ -727,6 +731,8 @@ def mutate(tree: Path, green: str, hunks: list[tuple[str, int, str]], targets: l | |||
| 727 | entry["result"] = "compiler crashed" | 731 | entry["result"] = "compiler crashed" |
| 728 | elif any(s["tests"].get(t) == "failed" for t in targets): | 732 | elif any(s["tests"].get(t) == "failed" for t in targets): |
| 729 | entry["result"] = "caught" | 733 | entry["result"] = "caught" |
| 734 | elif s["timed_out"] == "building": # no answer: the build was too slow, or the undone code made it hang | ||
| 735 | entry["result"] = "timed out building" | ||
| 730 | elif s["timed_out"]: | 736 | elif s["timed_out"]: |
| 731 | entry["result"] = "caught by timeout" | 737 | entry["result"] = "caught by timeout" |
| 732 | elif not any(t in s["tests"] for t in targets): | 738 | elif not any(t in s["tests"] for t in targets): |