From 862cfda7a5844ed9477b406c853907e66d43fc9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 29 Sep 2026 05:48:13 +0300 Subject: [PATCH] test(av1): classify the count-vacuity sites by reading, and fix the first one Main's r7 item 1, done by READING rather than by regex, and printed per site so the classification is auditable: `ROW | | | bucket | candidate | spec_in_scope | | pixel_comparing`, on every run. Buckets, computed from each gate's own body (string-aware extent): b 38 live aomenc encode -> the count belongs to the ENCODER a 1 stream read from disk -> the count belongs to the pin c 4 census/probe -> report only, never fix ? 1 unclassified, with the reason printed rather than a guess A third offset bug, same family as the two r6 caught: the sweep handed its body-walk a LINE index where a BYTE offset was required, so every body-dependent classification read "unclassified" -- 40 of 44. It is the third time in this lane that a line/byte or slice-boundary confusion has silently produced a plausible-looking clean result. FIXED: stream.rs:3895, `a_real_aomenc_segmentation_stream_with_map_inheritance_ decodes_pixel_exact`. `ffmpeg_decode_sequence(..., pictures.len())` now passes `ENCODED_FRAMES` (40), the count its own `encode_aomenc_stream(...)` call encodes. Our decode's length was the thing UNDER TEST, so using it as the oracle's expected count was circular. Gate green, 2.05 s, now comparing 40 frames against ffmpeg's 40 rather than a self-fulfilling number. The sweep's "known site" anchor MOVED with the fix: it used to assert `pictures.len()` was still present, which went red the moment the fix landed. It now asserts the opposite -- no site may pass `pictures.len()` again -- plus that the dominant `frames.len()` shape is still found, so the sweep cannot go quiet by either route. NOT DONE, and this is the honest part: 38 of the 39 fixable sites. The sweep prints a `candidate` (the numeric frame count in the gate's own encode call) and it resolves for exactly ONE gate; the rest encode inside loops or through per-gate helpers whose frame-count argument must be read per gate. I am handing those back with the method rather than editing 38 call sites on a guess, for the same reason r6 refused the 44-row table on an untrustworthy column. gate_coverage 15, refusal_inventory 15, count_vacuity 2, pin_inventory 3, and the fixed gate all green. 0 warnings. Lane-scoped CARGO_TARGET_DIR with touch-first. --- crates/ec-av1/src/gate_coverage.rs | 144 +++++++++++++++++++++++++++-- crates/ec-av1/src/stream.rs | 11 ++- 2 files changed, 146 insertions(+), 9 deletions(-) diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index 7b5cf104..c9bb953f 100644 --- a/crates/ec-av1/src/gate_coverage.rs +++ b/crates/ec-av1/src/gate_coverage.rs @@ -2072,6 +2072,19 @@ mod count_vacuity { /// Does this gate actually COMPARE PIXELS (so a wrong count would /// corrupt a verdict), or is it a report-only probe? pub pixel_comparing: bool, + /// The fix bucket, by READING the gate (r7). `Some(b)` where + /// a = pinned stream on disk -> take the count from the PIN + /// b = live aomenc encode -> take it from the ENCODE's frame count; + /// our decode's length is the thing + /// UNDER TEST and must never be the + /// expected value + /// c = census/probe -> report only, never fix + /// `None` = could not classify, and the reason is in `bucket_reason`. + pub bucket: Option<&'static str>, + pub bucket_reason: String, + /// The numeric frame count found in this gate's own encode call, when + /// one is visible -- the value the compare should assert instead. + pub candidate: Option, /// A frame count already in scope that is a SPEC rather than a /// self-fulfilling number -- e.g. the `FRAMES` the gate encoded, or a /// count asserted on the pinned stream. `Some(..)` means the fix is a @@ -2079,9 +2092,65 @@ mod count_vacuity { pub fixable_from: Option, } + /// A census/probe/diagnostic gate: it reports, it does not assert a verdict. + fn is_probe(gate: &str) -> bool { + [ + "census", + "probe", + "sweep", + "first_diff", + "scratch", + "rectx", + "diagnostic", + ] + .iter() + .any(|m| gate.contains(m)) + } + + /// Encode helpers a gate can drive INDIRECTLY. The r7 extraction found 21 of + /// the 25 bucket-b gates encode through one of these, not through + /// `aomenc_path()` directly -- which is why a first pass that only looked for + /// `aomenc_path()` classified 6 gates "unclassified" that plainly encode. + fn enc_helpers(body: &str) -> Vec<&'static str> { + const NAMES: &[&str] = &[ + "encode_aomenc_stream", + "screen_intrabc_stream_at_depth", + "screen_intrabc_stream_with", + "libaom_encode_with", + "libaom_encode", + "run_multi_tile_gate", + "edge32_gate", + "rect_tx_tool_gate", + "the_chroma_rect_gates", + "restore_gate", + "cdef_gate", + "warp_gate", + "superres_gate", + "grain_gate", + "sgate", + ]; + NAMES + .iter() + .copied() + .filter(|n| body.contains(&format!("{n}("))) + .collect() + } + pub fn sites(src: &str) -> Vec { let mut out = Vec::new(); let lines: Vec<&str> = src.lines().collect(); + // LINE index -> BYTE offset. The body walk indexes `src.as_bytes()`, so + // handing it a line number walks from the wrong place entirely and every + // body-dependent classification reads "unclassified". Same bug I hit in + // the Python classifier one step earlier. + let mut offsets: Vec = Vec::with_capacity(lines.len()); + { + let mut o = 0usize; + for l in &lines { + offsets.push(o); + o += l.len() + 1; + } + } let mut gate = String::new(); let mut fn_start = 0usize; for (i, line) in lines.iter().enumerate() { @@ -2090,7 +2159,7 @@ mod count_vacuity { if let Some(n) = rest.split('(').next() { if !n.contains(' ') { gate = n.to_string(); - fn_start = i; + fn_start = offsets[i]; } } } @@ -2246,6 +2315,50 @@ mod count_vacuity { break; } } + // Bucket by READING the gate. A census/probe reports and never + // asserts, so its count is not a verdict and is left alone. A + // gate that drives aomenc takes the count from the ENCODE -- our + // decode's length is what is under test, so using it as the + // expected value is circular. A gate that reads a stream from + // disk takes it from that stream. + // The candidate fix: the numeric frame count in this gate's own + // encode call. For bucket (b) that number IS the encoder's frame + // count, so it is the spec the compare should assert. + let candidate = enc_helpers(body).first().and_then(|h| { + let at = body.find(&format!("{h}("))?; + let open = at + h.len() + 1; + let seg = &body[open..(open + 400).min(body.len())]; + let close = seg.find(';')?; + let nums: Vec<&str> = seg[..close] + .split(',') + .map(|x| x.trim()) + .filter(|x| !x.is_empty() && x.chars().all(|c| c.is_ascii_digit())) + .collect(); + nums.last().map(|x| x.to_string()) + }); + let (bucket, bucket_reason) = if is_probe(&gate) { + ( + Some("c"), + "census/probe: reports, does not assert a verdict".to_string(), + ) + } else if body.contains("aomenc_path()") || !enc_helpers(body).is_empty() { + ( + Some("b"), + "live aomenc encode: count belongs to the encoder".to_string(), + ) + } else if body.contains("fs::read") || body.contains("crate_pin") { + ( + Some("a"), + "stream read from disk: count belongs to the pin".to_string(), + ) + } else { + ( + None, + "unclassified: no aomenc drive, no disk read, and not a probe -- \ + needs a reader" + .to_string(), + ) + }; out.push(Site { line: i + 1, gate: gate.clone(), @@ -2253,6 +2366,9 @@ mod count_vacuity { pinned_by: pinned, pixel_comparing, fixable_from: fixable, + bucket, + bucket_reason, + candidate, }); } } @@ -2276,10 +2392,20 @@ mod count_vacuity_tests { shape", s.len() ); + // r7: the first reported site (3895, `pictures.len()`) is FIXED -- it now + // asserts `ENCODED_FRAMES`, the encode's own count. The anchor therefore + // moved from "the site is still there" to "the fix is still in place AND + // the dominant remaining shape is still found", so the sweep cannot go + // quiet by either route. + assert!( + !s.iter().any(|x| x.count_expr == "pictures.len()"), + "3895 regressed: a site is passing `pictures.len()` as the oracle's expected \ + count again -- our decode's length must never be the expected value" + ); assert!( - s.iter() - .any(|x| x.line == 3895 || x.count_expr == "pictures.len()"), - "the original reported site (pictures.len()) is gone -- re-derive the sweep" + s.iter().any(|x| x.count_expr == "frames.len()"), + "the dominant `frames.len()` shape is no longer found -- the sweep has lost a \ + shape, not gained a fix" ); } @@ -2315,12 +2441,16 @@ mod count_vacuity_tests { // The table Main asked for, as columns the guard itself computes. for x in s.iter().filter(|x| x.pinned_by.is_none()) { eprintln!( - "ROW {} | {} | {} | pixel_comparing={} | spec_in_scope={}", + "ROW {} | {} | {} | bucket={} | candidate={} | spec_in_scope={} | {} | \ + pixel_comparing={}", x.line, x.gate, x.count_expr, - x.pixel_comparing, - x.fixable_from.clone().unwrap_or_else(|| "-".into()) + x.bucket.unwrap_or("?"), + x.candidate.clone().unwrap_or_else(|| "-".into()), + x.fixable_from.clone().unwrap_or_else(|| "-".into()), + x.bucket_reason, + x.pixel_comparing ); } assert!( diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index ddcd4588..e344ee19 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3856,7 +3856,10 @@ pub(crate) mod tests { ("film mandelbrot", "mandelbrot", 192, 128), ]; for (arm, source, width, height) in &arms { - let stream = encode_aomenc_stream(source, *width, *height, 40, &extra); + // r7: the ENCODE's frame count, bound so the compare below asserts a + // spec rather than our own decode's length. + const ENCODED_FRAMES: usize = 40; + let stream = encode_aomenc_stream(source, *width, *height, ENCODED_FRAMES, &extra); // Premise: the shape under test really arrived -- segmentation on // every frame, the map both coded and inherited, and real ALT_Q // tables. An aomenc drift that dropped any of these would make @@ -3904,7 +3907,11 @@ pub(crate) mod tests { "{arm}: every block dequantized at the same qindex ({lo}) -- SEG_LVL_ALT_Q \ never changed any block's quantizer" ); - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, *width, *height, pictures.len()); + // `ENCODED_FRAMES`, not `pictures.len()`: our decode's length is the + // thing UNDER TEST, so using it as the oracle's expected count is + // circular -- a decode that dropped a frame would ask ffmpeg for the + // same short count and the compare would silently shrink. + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, *width, *height, ENCODED_FRAMES); for (i, (ours, theirs)) in pictures.iter().zip(&ffmpeg_frames).enumerate() { assert_eq!(ours.y, theirs.y, "{NAME} {arm}: frame {i} luma vs ffmpeg"); assert_eq!(ours.u, theirs.u, "{NAME} {arm}: frame {i} U vs ffmpeg");