diff options
| author | MoonEyes <ducoinbenjamin@yahoo.fr> | 2026-12-01 15:06:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-12-01 15:06:18 +0100 |
| commit | b3910e5e3d6fdc3a77e84b8c7544cd27ed677d51 (patch) | |
| tree | e373ee7b4d114687e3050f3a6f7709fc60c8d261 /scripts | |
| parent | 3e7b34a52aed802e7d84cd9333cdfd0d194a723d (diff) | |
| parent | f442c3dfba5dca9dcf144ef71f1c52b6b3bd1cf1 (diff) | |
Merge pull request #2814 from TheGeogeo/test-red-green-compiler-crash
scripts: red_green.py tells a crashed compiler from a build error (TEST-RED-GREEN-COMPILER-CRASH)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/red_green.py | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/scripts/red_green.py b/scripts/red_green.py index 1af2fd167..7d8305f45 100644 --- a/scripts/red_green.py +++ b/scripts/red_green.py | |||
| @@ -20,7 +20,8 @@ It runs `cargo test --no-fail-fast` for the D3D12 crates the pull request touche | |||
| 20 | toolchain applies) and the changed `tests/**/test*.py` files with unittest, on both sides, in one worktree and one | 20 | toolchain applies) and the changed `tests/**/test*.py` files with unittest, on both sides, in one worktree and one |
| 21 | cargo target dir under --work-dir (default `<git common dir>/red-green`), red first. It keeps both between runs: the | 21 | cargo target dir under --work-dir (default `<git common dir>/red-green`), red first. It keeps both between runs: the |
| 22 | second run on the same crates builds only what changed. C++ `runtime/` tests are not run here (docs/testing.md has | 22 | second run on the same crates builds only what changed. C++ `runtime/` tests are not run here (docs/testing.md has |
| 23 | the fork-CI way). | 23 | the fork-CI way). A side whose compiler crashed (a Windows crash status of rustc or a build script, an internal |
| 24 | compiler error, a failed allocation) builds again once; a second crash is the verdict `compiler crashed`. | ||
| 24 | 25 | ||
| 25 | Exit 0: at least one test went from red to green and no test that passes on red fails on green. 1: any other | 26 | Exit 0: at least one test went from red to green and no test that passes on red fails on green. 1: any other |
| 26 | verdict. 2: a usage or git error. | 27 | verdict. 2: a usage or git error. |
| @@ -272,7 +273,16 @@ def crates_of(tree: Path, paths: list[str]) -> list[str]: | |||
| 272 | return names | 273 | return names |
| 273 | 274 | ||
| 274 | 275 | ||
| 275 | def cargo_tests(tree: Path, crates: list[str], cargo: str, target: Path) -> dict: | 276 | # A crashed compiler, not an error in the code: rustc or a build script ending with a Windows crash status |
| 277 | # (0xC0000005 access violation, 0xC00000FD stack overflow, 0xC0000409 abort, ...), an internal compiler error, or a | ||
| 278 | # failed allocation. Such a side runs again once (a crash of a test binary stays a test result). | ||
| 279 | COMPILER_CRASH = re.compile( | ||
| 280 | r"process didn't exit successfully: `[^`]*(?:rustc|build-script-\w+)[^`]*` \(exit (?:code|status): " | ||
| 281 | r"(0x[cC][0-9a-fA-F]{7}(?:, \w+)?)\)" | ||
| 282 | r"|(internal compiler error)|(the compiler unexpectedly panicked)|(memory allocation of \d+ bytes failed)") | ||
| 283 | |||
| 284 | |||
| 285 | def cargo_once(tree: Path, crates: list[str], cargo: str, target: Path) -> dict: | ||
| 276 | cmd = [sys.executable, cargo] if cargo.endswith(".py") else [cargo] | 286 | cmd = [sys.executable, cargo] if cargo.endswith(".py") else [cargo] |
| 277 | cmd += ["test", "--locked", "--no-fail-fast"] + [a for c in crates for a in ("-p", c)] | 287 | cmd += ["test", "--locked", "--no-fail-fast"] + [a for c in crates for a in ("-p", c)] |
| 278 | env = dict(os.environ, CARGO_TARGET_DIR=str(target)) | 288 | env = dict(os.environ, CARGO_TARGET_DIR=str(target)) |
| @@ -290,7 +300,21 @@ def cargo_tests(tree: Path, crates: list[str], cargo: str, target: Path) -> dict | |||
| 290 | elif error is None and CARGO_ERROR.match(line): | 300 | elif error is None and CARGO_ERROR.match(line): |
| 291 | error = line.strip() | 301 | error = line.strip() |
| 292 | no_build = r.returncode != 0 and not tests | 302 | no_build = r.returncode != 0 and not tests |
| 293 | return {"tests": tests, "no_build": (error or f"cargo exit {r.returncode}") if no_build else None} | 303 | crash = COMPILER_CRASH.search(out) if no_build else None |
| 304 | return {"tests": tests, "no_build": (error or f"cargo exit {r.returncode}") if no_build and not crash else None, | ||
| 305 | "crash": next(g for g in crash.groups() if g) if crash else None} | ||
| 306 | |||
| 307 | |||
| 308 | def cargo_tests(tree: Path, crates: list[str], cargo: str, target: Path) -> dict: | ||
| 309 | first = cargo_once(tree, crates, cargo, target) | ||
| 310 | if not first["crash"]: | ||
| 311 | return {"tests": first["tests"], "no_build": first["no_build"]} | ||
| 312 | print(f"red_green: the compiler crashed ({first['crash']}), running again", file=sys.stderr) | ||
| 313 | again = cargo_once(tree, crates, cargo, target) | ||
| 314 | result = {"tests": again["tests"], "no_build": again["no_build"], "rerun_after": first["crash"]} | ||
| 315 | if again["crash"]: | ||
| 316 | result["compiler_crashed"] = again["crash"] | ||
| 317 | return result | ||
| 294 | 318 | ||
| 295 | 319 | ||
| 296 | PY_TEST = re.compile(r"^(\w+) \(([\w.]+)\)(?:\n[^\n]*?)? \.\.\. (ok|FAIL|ERROR|skipped|expected failure|unexpected success)", | 320 | PY_TEST = re.compile(r"^(\w+) \(([\w.]+)\)(?:\n[^\n]*?)? \.\.\. (ok|FAIL|ERROR|skipped|expected failure|unexpected success)", |
| @@ -318,12 +342,14 @@ def python_tests(tree: Path, files: list[str]) -> dict: | |||
| 318 | 342 | ||
| 319 | 343 | ||
| 320 | def side(tree: Path, crates: list[str], py_files: list[str], cargo: str, target: Path) -> dict: | 344 | def side(tree: Path, crates: list[str], py_files: list[str], cargo: str, target: Path) -> dict: |
| 321 | result = {"tests": {}, "no_build": []} | 345 | result = {"tests": {}, "no_build": [], "compiler_crashed": None, "rerun_after": None} |
| 322 | for part in ([cargo_tests(tree, crates, cargo, target)] if crates else []) + \ | 346 | for part in ([cargo_tests(tree, crates, cargo, target)] if crates else []) + \ |
| 323 | ([python_tests(tree, py_files)] if py_files else []): | 347 | ([python_tests(tree, py_files)] if py_files else []): |
| 324 | result["tests"].update(part["tests"]) | 348 | result["tests"].update(part["tests"]) |
| 325 | if part["no_build"]: | 349 | if part["no_build"]: |
| 326 | result["no_build"].append(part["no_build"]) | 350 | result["no_build"].append(part["no_build"]) |
| 351 | for key in ("compiler_crashed", "rerun_after"): | ||
| 352 | result[key] = result[key] or part.get(key) | ||
| 327 | return result | 353 | return result |
| 328 | 354 | ||
| 329 | 355 | ||
| @@ -355,6 +381,9 @@ def compare(red: dict | None, green: dict | None) -> dict: | |||
| 355 | def verdict(red_why: str | None, green_why: str | None, red: dict | None, green: dict | None, rows: dict) -> str: | 381 | def verdict(red_why: str | None, green_why: str | None, red: dict | None, green: dict | None, rows: dict) -> str: |
| 356 | if green_why: | 382 | if green_why: |
| 357 | return "green not constructible" | 383 | return "green not constructible" |
| 384 | # Twice in a row on a side: the build cannot tell anything; not a code error, run it again later. | ||
| 385 | if any(s and s.get("compiler_crashed") for s in (red, green)): | ||
| 386 | return "compiler crashed" | ||
| 358 | green_failed = rows["regressions"] or any(r.endswith("(failed)") for r in rows["only_on_green"]) | 387 | green_failed = rows["regressions"] or any(r.endswith("(failed)") for r in rows["only_on_green"]) |
| 359 | if green and green["no_build"] or green_failed: | 388 | if green and green["no_build"] or green_failed: |
| 360 | return "green fails" | 389 | return "green fails" |
| @@ -379,6 +408,10 @@ def report(r: dict) -> str: | |||
| 379 | s = r[name] | 408 | s = r[name] |
| 380 | if s and s["no_build"]: | 409 | if s and s["no_build"]: |
| 381 | out.append(f"{name} does not build: " + "; ".join(s["no_build"])) | 410 | out.append(f"{name} does not build: " + "; ".join(s["no_build"])) |
| 411 | if s and s.get("compiler_crashed"): | ||
| 412 | out.append(f"{name}: the compiler crashed twice ({s['compiler_crashed']})") | ||
| 413 | elif s and s.get("rerun_after"): | ||
| 414 | out.append(f"{name}: the compiler crashed once ({s['rerun_after']}), the second build is the one shown") | ||
| 382 | rows = r["rows"] | 415 | rows = r["rows"] |
| 383 | labels = {"red_to_green": "red then green", "regressions": "pass on red, FAIL on green", | 416 | labels = {"red_to_green": "red then green", "regressions": "pass on red, FAIL on green", |
| 384 | "fail_on_both": "fail on both (failing on the base too?)", "only_on_green": "only on green", | 417 | "fail_on_both": "fail on both (failing on the base too?)", "only_on_green": "only on green", |