testcut P2 ec-h265: resumed run stopped; report partial, all candidates kept
Browse files at this commitf899940e0ea8a4143688eaa832d2e06824a9d553Parent: 9f41e354 changed files +208 -0
- lanes/testcut/p2-h265.md +14 -0
- lanes/testcut/p2h265-tools/mutrun.py +106 -0
- lanes/testcut/p2h265-tools/run1.sh +22 -0
- lanes/testcut/p2h265-tools/sample2.py +66 -0
lanes/testcut/p2-h265.mdmodified+14 -0
| @@ -31,3 +31,17 @@ Also in the same crate: `inter_placeholder_runs_over_pb_slices` (tests/it/cu_syn | |||
| 31 | 3. Kept with evidence: none. All five candidates are unfinished and kept. | 31 | 3. Kept with evidence: none. All five candidates are unfinished and kept. |
| 32 | 4. Tooling fixes: sample.py mapping fine; run A runner issue is in a scratch copy and needs a fresh sync. | 32 | 4. Tooling fixes: sample.py mapping fine; run A runner issue is in a scratch copy and needs a fresh sync. |
| 33 | 5. Next step if resumed: one mutant per fast run is too expensive. Needs either a per-test kill matrix on a precomputed fast-suite target, or a smaller sample (about 10 mutants per candidate). | 33 | 5. Next step if resumed: one mutant per fast run is too expensive. Needs either a per-test kill matrix on a precomputed fast-suite target, or a smaller sample (about 10 mutants per candidate). |
| 34 | + | ||
| 35 | +## Resumed run (orchestrator ordering: T-only first, then KT through the fast suite) | ||
| 36 | +Status: STOPPED. Deleted tests: 0. Seconds saved: 0. Every candidate kept (unfinished = keep). | ||
| 37 | + | ||
| 38 | +What happened: | ||
| 39 | +- Sampler and runner were fixed. `sample2.py` picks 20 seeded mutants from U(T) functions (pixel: 740 eligible, cu_syntax: 595). Noisy has no U(T) source functions (its U entries are test-file functions), so it falls back to mutants in functions T covers. | ||
| 40 | +- `cargo mutants --re` is unusable here. `--list` returns about 30 unrelated mutants for any regex, so the sampled set was not what ran. The runner was replaced by `mutrun.py`, which applies each mutant's own `diff` from `mutants.json`, runs `cargo nextest run -E test(=T)` and restores the file. Local check: applying 400 mutant diffs reproduces the expected one-line changes. | ||
| 41 | +- Timeouts: pixel's first four mutants all hit the 429 s limit with no nextest "Starting" line, so the cause is unknown. Host c was loaded (load about 9), so timeouts are not kill evidence. `mutrun.py` now marks timeouts without a start line as `TIMEOUT_NOSTART`. | ||
| 42 | +- Launcher duplication: two motion loops ran at once on b1, and stale `run1.sh`/`cargo mutants` chains ran on both c2 and b1. All were killed by PID, and the lanes were cleaned with `remote-run --clean`. The b1 motion result from 13:25 used an empty sample and is discarded. | ||
| 43 | +- Final state: pixel's run was killed before writing its result file, so no statuses exist. cu_syntax and noisy never ran. b1 (motion, ffmpeg) never got a slot. | ||
| 44 | + | ||
| 45 | +Launchers that were running (both stopped): c2 PID 1576309, b1 PID 1576312. | ||
| 46 | + | ||
| 47 | +Next step if resumed: give each mutant a timeout measured against an unmutated baseline run on the same host, or use a quiet host, and run the sample per candidate in one job so that no two chains share a tree. | ||
lanes/testcut/p2h265-tools/mutrun.pyadded+106 -0
| @@ -0,0 +1,106 @@ | |||
| 1 | +# usage: mutrun.py OUT NAMES_JSON TAG TIMEOUT_SECS FILTER_EXPR [--profile fast] | ||
| 2 | +# Applies each named mutant's own diff (from OUT/mutants.json) to the lane tree, runs | ||
| 3 | +# `cargo nextest run -p ec-h265 -E FILTER_EXPR`, restores the file, and records one row per mutant: | ||
| 4 | +# name <TAB> status <TAB> summary | ||
| 5 | +# status: KILLED (test failure or timeout), SURVIVED (all pass), UNVIABLE (compile error), NORUN (no test ran). | ||
| 6 | +# The tree is the lane's synced tree (cwd); only the one mutated file is touched, and it is restored. | ||
| 7 | +import json, os, subprocess, sys, re | ||
| 8 | +out, names_file, tag, timeout = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4]) | ||
| 9 | +expr = sys.argv[5] | ||
| 10 | +profile = sys.argv[7] if len(sys.argv) > 7 and sys.argv[6] == "--profile" else None | ||
| 11 | +names = json.load(open(names_file)) | ||
| 12 | +muts = {m["name"]: m for m in json.load(open(f"{out}/mutants.json"))} | ||
| 13 | + | ||
| 14 | +def parse(diff): | ||
| 15 | + lines = diff.split("\n") | ||
| 16 | + fname = lines[0][4:].strip() | ||
| 17 | + hunks = [] | ||
| 18 | + i = 1 | ||
| 19 | + while i < len(lines): | ||
| 20 | + m = re.match(r"@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@", lines[i]) | ||
| 21 | + if not m: | ||
| 22 | + i += 1 | ||
| 23 | + continue | ||
| 24 | + start = int(m.group(1)) | ||
| 25 | + body = [] | ||
| 26 | + i += 1 | ||
| 27 | + while i < len(lines) and not lines[i].startswith("@@"): | ||
| 28 | + if lines[i][:1] in (" ", "-", "+"): | ||
| 29 | + body.append((lines[i][:1], lines[i][1:])) | ||
| 30 | + i += 1 | ||
| 31 | + hunks.append((start, body)) | ||
| 32 | + return fname, hunks | ||
| 33 | + | ||
| 34 | +def apply(orig, hunks): | ||
| 35 | + res, cur = [], 0 | ||
| 36 | + for start, body in hunks: | ||
| 37 | + pos = start - 1 | ||
| 38 | + res.extend(orig[cur:pos]) | ||
| 39 | + cur = pos | ||
| 40 | + for op, text in body: | ||
| 41 | + if op in (" ", "-"): | ||
| 42 | + if cur >= len(orig) or orig[cur] != text: | ||
| 43 | + raise ValueError(f"context mismatch at line {cur + 1}") | ||
| 44 | + if op == " ": | ||
| 45 | + res.append(text) | ||
| 46 | + cur += 1 | ||
| 47 | + else: | ||
| 48 | + res.append(text) | ||
| 49 | + res.extend(orig[cur:]) | ||
| 50 | + return res | ||
| 51 | + | ||
| 52 | +def run_once(): | ||
| 53 | + cmd = ["cargo", "nextest", "run", "-p", "ec-h265", "--no-fail-fast", "-E", expr] | ||
| 54 | + if profile: | ||
| 55 | + cmd[-2:-2] = ["--profile", profile] | ||
| 56 | + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, | ||
| 57 | + start_new_session=True) | ||
| 58 | + try: | ||
| 59 | + output, _ = p.communicate(timeout=timeout) | ||
| 60 | + return p.returncode, output, False | ||
| 61 | + except subprocess.TimeoutExpired: | ||
| 62 | + os.killpg(p.pid, 9) | ||
| 63 | + output, _ = p.communicate() | ||
| 64 | + return -1, output or "", True | ||
| 65 | + | ||
| 66 | +rows = [] | ||
| 67 | +for name in names: | ||
| 68 | + m = muts.get(name) | ||
| 69 | + if m is None: | ||
| 70 | + rows.append((name, "NORUN", "name not in mutants.json")) | ||
| 71 | + continue | ||
| 72 | + fname, hunks = parse(m["diff"]) | ||
| 73 | + raw = open(fname, "rb").read() | ||
| 74 | + text = raw.decode() | ||
| 75 | + orig = text.split("\n") | ||
| 76 | + try: | ||
| 77 | + new = apply(orig, hunks) | ||
| 78 | + except ValueError as e: | ||
| 79 | + rows.append((name, "NORUN", f"apply failed: {e}")) | ||
| 80 | + continue | ||
| 81 | + try: | ||
| 82 | + open(fname, "w").write("\n".join(new)) | ||
| 83 | + rc, output, timed_out = run_once() | ||
| 84 | + finally: | ||
| 85 | + open(fname, "wb").write(raw) | ||
| 86 | + summary = re.findall(r"Summary \[[^\]]*\] (\d+) tests? run", output) | ||
| 87 | + ran = int(summary[-1]) if summary else 0 | ||
| 88 | + if timed_out: | ||
| 89 | + # A timeout is kill evidence only if the test run had started (build time alone is not). | ||
| 90 | + status = "KILLED" if re.search(r"Starting \d+ tests?", output) else "TIMEOUT_NOSTART" | ||
| 91 | + elif "could not compile" in output or "error[E" in output: | ||
| 92 | + status = "UNVIABLE" | ||
| 93 | + elif rc == 0 and ran > 0: | ||
| 94 | + status = "SURVIVED" | ||
| 95 | + elif rc != 0 and ran > 0: | ||
| 96 | + status = "KILLED" | ||
| 97 | + else: | ||
| 98 | + status = "NORUN" | ||
| 99 | + err = next((l for l in output.splitlines() if "error[" in l or l.startswith("error")), "") if status == "UNVIABLE" else "" | ||
| 100 | + rows.append((name, status, f"rc={rc} ran={ran} timeout={timed_out} {err}")) | ||
| 101 | + print(status, name[:90], f"rc={rc} ran={ran}", flush=True) | ||
| 102 | + | ||
| 103 | +with open(f"{out}/res-{tag}.tsv", "w") as f: | ||
| 104 | + for r in rows: | ||
| 105 | + f.write("\t".join(r) + "\n") | ||
| 106 | +print("summary", {s: sum(1 for r in rows if r[1] == s) for s in ("KILLED", "SURVIVED", "UNVIABLE", "NORUN")}) | ||
lanes/testcut/p2h265-tools/run1.shadded+22 -0
| @@ -0,0 +1,22 @@ | |||
| 1 | +#!/usr/bin/env bash | ||
| 2 | +# Step 1 (T only). usage: run1.sh TEST:SECONDS ... (run from the synced tree; OUT = <lane>/out) | ||
| 3 | +# Per candidate: 20 seeded U(T) mutants (sample2.py), each applied from its own mutants.json diff | ||
| 4 | +# (mutrun.py) and run against T only with timeout 3x T's runtime. | ||
| 5 | +# Writes KT-<T>.txt (killed by T) and S1-<T>.txt (survived T alone), plus res-B1-<T>.tsv. | ||
| 6 | +set -uo pipefail | ||
| 7 | +export EC_REQUIRE_FIXTURES=1 | ||
| 8 | +TOOLS=$PWD/lanes/testcut/p2h265-tools | ||
| 9 | +OUT=$(dirname "$PWD")/out | ||
| 10 | +mkdir -p "$OUT" | ||
| 11 | +SEED=2026 | ||
| 12 | +for arg in "$@"; do | ||
| 13 | + T=${arg%%:*}; SECS=${arg##*:}; TO=$((SECS * 3)) | ||
| 14 | + python3 "$TOOLS/sample2.py" "$OUT" "$T" 20 "$SEED" || { echo "$T sample failed"; continue; } | ||
| 15 | + echo "== $T timeout ${TO}s $(date +%T)" | ||
| 16 | + python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/s-$T.json" "B1-$T" "$TO" "test(/(^|::)$T\$/)" > "$OUT/B1-$T.log" 2>&1 | ||
| 17 | + echo "exit $? $(date +%T)" | ||
| 18 | + awk -F'\t' '$2=="KILLED"{print $1}' "$OUT/res-B1-$T.tsv" > "$OUT/KT-$T.txt" | ||
| 19 | + awk -F'\t' '$2=="SURVIVED"{print $1}' "$OUT/res-B1-$T.tsv" > "$OUT/S1-$T.txt" | ||
| 20 | + echo "statuses: $(cut -f2 "$OUT/res-B1-$T.tsv" | sort | uniq -c | tr '\n' ' ')" | ||
| 21 | + echo "KT=$(wc -l < "$OUT/KT-$T.txt") S1=$(wc -l < "$OUT/S1-$T.txt")" | ||
| 22 | +done | ||
lanes/testcut/p2h265-tools/sample2.pyadded+66 -0
| @@ -0,0 +1,66 @@ | |||
| 1 | +# usage: sample2.py OUT TEST N SEED -> OUT/s-TEST.json | ||
| 2 | +# Seeded sample of mutants whose containing fast-suite function is in U(TEST) (the functions TEST | ||
| 3 | +# covers that the fast suite does not). Writes the mutant names; prints eligible/sampled counts. | ||
| 4 | +import json, random, sys, collections | ||
| 5 | +out, test, n, seed = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]) | ||
| 6 | + | ||
| 7 | +def tail(p): | ||
| 8 | + i = p.find("ec-h265/") | ||
| 9 | + return p[i + 8:] if i >= 0 else None | ||
| 10 | + | ||
| 11 | +def load(name): | ||
| 12 | + return json.load(open(f"{out}/{name}.json"))["data"][0] | ||
| 13 | + | ||
| 14 | +def funcs(data): | ||
| 15 | + res = {} | ||
| 16 | + for fn in data["functions"]: | ||
| 17 | + if not fn["regions"]: | ||
| 18 | + continue | ||
| 19 | + fl = tail(fn["filenames"][fn["regions"][0][5]]) | ||
| 20 | + if fl is None: | ||
| 21 | + continue | ||
| 22 | + lo = min(r[0] for r in fn["regions"]) | ||
| 23 | + hi = max(r[2] for r in fn["regions"]) | ||
| 24 | + key = (fl, fn["name"]) | ||
| 25 | + d = res.setdefault(key, {"lo": lo, "hi": hi, "cov": False}) | ||
| 26 | + d["lo"] = min(d["lo"], lo) | ||
| 27 | + d["hi"] = max(d["hi"], hi) | ||
| 28 | + d["cov"] = d["cov"] or any(r[4] > 0 for r in fn["regions"]) | ||
| 29 | + return res | ||
| 30 | + | ||
| 31 | +fast = funcs(load("fast")) | ||
| 32 | +T = funcs(load(test)) | ||
| 33 | +U = {(x[0], x[1]) for x in json.load(open(f"{out}/coverage-summary.json"))["per_test"][test]["U_functions"]} | ||
| 34 | +by_file = collections.defaultdict(list) | ||
| 35 | +for key in fast: | ||
| 36 | + by_file[key[0]].append(key) | ||
| 37 | + | ||
| 38 | +elig = [] | ||
| 39 | +covered = [] | ||
| 40 | +for m in json.load(open(f"{out}/mutants.json")): | ||
| 41 | + f = tail(m["file"]) if "ec-h265/" in m["file"] else m["file"] | ||
| 42 | + line = m["span"]["start"]["line"] | ||
| 43 | + best = None | ||
| 44 | + for key in by_file.get(f, []): | ||
| 45 | + fn = fast[key] | ||
| 46 | + if not T.get(key, {}).get("cov"): | ||
| 47 | + continue | ||
| 48 | + if fn["lo"] <= line <= fn["hi"]: | ||
| 49 | + if best is None or (fn["hi"] - fn["lo"]) < (best[1]["hi"] - best[1]["lo"]): | ||
| 50 | + best = (key, fn) | ||
| 51 | + if best is None: | ||
| 52 | + continue | ||
| 53 | + key = best[0] | ||
| 54 | + if key in U and T.get(key, {}).get("cov"): | ||
| 55 | + elig.append(m["name"]) | ||
| 56 | + elif T.get(key, {}).get("cov"): | ||
| 57 | + covered.append(m["name"]) | ||
| 58 | + | ||
| 59 | +elig = sorted(set(elig)) | ||
| 60 | +covered = sorted(set(covered) - set(elig)) | ||
| 61 | +# Fallback when U(T) holds no source functions (e.g. only test-file functions): mutants in functions | ||
| 62 | +# T covers, which the protocol's step 3 allows. | ||
| 63 | +pool, label = (elig, "U") if elig else (covered, "covered-fallback") | ||
| 64 | +picked = random.Random(seed).sample(pool, min(n, len(pool))) | ||
| 65 | +json.dump(picked, open(f"{out}/s-{test}.json", "w")) | ||
| 66 | +print(test, label, len(pool), "sampled", len(picked), "seed", seed) | ||