From 0810a85d2ffcc32cf4ad89d9891744dc4dfab400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Sep 2026 22:28:54 +0300 Subject: [PATCH] test(av1): gate coverage is per (tool x bit depth), not per tool Every 10-bit gate ran --enable-restoration=0, so the 10-bit loop-restoration path was never exercised and two hbd defects (SGR box sums unscaled, Wiener clamp at the 8-bit bound) survived the '10-bit bit-exact' milestone. gate_coverage.rs now classifies each real-aomenc gate by bit depth and pins NEVER_EXERCISED_8BIT (12) and NEVER_EXERCISED_10BIT (19) over a fixed 26-flag TOOL_UNIVERSE, with the same 'defaulted means unknown' rule: only an explicit --enable-=1 in a gate of that depth retires an entry. 45 gates, 4 of them 10-bit. --- crates/ec-av1/src/gate_coverage.rs | 339 +++++++++++++++++++++++++++-- lanes/covbd-r1.report.md | 86 ++++++++ 2 files changed, 405 insertions(+), 20 deletions(-) create mode 100644 lanes/covbd-r1.report.md diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index 53165792..727088f6 100644 --- a/crates/ec-av1/src/gate_coverage.rs +++ b/crates/ec-av1/src/gate_coverage.rs @@ -39,39 +39,236 @@ const NEVER_EXERCISED: &[(&str, &str)] = &[ // lane could produce sits under TX_MODE_SELECT, whose inter var-tx // partition tree is unread -- so no stream reconstructs one end to end // yet and this entry stays. - ("enable-intrabc", "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree"), + ( + "enable-intrabc", + "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree", + ), +]; + +/// The `--enable-*` tools this decoder cares about, whether or not any gate +/// names one. A flag no gate mentions is *defaulted*, i.e. unknown, and by the +/// rule above unknown is not coverage -- so the universe is fixed here rather +/// than derived from the gate source, which would silently shrink to whatever +/// the gates happen to spell. +#[cfg(test)] +const TOOL_UNIVERSE: &[&str] = &[ + "enable-1to4-partitions", + "enable-ab-partitions", + "enable-angle-delta", + "enable-cdef", + "enable-cfl-intra", + "enable-dist-wtd-comp", + "enable-dual-filter", + "enable-filter-intra", + "enable-flip-idtx", + "enable-global-motion", + "enable-interintra-comp", + "enable-intra-edge-filter", + "enable-intrabc", + "enable-masked-comp", + "enable-obmc", + "enable-order-hint", + "enable-paeth-intra", + "enable-palette", + "enable-rect-partitions", + "enable-rect-tx", + "enable-ref-frame-mvs", + "enable-restoration", + "enable-smooth-intra", + "enable-superres", + "enable-tx64", + "enable-warped-motion", +]; + +/// Coverage is per (tool x bit depth), not per tool. +/// +/// lane-hbdinter found two 10-bit-only defects (SGR box sums unscaled, Wiener +/// clamp pinned at the 8-bit bound) that survived the "10-bit bit-exact" +/// milestone because every 10-bit gate passed `--enable-restoration=0`: +/// `enable-restoration` is positively exercised -- at 8 bits only. A tool the +/// 8-bit gates cover says nothing about the high-bit-depth path through the +/// same code, so the two lists below are pinned separately. +/// +/// Each entry is `(flag, why)`. A gate that passes `--enable-=1` at that +/// depth retires the entry, and this test fails until it is deleted. +#[cfg(test)] +const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[ + ( + "enable-1to4-partitions", + "off in 42 gates, on in none: PARTITION_HORZ_4/VERT_4 at 64x64 needs TX_64X16 luma plus 32x8 chroma scans (lane-part32 r5)", + ), + ( + "enable-angle-delta", + "off in 36 gates, on in none: the directional-intra gates pin it off to isolate the base modes", + ), + ( + "enable-cfl-intra", + "off in 41 gates, on in none: chroma-from-luma prediction is unimplemented", + ), + ( + "enable-dist-wtd-comp", + "off in 11 gates, on in none: distance-weighted compound is unimplemented", + ), + ( + "enable-dual-filter", + "never spelled by any gate, so defaulted = unknown; no stream is proven to carry per-direction interp filters", + ), + ( + "enable-flip-idtx", + "never spelled; the flip/identity transform types are unproven by a real stream", + ), + ( + "enable-global-motion", + "off in 5 gates, on in none at 8 bits; lane-gm owns the global-warp prediction that is still missing", + ), + ( + "enable-intrabc", + "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree", + ), + ( + "enable-rect-tx", + "never spelled; rect transforms reach the decoder only through partition shape, never through a gate that names the tool", + ), + ( + "enable-ref-frame-mvs", + "off in 27 gates, on in none: temporal MV projection is unimplemented", + ), + ( + "enable-superres", + "never spelled: the three superres gates drive `--superres-mode=1` instead, so the tool IS exercised but not under this flag -- retire this entry only by renaming the check, not by assuming coverage", + ), + ( + "enable-tx64", + "never spelled; TX_64X64 appears only where aomenc's default picks it, which is unknown per stream", + ), +]; + +#[cfg(test)] +const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ + // Only 4 of the 45 real-aomenc gates encode at 10 bits, and they pin the + // pixel filters and the intra tool set off. Every entry the 8-bit list + // carries is a hole here too; the seven extra ones below are tools an + // 8-bit gate DOES enable, whose high-bit-depth path no stream has ever + // touched -- exactly the shape that hid the two lane-hbdinter defects. + ( + "enable-1to4-partitions", + "hole at both depths, see the 8-bit list", + ), + ( + "enable-ab-partitions", + "8-bit only: no 10-bit gate enables AB partitions", + ), + ( + "enable-angle-delta", + "hole at both depths, see the 8-bit list", + ), + ( + "enable-cfl-intra", + "hole at both depths, see the 8-bit list", + ), + ( + "enable-dist-wtd-comp", + "hole at both depths, see the 8-bit list", + ), + ( + "enable-dual-filter", + "hole at both depths, see the 8-bit list", + ), + ( + "enable-filter-intra", + "8-bit only: no 10-bit gate enables filter intra", + ), + ( + "enable-flip-idtx", + "hole at both depths, see the 8-bit list", + ), + ( + "enable-global-motion", + "hole at both depths, see the 8-bit list", + ), + ( + "enable-intra-edge-filter", + "8-bit only: the 10-bit intra path never runs the edge filter", + ), + ("enable-intrabc", "hole at both depths, see the 8-bit list"), + ( + "enable-paeth-intra", + "8-bit only: no 10-bit gate enables Paeth", + ), + ( + "enable-rect-partitions", + "8-bit only: no 10-bit gate enables rect partitions", + ), + ("enable-rect-tx", "hole at both depths, see the 8-bit list"), + ( + "enable-ref-frame-mvs", + "hole at both depths, see the 8-bit list", + ), + ( + "enable-restoration", + "8-bit only -- THE instance this split was built for: every 10-bit gate passed `--enable-restoration=0`, so the SGR box sums and the Wiener clamp were never run at 10 bits and both were wrong (lane-hbdinter, 2026-09-01)", + ), + ( + "enable-smooth-intra", + "8-bit only: no 10-bit gate enables smooth intra", + ), + ( + "enable-superres", + "the 10-bit superres gate drives `--superres-mode=1`, not this flag; see the 8-bit entry", + ), + ("enable-tx64", "hole at both depths, see the 8-bit list"), ]; #[cfg(test)] mod tests { - use super::NEVER_EXERCISED; + use super::{NEVER_EXERCISED, NEVER_EXERCISED_8BIT, NEVER_EXERCISED_10BIT, TOOL_UNIVERSE}; use std::collections::{BTreeMap, BTreeSet}; - /// `--enable-*` settings per real-aomenc gate, derived from the gate - /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`. - fn tool_settings() -> (usize, BTreeMap) { + /// Bodies of the real-aomenc gates: a `fn` body carrying the shared + /// `--passes=1` every one of them passes. Split on the attribute that + /// opens a test. + fn gate_bodies() -> Vec<&'static str> { let src = include_str!("stream.rs"); - // A real-aomenc gate is a `fn` body carrying the shared `--passes=1` - // every one of them passes. Split on the attribute that opens a test. let gates: Vec<&str> = src .split("\n #[") .filter(|body| body.contains("\"--passes=1\"")) .collect(); - assert!(gates.len() >= 20, "expected the real-aomenc gates, found {}", gates.len()); + assert!( + gates.len() >= 20, + "expected the real-aomenc gates, found {}", + gates.len() + ); + gates + } + + /// `--enable-=` settings spelled inside one gate body. + fn flags_in(gate: &str) -> BTreeMap { + let mut here = BTreeMap::new(); + for (i, _) in gate.match_indices("\"--enable-") { + let rest = &gate[i + 3..]; + let Some(end) = rest.find('"') else { continue }; + let Some((flag, value)) = rest[..end].split_once('=') else { + continue; + }; + let Some(value) = value.chars().next() else { + continue; + }; + here.insert(flag.to_owned(), value); + } + here + } + + /// `--enable-*` settings per real-aomenc gate, derived from the gate + /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`. + fn tool_settings() -> (usize, BTreeMap) { + let gates = gate_bodies(); let mut per_tool: BTreeMap = BTreeMap::new(); let mut names: BTreeSet = BTreeSet::new(); let mut seen: Vec> = Vec::new(); for gate in &gates { - let mut here = BTreeMap::new(); - for (i, _) in gate.match_indices("\"--enable-") { - let rest = &gate[i + 3..]; - let Some(end) = rest.find('"') else { continue }; - let Some((flag, value)) = rest[..end].split_once('=') else { continue }; - let Some(value) = value.chars().next() else { continue }; - names.insert(flag.to_owned()); - here.insert(flag.to_owned(), value); - } + let here = flags_in(gate); + names.extend(here.keys().cloned()); seen.push(here); } for name in names { @@ -126,10 +323,112 @@ mod tests { #[test] fn tool_settings_reads_whole_flags() { let (gate_count, per_tool) = tool_settings(); - assert!(per_tool.contains_key("enable-cdef"), "expected --enable-cdef among the gate flags"); + assert!( + per_tool.contains_key("enable-cdef"), + "expected --enable-cdef among the gate flags" + ); for (name, &(off, on, defaulted)) in &per_tool { - assert!(!name.is_empty() && !name.contains(['"', '=']), "malformed flag {name:?}"); - assert_eq!(off + on + defaulted, gate_count, "{name} counts do not cover every gate"); + assert!( + !name.is_empty() && !name.contains(['"', '=']), + "malformed flag {name:?}" + ); + assert_eq!( + off + on + defaulted, + gate_count, + "{name} counts do not cover every gate" + ); + } + } + + /// A gate encodes at 10 bits when its recipe says so: the shared 10-bit + /// helper, an explicit `--bit-depth=10`/`--input-bit-depth=10`, or a + /// `yuv420p10le` fixture handed to aomenc. Everything else is aomenc's + /// 8-bit default. + fn is_ten_bit(body: &str) -> bool { + body.contains("encode_10bit_gradients") + || body.contains("--bit-depth=10") + || body.contains("--input-bit-depth=10") + || body.contains("yuv420p10le") + } + + /// Flags a gate positively enables (`=1`), at gates of the given depth. + fn enabled_at(ten_bit: bool) -> BTreeSet { + let mut on = BTreeSet::new(); + for gate in gate_bodies() { + if is_ten_bit(gate) != ten_bit { + continue; + } + for (flag, value) in flags_in(gate) { + if value == '1' { + on.insert(flag); + } + } + } + on + } + + /// The tools of [`TOOL_UNIVERSE`] that no gate of this depth enables. + fn never_exercised_at(ten_bit: bool) -> BTreeSet<&'static str> { + let on = enabled_at(ten_bit); + TOOL_UNIVERSE + .iter() + .copied() + .filter(|t| !on.contains(*t)) + .collect() + } + + fn check_depth(ten_bit: bool, listed: &[(&str, &str)]) { + let derived = never_exercised_at(ten_bit); + let listed: BTreeSet<&str> = listed.iter().map(|&(flag, _)| flag).collect(); + let depth = if ten_bit { "10-bit" } else { "8-bit" }; + let unlisted: Vec<&&str> = derived.difference(&listed).collect(); + assert!( + unlisted.is_empty(), + "no {depth} gate passes `=1` for {unlisted:?}, so no real {depth} stream exercises \ + them -- enable the tool in a {depth} gate that asserts it fired, or list it" + ); + let stale: Vec<&&str> = listed.difference(&derived).collect(); + assert!( + stale.is_empty(), + "the {depth} list still names {stale:?}, but a {depth} gate now passes `=1` for them \ + -- delete those entries, the coverage hole is closed" + ); + } + + #[test] + fn never_exercised_8bit_matches_the_gate_recipes() { + check_depth(false, NEVER_EXERCISED_8BIT); + } + + #[test] + fn never_exercised_10bit_matches_the_gate_recipes() { + check_depth(true, NEVER_EXERCISED_10BIT); + } + + /// `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` prints both + /// lists, so the per-depth holes can be read without opening this file. + #[test] + fn print_never_exercised_per_bit_depth() { + let ten: Vec<&str> = gate_bodies() + .into_iter() + .filter(|b| is_ten_bit(b)) + .collect(); + let total = gate_bodies().len(); + println!( + "gate_coverage: {} real-aomenc gates, {} of them 10-bit", + total, + ten.len() + ); + for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] { + let holes = never_exercised_at(ten_bit); + println!( + "NEVER_EXERCISED_{label} ({} of {}):", + holes.len(), + TOOL_UNIVERSE.len() + ); + for flag in &holes { + println!(" --{flag}"); + } } } } diff --git a/lanes/covbd-r1.report.md b/lanes/covbd-r1.report.md new file mode 100644 index 00000000..5e09ed7e --- /dev/null +++ b/lanes/covbd-r1.report.md @@ -0,0 +1,86 @@ +# lane-covbd r1 — gate coverage per (tool x bit depth) + +## What changed +- `crates/ec-av1/src/gate_coverage.rs` + - `TOOL_UNIVERSE` (26 `--enable-*` flags, fixed in source, not derived): the flags the + decoder cares about, so a flag *no* gate spells still counts as a hole (defaulted = + unknown, the pre-existing rule). + - `NEVER_EXERCISED_8BIT` (12 entries) / `NEVER_EXERCISED_10BIT` (19 entries), each + `(flag, why)`. + - tests `never_exercised_8bit_matches_the_gate_recipes` / + `never_exercised_10bit_matches_the_gate_recipes`: negative check (every listed entry + really has no `=1` at that depth) and positive check (a flag that a gate of that depth + now enables must be deleted from the list — the test fails until it is). + - `is_ten_bit(body)`: a gate is 10-bit if its recipe contains `encode_10bit_gradients`, + `--bit-depth=10`, `--input-bit-depth=10`, or a `yuv420p10le` fixture (that is how the + existing 10-bit gates spell it, stream.rs:1905/1934/2141/9001). + - `gate_bodies()` / `flags_in()` factored out of `tool_settings()`; the original + `NEVER_EXERCISED` list and its test are untouched. + - `print_never_exercised_per_bit_depth`: the orchestrator helper. +- No gate recipe touched; `stream.rs` unchanged. + +## Finding +45 real-aomenc gates, **4 of them 10-bit**. Seven tools are positively enabled at 8 bits and +by no 10-bit gate: `restoration`, `cdef`-adjacent intra set (`filter-intra`, +`intra-edge-filter`, `paeth-intra`, `smooth-intra`), `rect-partitions`, `ab-partitions`. +`enable-restoration` is the instance that cost two hbd defects (SGR box sums unscaled, +Wiener clamp at the 8-bit bound, lane-hbdinter 2026-09-01). + +Caveat recorded in the list itself: `enable-superres` is a *flag-spelling* hole, not a real +one — the three superres gates drive `--superres-mode=1` (one of them 10-bit). + +## Printed lists (verbatim) +``` +gate_coverage: 45 real-aomenc gates, 4 of them 10-bit +NEVER_EXERCISED_8BIT (12 of 26): + --enable-1to4-partitions + --enable-angle-delta + --enable-cfl-intra + --enable-dist-wtd-comp + --enable-dual-filter + --enable-flip-idtx + --enable-global-motion + --enable-intrabc + --enable-rect-tx + --enable-ref-frame-mvs + --enable-superres + --enable-tx64 +NEVER_EXERCISED_10BIT (19 of 26): + --enable-1to4-partitions + --enable-ab-partitions + --enable-angle-delta + --enable-cfl-intra + --enable-dist-wtd-comp + --enable-dual-filter + --enable-filter-intra + --enable-flip-idtx + --enable-global-motion + --enable-intra-edge-filter + --enable-intrabc + --enable-paeth-intra + --enable-rect-partitions + --enable-rect-tx + --enable-ref-frame-mvs + --enable-restoration + --enable-smooth-intra + --enable-superres + --enable-tx64 +``` + +## Gates / tests +- `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` -> 5 passed, 0 failed. +- `cargo test -p ec-av1 --lib refusal_inventory` -> 3 passed, 0 failed. +- `cargo check -p ec-av1` -> clean (118 pre-existing missing-doc warnings). +- EVIDENCE: crates/ec-av1/src/gate_coverage.rs | cargo test -p ec-av1 --lib gate_coverage -- --nocapture | 5/5 pass, 45 gates parsed, 4 ten-bit, 12/19 holes printed above + +## Refusals lifted +None — this lane is instrumentation only, no decode behaviour changed. + +## Residue +- accepted: `enable-superres` and `enable-cdef`-style aliasing. Tools driven by a non + `--enable-*` flag (`--superres-mode=1`) read as holes. Fix is an alias map, one line per + alias, when a second case appears. +- deferred: closing any 10-bit hole — other lanes own gate authoring; this lane was + chartered not to write gates. What unblocks it: a 10-bit gate passing `=1` for the tool. +- accepted: `cargo fmt -p ec-av1` reformatted 18 unrelated files; reverted, only + gate_coverage.rs is in the commit.