|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Every e2e test runs somewhere, or says why it cannot (rule R5). |
| 3 | +
|
| 4 | +WHY THIS EXISTS |
| 5 | +
|
| 6 | +`run_all.sh` exits 0 on a skip, and a skip line reads the same whether the |
| 7 | +host legitimately lacks a capability or the runner was set up wrong. Measured |
| 8 | +on 2026-10-01, before this check: 24 of 564 tests ran on no host and were named |
| 9 | +by no workflow. Seven declared `llvm`, which no line granted; three declared |
| 10 | +`musl`, whose probe named a release (15.1.0) the runners no longer installed; |
| 11 | +seven declared `mingw-cross`, which no shard installed. Every one of those runs |
| 12 | +was green. |
| 13 | +
|
| 14 | +WHAT IT CHECKS |
| 15 | +
|
| 16 | +It reads the per-test reports the shards write (`E2E_REPORT` of run_all.sh, one |
| 17 | +`<status>\\t<test>\\t<ms>\\t<detail>` line per test) and decides, for every test |
| 18 | +under tests/e2e: |
| 19 | +
|
| 20 | + ran some report says pass, fail or timeout; |
| 21 | + job no report ran it, but a workflow names it (by file name, or by its |
| 22 | + number as an `E2E_ONLY` pattern such as `239_*.sh`): a dedicated job |
| 23 | + runs it and asserts its result itself; |
| 24 | + excused tests/e2e/coverage-exceptions.tsv lists it with the reason no hosted |
| 25 | + runner can run it; |
| 26 | + uncovered none of these. The check fails. |
| 27 | +
|
| 28 | +An exception for a test that ran, or for a test that does not exist, also fails |
| 29 | +the check, so that the list cannot outlive the reason it records. |
| 30 | +
|
| 31 | +With --timings-out DIR it writes `<host>.tsv`, the measured duration of every |
| 32 | +test that ran, merged across that host's shards, in the format run_all.sh reads |
| 33 | +from E2E_TIMINGS; refreshing tests/e2e/timings/ is copying those files. A report |
| 34 | +file is named `e2e-report-<host>-<shard>.tsv`. |
| 35 | +
|
| 36 | +Usage: |
| 37 | + check_e2e_coverage.py --reports DIR [--root DIR] [--timings-out DIR] |
| 38 | +""" |
| 39 | +from __future__ import annotations |
| 40 | + |
| 41 | +import argparse |
| 42 | +import re |
| 43 | +import sys |
| 44 | +from collections import defaultdict |
| 45 | +from pathlib import Path |
| 46 | + |
| 47 | +RAN = {"pass", "fail", "timeout"} |
| 48 | +REPORT_NAME = re.compile(r"e2e-report-(?P<host>[a-z0-9-]+?)-(?P<shard>\d+)\.tsv$") |
| 49 | + |
| 50 | + |
| 51 | +def read_reports(directory: Path): |
| 52 | + """Yield (host, shard, status, test, ms, detail) for every report line.""" |
| 53 | + for path in sorted(directory.rglob("e2e-report-*.tsv")): |
| 54 | + m = REPORT_NAME.search(path.name) |
| 55 | + if not m: |
| 56 | + continue |
| 57 | + for line in path.read_text(encoding="utf-8", errors="replace").splitlines(): |
| 58 | + parts = line.split("\t") |
| 59 | + if len(parts) < 3: |
| 60 | + continue |
| 61 | + ms = int(parts[2]) if parts[2].isdigit() else 0 |
| 62 | + yield m["host"], int(m["shard"]), parts[0], parts[1], ms, parts[3] if len(parts) > 3 else "" |
| 63 | + |
| 64 | + |
| 65 | +def read_exceptions(path: Path) -> dict[str, str]: |
| 66 | + out: dict[str, str] = {} |
| 67 | + if not path.exists(): |
| 68 | + return out |
| 69 | + for line in path.read_text(encoding="utf-8").splitlines(): |
| 70 | + if not line.strip() or line.startswith("#"): |
| 71 | + continue |
| 72 | + test, _, reason = line.partition("\t") |
| 73 | + out[test.strip()] = reason.strip() |
| 74 | + return out |
| 75 | + |
| 76 | + |
| 77 | +def named_by_a_workflow(test: str, workflows: str) -> bool: |
| 78 | + number = test.split("_", 1)[0] |
| 79 | + return test in workflows or test[:-3] in workflows or f"{number}_*" in workflows |
| 80 | + |
| 81 | + |
| 82 | +def main() -> int: |
| 83 | + parser = argparse.ArgumentParser() |
| 84 | + parser.add_argument("--reports", required=True) |
| 85 | + parser.add_argument("--root", default=".") |
| 86 | + parser.add_argument("--timings-out") |
| 87 | + args = parser.parse_args() |
| 88 | + root = Path(args.root).resolve() |
| 89 | + |
| 90 | + tests = sorted(p.name for p in (root / "tests" / "e2e").glob("[0-9]*.sh")) |
| 91 | + workflows = "\n".join(p.read_text(encoding="utf-8") |
| 92 | + for p in sorted((root / ".github" / "workflows").glob("*.yml"))) |
| 93 | + exceptions = read_exceptions(root / "tests" / "e2e" / "coverage-exceptions.tsv") |
| 94 | + |
| 95 | + ran: dict[str, set[str]] = defaultdict(set) |
| 96 | + skipped: dict[str, set[str]] = defaultdict(set) |
| 97 | + shard_ms: dict[tuple[str, int], int] = defaultdict(int) |
| 98 | + timings: dict[str, dict[str, int]] = defaultdict(dict) |
| 99 | + reports = 0 |
| 100 | + for host, shard, status, test, ms, detail in read_reports(Path(args.reports)): |
| 101 | + reports += 1 |
| 102 | + if status in RAN: |
| 103 | + ran[test].add(host) |
| 104 | + shard_ms[(host, shard)] += ms |
| 105 | + timings[host][test] = ms |
| 106 | + elif status == "skip": |
| 107 | + skipped[test].add(f"{host}: {detail}") |
| 108 | + if reports == 0: |
| 109 | + print(f"no report under {args.reports}: nothing can be said about coverage") |
| 110 | + return 1 |
| 111 | + |
| 112 | + uncovered, stale = [], [] |
| 113 | + counts = defaultdict(int) |
| 114 | + for test in tests: |
| 115 | + if test in ran: |
| 116 | + counts["ran"] += 1 |
| 117 | + if test in exceptions: |
| 118 | + stale.append(f"{test} is excused but ran on {', '.join(sorted(ran[test]))}") |
| 119 | + elif named_by_a_workflow(test, workflows): |
| 120 | + counts["job"] += 1 |
| 121 | + elif test in exceptions: |
| 122 | + counts["excused"] += 1 |
| 123 | + else: |
| 124 | + uncovered.append(f"{test}: {'; '.join(sorted(skipped[test])) or 'in no report'}") |
| 125 | + for test in exceptions: |
| 126 | + if test not in tests: |
| 127 | + stale.append(f"{test} is excused but does not exist") |
| 128 | + |
| 129 | + print(f"{len(tests)} tests: {counts['ran']} ran on a shard, {counts['job']} run by a " |
| 130 | + f"dedicated job, {counts['excused']} excused, {len(uncovered)} uncovered") |
| 131 | + for (host, shard), ms in sorted(shard_ms.items()): |
| 132 | + print(f" {host} shard {shard}: {ms / 60000:.1f} min of tests") |
| 133 | + for line in uncovered: |
| 134 | + print(f"UNCOVERED: {line}") |
| 135 | + for line in stale: |
| 136 | + print(f"STALE EXCEPTION: {line}") |
| 137 | + |
| 138 | + if args.timings_out: |
| 139 | + out = Path(args.timings_out) |
| 140 | + out.mkdir(parents=True, exist_ok=True) |
| 141 | + for host, table in timings.items(): |
| 142 | + (out / f"{host}.tsv").write_text( |
| 143 | + "".join(f"{t}\t{ms}\n" for t, ms in sorted(table.items())), encoding="utf-8") |
| 144 | + return 1 if uncovered or stale else 0 |
| 145 | + |
| 146 | + |
| 147 | +if __name__ == "__main__": |
| 148 | + sys.exit(main()) |
0 commit comments