diff --git a/lanes/testcut/p2-h265.md b/lanes/testcut/p2-h265.md index 0b871374..cea1fae1 100644 --- a/lanes/testcut/p2-h265.md +++ b/lanes/testcut/p2-h265.md @@ -31,3 +31,17 @@ Also in the same crate: `inter_placeholder_runs_over_pb_slices` (tests/it/cu_syn 3. Kept with evidence: none. All five candidates are unfinished and kept. 4. Tooling fixes: sample.py mapping fine; run A runner issue is in a scratch copy and needs a fresh sync. 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). + +## Resumed run (orchestrator ordering: T-only first, then KT through the fast suite) +Status: STOPPED. Deleted tests: 0. Seconds saved: 0. Every candidate kept (unfinished = keep). + +What happened: +- 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. +- `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. +- 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`. +- 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. +- 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. + +Launchers that were running (both stopped): c2 PID 1576309, b1 PID 1576312. + +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. diff --git a/lanes/testcut/p2h265-tools/mutrun.py b/lanes/testcut/p2h265-tools/mutrun.py new file mode 100644 index 00000000..c6aee8d2 --- /dev/null +++ b/lanes/testcut/p2h265-tools/mutrun.py @@ -0,0 +1,106 @@ +# usage: mutrun.py OUT NAMES_JSON TAG TIMEOUT_SECS FILTER_EXPR [--profile fast] +# Applies each named mutant's own diff (from OUT/mutants.json) to the lane tree, runs +# `cargo nextest run -p ec-h265 -E FILTER_EXPR`, restores the file, and records one row per mutant: +# name status summary +# status: KILLED (test failure or timeout), SURVIVED (all pass), UNVIABLE (compile error), NORUN (no test ran). +# The tree is the lane's synced tree (cwd); only the one mutated file is touched, and it is restored. +import json, os, subprocess, sys, re +out, names_file, tag, timeout = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4]) +expr = sys.argv[5] +profile = sys.argv[7] if len(sys.argv) > 7 and sys.argv[6] == "--profile" else None +names = json.load(open(names_file)) +muts = {m["name"]: m for m in json.load(open(f"{out}/mutants.json"))} + +def parse(diff): + lines = diff.split("\n") + fname = lines[0][4:].strip() + hunks = [] + i = 1 + while i < len(lines): + m = re.match(r"@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@", lines[i]) + if not m: + i += 1 + continue + start = int(m.group(1)) + body = [] + i += 1 + while i < len(lines) and not lines[i].startswith("@@"): + if lines[i][:1] in (" ", "-", "+"): + body.append((lines[i][:1], lines[i][1:])) + i += 1 + hunks.append((start, body)) + return fname, hunks + +def apply(orig, hunks): + res, cur = [], 0 + for start, body in hunks: + pos = start - 1 + res.extend(orig[cur:pos]) + cur = pos + for op, text in body: + if op in (" ", "-"): + if cur >= len(orig) or orig[cur] != text: + raise ValueError(f"context mismatch at line {cur + 1}") + if op == " ": + res.append(text) + cur += 1 + else: + res.append(text) + res.extend(orig[cur:]) + return res + +def run_once(): + cmd = ["cargo", "nextest", "run", "-p", "ec-h265", "--no-fail-fast", "-E", expr] + if profile: + cmd[-2:-2] = ["--profile", profile] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, + start_new_session=True) + try: + output, _ = p.communicate(timeout=timeout) + return p.returncode, output, False + except subprocess.TimeoutExpired: + os.killpg(p.pid, 9) + output, _ = p.communicate() + return -1, output or "", True + +rows = [] +for name in names: + m = muts.get(name) + if m is None: + rows.append((name, "NORUN", "name not in mutants.json")) + continue + fname, hunks = parse(m["diff"]) + raw = open(fname, "rb").read() + text = raw.decode() + orig = text.split("\n") + try: + new = apply(orig, hunks) + except ValueError as e: + rows.append((name, "NORUN", f"apply failed: {e}")) + continue + try: + open(fname, "w").write("\n".join(new)) + rc, output, timed_out = run_once() + finally: + open(fname, "wb").write(raw) + summary = re.findall(r"Summary \[[^\]]*\] (\d+) tests? run", output) + ran = int(summary[-1]) if summary else 0 + if timed_out: + # A timeout is kill evidence only if the test run had started (build time alone is not). + status = "KILLED" if re.search(r"Starting \d+ tests?", output) else "TIMEOUT_NOSTART" + elif "could not compile" in output or "error[E" in output: + status = "UNVIABLE" + elif rc == 0 and ran > 0: + status = "SURVIVED" + elif rc != 0 and ran > 0: + status = "KILLED" + else: + status = "NORUN" + err = next((l for l in output.splitlines() if "error[" in l or l.startswith("error")), "") if status == "UNVIABLE" else "" + rows.append((name, status, f"rc={rc} ran={ran} timeout={timed_out} {err}")) + print(status, name[:90], f"rc={rc} ran={ran}", flush=True) + +with open(f"{out}/res-{tag}.tsv", "w") as f: + for r in rows: + f.write("\t".join(r) + "\n") +print("summary", {s: sum(1 for r in rows if r[1] == s) for s in ("KILLED", "SURVIVED", "UNVIABLE", "NORUN")}) diff --git a/lanes/testcut/p2h265-tools/run1.sh b/lanes/testcut/p2h265-tools/run1.sh new file mode 100644 index 00000000..d3142e51 --- /dev/null +++ b/lanes/testcut/p2h265-tools/run1.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Step 1 (T only). usage: run1.sh TEST:SECONDS ... (run from the synced tree; OUT = /out) +# Per candidate: 20 seeded U(T) mutants (sample2.py), each applied from its own mutants.json diff +# (mutrun.py) and run against T only with timeout 3x T's runtime. +# Writes KT-.txt (killed by T) and S1-.txt (survived T alone), plus res-B1-.tsv. +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +TOOLS=$PWD/lanes/testcut/p2h265-tools +OUT=$(dirname "$PWD")/out +mkdir -p "$OUT" +SEED=2026 +for arg in "$@"; do + T=${arg%%:*}; SECS=${arg##*:}; TO=$((SECS * 3)) + python3 "$TOOLS/sample2.py" "$OUT" "$T" 20 "$SEED" || { echo "$T sample failed"; continue; } + echo "== $T timeout ${TO}s $(date +%T)" + python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/s-$T.json" "B1-$T" "$TO" "test(/(^|::)$T\$/)" > "$OUT/B1-$T.log" 2>&1 + echo "exit $? $(date +%T)" + awk -F'\t' '$2=="KILLED"{print $1}' "$OUT/res-B1-$T.tsv" > "$OUT/KT-$T.txt" + awk -F'\t' '$2=="SURVIVED"{print $1}' "$OUT/res-B1-$T.tsv" > "$OUT/S1-$T.txt" + echo "statuses: $(cut -f2 "$OUT/res-B1-$T.tsv" | sort | uniq -c | tr '\n' ' ')" + echo "KT=$(wc -l < "$OUT/KT-$T.txt") S1=$(wc -l < "$OUT/S1-$T.txt")" +done diff --git a/lanes/testcut/p2h265-tools/sample2.py b/lanes/testcut/p2h265-tools/sample2.py new file mode 100644 index 00000000..6e8ca1a3 --- /dev/null +++ b/lanes/testcut/p2h265-tools/sample2.py @@ -0,0 +1,66 @@ +# usage: sample2.py OUT TEST N SEED -> OUT/s-TEST.json +# Seeded sample of mutants whose containing fast-suite function is in U(TEST) (the functions TEST +# covers that the fast suite does not). Writes the mutant names; prints eligible/sampled counts. +import json, random, sys, collections +out, test, n, seed = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]) + +def tail(p): + i = p.find("ec-h265/") + return p[i + 8:] if i >= 0 else None + +def load(name): + return json.load(open(f"{out}/{name}.json"))["data"][0] + +def funcs(data): + res = {} + for fn in data["functions"]: + if not fn["regions"]: + continue + fl = tail(fn["filenames"][fn["regions"][0][5]]) + if fl is None: + continue + lo = min(r[0] for r in fn["regions"]) + hi = max(r[2] for r in fn["regions"]) + key = (fl, fn["name"]) + d = res.setdefault(key, {"lo": lo, "hi": hi, "cov": False}) + d["lo"] = min(d["lo"], lo) + d["hi"] = max(d["hi"], hi) + d["cov"] = d["cov"] or any(r[4] > 0 for r in fn["regions"]) + return res + +fast = funcs(load("fast")) +T = funcs(load(test)) +U = {(x[0], x[1]) for x in json.load(open(f"{out}/coverage-summary.json"))["per_test"][test]["U_functions"]} +by_file = collections.defaultdict(list) +for key in fast: + by_file[key[0]].append(key) + +elig = [] +covered = [] +for m in json.load(open(f"{out}/mutants.json")): + f = tail(m["file"]) if "ec-h265/" in m["file"] else m["file"] + line = m["span"]["start"]["line"] + best = None + for key in by_file.get(f, []): + fn = fast[key] + if not T.get(key, {}).get("cov"): + continue + if fn["lo"] <= line <= fn["hi"]: + if best is None or (fn["hi"] - fn["lo"]) < (best[1]["hi"] - best[1]["lo"]): + best = (key, fn) + if best is None: + continue + key = best[0] + if key in U and T.get(key, {}).get("cov"): + elig.append(m["name"]) + elif T.get(key, {}).get("cov"): + covered.append(m["name"]) + +elig = sorted(set(elig)) +covered = sorted(set(covered) - set(elig)) +# Fallback when U(T) holds no source functions (e.g. only test-file functions): mutants in functions +# T covers, which the protocol's step 3 allows. +pool, label = (elig, "U") if elig else (covered, "covered-fallback") +picked = random.Random(seed).sample(pool, min(n, len(pool))) +json.dump(picked, open(f"{out}/s-{test}.json", "w")) +print(test, label, len(pool), "sampled", len(picked), "seed", seed)