diff --git a/crates/ec-h265/tests/it/conformance.rs b/crates/ec-h265/tests/it/conformance.rs index 210ab7b7..59223582 100644 --- a/crates/ec-h265/tests/it/conformance.rs +++ b/crates/ec-h265/tests/it/conformance.rs @@ -482,6 +482,92 @@ fn transform_skip_decodes_bit_exactly() { assert!(quality > 30.0, "{name}: PSNR {quality:.2} dB at QP 22"); } } +#[test] +fn ffmpeg_decodes_bit_exactly_at_every_shape() { + if !have_ffmpeg() { + eprintln!("skipping: ffmpeg not installed"); + return; + } + // 1920x1080 needs the conformance window on the bottom (1088 coded rows are + // not used: 1080 is a multiple of 8, but 64x64 CTBs still overhang), 1916 + // needs it on the right, 130x66 exercises a partial CTB in both directions. + // Both tree sizes are coded: the default is 32, and 64 is still offered. + for &(w, h, ctb) in &[ + (64u32, 64u32, None), + (130, 66, None), + (1916, 1080, None), + (352, 288, None), + (1916, 1080, Some(64)), + (130, 66, Some(64)), + ] { + let (source, coded) = encode(w, h, 27, ctb); + let name = format!( + "shape-{w}x{h}-ctb{}", + ctb.map_or("default".to_string(), |c| c.to_string()) + ); + let path = write_au(&name, &coded); + let decoded = match ffmpeg_decode(&path) { + Ok(bytes) => bytes, + Err(e) => panic!("{name}: ffmpeg failed: {e}"), + }; + let recon = planes_of(coded.recon.as_ref().expect("recon kept")); + assert_eq!( + decoded.len(), + recon.len(), + "{name}: decoded {} bytes, reconstruction {} bytes", + decoded.len(), + recon.len() + ); + let mismatches = decoded.iter().zip(&recon).filter(|(a, b)| a != b).count(); + if mismatches != 0 { + // Which plane and where: a luma-only divergence is the transform + // tree, a chroma-only one is the flags that ride on it. + let luma = (w * h) as usize; + let chroma = luma / 4; + let first = decoded + .iter() + .zip(&recon) + .position(|(a, b)| a != b) + .unwrap(); + let count = |range: std::ops::Range| { + decoded[range.clone()] + .iter() + .zip(&recon[range]) + .filter(|(a, b)| a != b) + .count() + }; + let mut map = String::new(); + for by in (0..h as usize).step_by(16) { + for bx in (0..w as usize).step_by(16) { + let mut c = 0; + for row in by..by + 16 { + for col in bx..bx + 16 { + let i = row * w as usize + col; + if decoded[i] != recon[i] { + c += 1; + } + } + } + map.push_str(&format!("{c:4}")); + } + map.push('\n'); + } + eprintln!("luma 16x16 mismatch map:\n{map}"); + panic!( + "{name}: {mismatches} samples differ -- Y {}, Cb {}, Cr {}, first at {first} \ + ({}, {})", + count(0..luma), + count(luma..luma + chroma), + count(luma + chroma..luma + 2 * chroma), + first % w as usize, + first / w as usize, + ); + } + // And the encode is worth something: PSNR against the source. + let quality = psnr(&planes_of(&source), &recon); + assert!(quality > 30.0, "{name}: PSNR {quality:.2} dB at QP 27"); + } +} /// A 64x64 coding unit predicts and transforms in four 32x32 blocks under one /// luma mode, with the transform split inferred rather than signalled diff --git a/lanes/testcut/p2-h265.md b/lanes/testcut/p2-h265.md index 0cb5c848..c9cd6dcc 100644 --- a/lanes/testcut/p2-h265.md +++ b/lanes/testcut/p2-h265.md @@ -1,6 +1,6 @@ # testcut Phase 2: ec-h265 lane (testcut-p2-h265) -Status: DONE (second attempt, host b, lane `testcut-p2-h265-s1`). Deleted 4 tests, about 364 s of release runtime saved (per rest.tsv times: 143.0 + 54.7 + 119.2 + 47.8). +Status: DONE (second attempt, host b, lanes `testcut-p2-h265-s1`, `-s2`). Deleted 3 tests, about 317 s of release runtime saved (per rest.tsv times: 143.0 + 54.7 + 119.2). ffmpeg_decodes_bit_exactly_at_every_shape was restored after the recheck below. ## Method and why the first attempt was invalid The earlier "kills" were timeouts: mutation runs used the debug profile, so the unmutated pixel run took 915 s against a 429 s timeout. This run uses `--release` everywhere, builds each mutant first (`--no-run`, separate build timeout), and sets the test timeout to 2.5 x the measured unmutated baseline of the same command on the same host (`run1.sh`, `fast.sh`, `mutrun.py`). Mutants are applied by index from `mutants.json`, 10 seeded (seed 2026) mutants per candidate from U(T) functions (noisy: functions T covers). A kill counts only if the test failed (rc=100, tests ran); timeouts do not count. Fast stage: `--profile fast --release`, fail-fast; unmutated fast baseline was 168 passed / 14 skipped, 0 failures, so nothing had to be excluded. Fixtures: `EC_REQUIRE_FIXTURES=1` everywhere; baselines passed with the test started. @@ -13,7 +13,7 @@ Validity checks: baseline logs show `PASS` for exactly the one test; SURVIVED ro | ec-h265 | pixel_pipeline_runs_over_conformance_streams | 142.99 | pseudo (prints only) | 223 | 10 | 10 | 0 | - | - | DELETED (kills nothing; baseline 48 s, timeout 125 s) | | ec-h265 | cu_syntax_sweep_over_conformance_streams | 54.75 | pseudo (prints table only) | 171 | 10 | 9 | 1 (wpp.rs:494:27 `-` to `/`) | 0 | 0 | DELETED (the one kill is also killed by the fast suite) | | ec-h265 | motion_derivation_is_deterministic_over_conformance_streams | 119.18 | candidate | 148 | 10 | 9 | 1 | 0 | 0 | DELETED (fast suite kills the T-kill) | -| ec-h265 | ffmpeg_decodes_bit_exactly_at_every_shape | 47.80 | candidate | 57 | 10 | 5 | 5 (2 real, 3 hang-timeouts) | 0 | 0 | DELETED (both real kills die in the fast suite; the hang mutants hang T and the fast suite alike, ctu.rs:429 rechecked at 600 s/1200 s) | +| ec-h265 | ffmpeg_decodes_bit_exactly_at_every_shape | 47.80 | candidate | 57 | 10 | 5 | 5 (2 failing, 3 hang-timeouts; hangs reconfirmed on a quiet host, load 0.9) | 1 (ctu.rs:429:13 `+` to `-` in code_quadtree: T hangs, fast suite also hangs, no real failure) | not run | KEEP (K'=1 unresolved; the other 4 T-kills are real fast-suite failures) | | ec-h265 | noisy_near_black_lands_within_five_percent | 41.17 | candidate | 84 | 10 | 3 | 7 | 1 (ctu.rs:534:29 `+` to `-` in save_meta: T fails, fast suite hangs past 1200 s) | not run | KEEP (the only fast-suite outcome is a hang, not a failure; K' step not run) | | ec-h265 | conformance_pictures_match_the_sei_hash | 85.08 | protected | | | | | | | protected | | ec-h265 | rext_conformance_pictures_match_the_sei_hash | 83.30 | protected | | | | | | | protected | @@ -25,9 +25,12 @@ Validity checks: baseline logs show `PASS` for exactly the one test; SURVIVED ro Release baselines measured on b: pixel 48 s, cu_syntax 21 s, noisy 39 s, motion 40 s, ffmpeg 23 s (the rest.tsv times are from a different run mix). Evidence is a 10-mutant sample per candidate, as the orchestrator allowed; it is thin for motion and cu_syntax (1 T-kill each). ## Summary -1. Tests deleted: pixel_pipeline_runs_over_conformance_streams, cu_syntax_sweep_over_conformance_streams, motion_derivation_is_deterministic_over_conformance_streams, ffmpeg_decodes_bit_exactly_at_every_shape (helpers `Row`, `sweep` and unused imports removed). -2. Seconds saved: about 364 s (rest.tsv times). -3. Kept with evidence: noisy_near_black_lands_within_five_percent (K=1, hang-only fast outcome). Protected: 6 tests. +1. Tests deleted: pixel_pipeline_runs_over_conformance_streams, cu_syntax_sweep_over_conformance_streams, motion_derivation_is_deterministic_over_conformance_streams (helpers `Row`, `sweep` and unused imports removed). +2. Seconds saved: about 317 s (rest.tsv times). +3. Kept with evidence: noisy_near_black_lands_within_five_percent (K=1, hang-only fast outcome) and ffmpeg_decodes_bit_exactly_at_every_shape (K'=1, hang-only). Protected: 6 tests. 4. Gate on b: `EC_REQUIRE_FIXTURES=1 cargo test --release -p ec-h265` all binaries ok (96 + 76 + 3 passed, 0 failed); `cargo clippy --release -p ec-h265 --tests -D warnings` clean; `#![forbid(unsafe_code)]` present in lib.rs. 5. `.config/nextest.toml` still names ffmpeg_decodes_bit_exactly_at_every_shape in the fast filter; harmless, left. `inter_placeholder_runs_over_pb_slices` was not heavy and is kept. Tools: `lanes/testcut/p2h265-tools/{run1.sh,fast.sh,recheck.sh,gate.sh,mutrun.py}`. Per-mutant rows: `lanes/testcut/p2h265-evidence/res-*.tsv`. + +Note: samples were 10 mutants per candidate. Evidence for motion_derivation and cu_syntax_sweep is thin (1 T-kill each, both also killed by the fast suite). +Recheck (lane -s2, quiet host, load 0.9, T baseline 22 s, timeout 63 s): all 3 ffmpeg hang mutants still hang in T alone (real kills under the lane rules). Fast profile: residual.rs:609 and residual.rs:430 fail with rc=100 (killed); ctu.rs:429 hangs past 2.5 x the 54 s fast baseline (and past 1200 s earlier), so it is not killed by the fast suite. The test was restored byte-for-byte from before the deletion (conformance.rs), so the gate result above for the remaining code still applies. diff --git a/lanes/testcut/p2h265-evidence/res-R2-F.tsv b/lanes/testcut/p2h265-evidence/res-R2-F.tsv new file mode 100644 index 00000000..d2a21b0e --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-R2-F.tsv @@ -0,0 +1,3 @@ +crates/ec-h265/src/residual.rs:609:42: replace + with - in residual_header KILLED rc=100 ran=81 timeout=False +crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/residual.rs:430:64: replace >> with << in rdoq KILLED rc=100 ran=86 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-R2-T.tsv b/lanes/testcut/p2h265-evidence/res-R2-T.tsv new file mode 100644 index 00000000..5a9c20f2 --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-R2-T.tsv @@ -0,0 +1,3 @@ +crates/ec-h265/src/residual.rs:609:42: replace + with - in residual_header KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/residual.rs:430:64: replace >> with << in rdoq KILLED rc=-1 ran=0 timeout=True diff --git a/lanes/testcut/p2h265-tools/recheck2.sh b/lanes/testcut/p2h265-tools/recheck2.sh new file mode 100644 index 00000000..843ad18b --- /dev/null +++ b/lanes/testcut/p2h265-tools/recheck2.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Recheck the 3 ffmpeg T-timeout mutants on a quiet host: T alone (2.5x measured baseline), then fast profile. +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +TOOLS=$PWD/lanes/testcut/p2h265-tools +OUT=$(dirname "$PWD")/out +echo "load: $(cat /proc/loadavg)" +F="test(/(^|::)ffmpeg_decodes_bit_exactly_at_every_shape\$/)" +cargo nextest run --release -p ec-h265 -E "$F" --no-run >/dev/null 2>&1 +S=$(date +%s); cargo nextest run --release -p ec-h265 -E "$F" > "$OUT/b2.log" 2>&1; echo "T baseline rc=$? $(( $(date +%s)-S ))s" +cat > "$OUT/names.json" <<'J' +["crates/ec-h265/src/residual.rs:609:42: replace + with - in residual_header","crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree","crates/ec-h265/src/residual.rs:430:64: replace >> with << in rdoq"] +J +python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/names.json" R2-T 63 "$F" +python3 - <<'P' +import json,os +o=os.environ.get("OUT") +P +awk -F'\t' '$2=="KILLED"{print $1}' "$OUT/res-R2-T.tsv" > "$OUT/k2.txt" +python3 -c "import json,sys;json.dump([l.rstrip('\n') for l in open(sys.argv[1]) if l.strip()],open(sys.argv[2],'w'))" "$OUT/k2.txt" "$OUT/k2.json" +cargo nextest run --release -p ec-h265 --profile fast --no-run >/dev/null 2>&1 +S=$(date +%s); cargo nextest run --release -p ec-h265 --profile fast --no-fail-fast > "$OUT/fb2.log" 2>&1; SECS=$(( $(date +%s)-S )); echo "fast baseline rc=$? ${SECS}s" +FAILFAST=1 python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/k2.json" R2-F $(( SECS*5/2+5 )) "all()" --profile fast +cut -f1,2,3 "$OUT"/res-R2-*.tsv | cut -c1-200 +echo R2_DONE