Pin the coding tools no real-aomenc gate exercises
Browse files at this commit21b2356702b3881c2727339e11cf0f038d6cae2aParent: 7895d2a- test
- pin the coding tools no real-aomenc gate exercises
2 changed files +114 -0
crates/ec-av1/src/gate_coverage.rsadded+113 -0
| @@ -0,0 +1,113 @@ | |||
| 1 | +//! A guard over the real-aomenc gates' own encoder recipes. | ||
| 2 | +//! | ||
| 3 | +//! Every gate in [`crate::stream`] that runs a real `aomenc` picks its coding | ||
| 4 | +//! tools with `--enable-*=0/1` flags, and a flag left off the command line | ||
| 5 | +//! takes aomenc's default (on, for the tools this decoder cares about). That | ||
| 6 | +//! makes it possible -- and it happened -- for a coding tool to be switched | ||
| 7 | +//! *off in every single gate*, so that no real stream in this repository ever | ||
| 8 | +//! exercised it and a corner-cut in the decoder survived twenty gates | ||
| 9 | +//! unnoticed: `reconstruct`'s `smooth_neighbor` was hardcoded `false`, wrong | ||
| 10 | +//! whenever a directional block neighbours a smooth-mode one, and invisible | ||
| 11 | +//! because all twenty gates passed `--enable-smooth-intra=0` | ||
| 12 | +//! (lane-chroma r1, 2026-08-30). | ||
| 13 | +//! | ||
| 14 | +//! The test below re-derives that set from the gate source and pins it. A tool | ||
| 15 | +//! that is switched off in every gate and on in none is *provably never | ||
| 16 | +//! exercised* by a real stream, and belongs on [`NEVER_EXERCISED`] with a | ||
| 17 | +//! reason. Landing the decode support for one means enabling it in that | ||
| 18 | +//! feature's gate, which shrinks the derived set and fails this test until the | ||
| 19 | +//! list is updated -- the point being that the shrink is noticed. | ||
| 20 | + | ||
| 21 | +/// aomenc coding tools that no real-`aomenc` gate exercises: switched off in | ||
| 22 | +/// every gate that names them, on in none, defaulted in none. | ||
| 23 | +/// | ||
| 24 | +/// Each entry is `(flag, why)`. Removing an entry is how a lane records that | ||
| 25 | +/// its tool is now covered by a real stream. | ||
| 26 | +#[cfg(test)] | ||
| 27 | +const NEVER_EXERCISED: &[(&str, &str)] = &[ | ||
| 28 | + ("enable-cdef", "cdef_idx is not read yet; the CDEF filter itself is implemented and unit-tested"), | ||
| 29 | + ("enable-intrabc", "intra block copy syntax is consumed but no block is reconstructed from it"), | ||
| 30 | + ("enable-paeth-intra", "chroma PAETH_PRED is refused; luma is unexercised against a real stream"), | ||
| 31 | + ("enable-palette", "palette syntax is consumed but no block is reconstructed from a palette"), | ||
| 32 | + ("enable-smooth-intra", "chroma SMOOTH_PRED is refused, and the intra edge filter's smooth-neighbour bucket is a known corner-cut"), | ||
| 33 | +]; | ||
| 34 | + | ||
| 35 | +#[cfg(test)] | ||
| 36 | +mod tests { | ||
| 37 | + use super::NEVER_EXERCISED; | ||
| 38 | + use std::collections::{BTreeMap, BTreeSet}; | ||
| 39 | + | ||
| 40 | + /// `--enable-*` settings per real-aomenc gate, derived from the gate | ||
| 41 | + /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`. | ||
| 42 | + fn tool_settings() -> (usize, BTreeMap<String, (usize, usize, usize)>) { | ||
| 43 | + let src = include_str!("stream.rs"); | ||
| 44 | + // A real-aomenc gate is a `fn` body carrying the shared `--passes=1` | ||
| 45 | + // every one of them passes. Split on the attribute that opens a test. | ||
| 46 | + let gates: Vec<&str> = src | ||
| 47 | + .split("\n #[") | ||
| 48 | + .filter(|body| body.contains("\"--passes=1\"")) | ||
| 49 | + .collect(); | ||
| 50 | + assert!(gates.len() >= 20, "expected the real-aomenc gates, found {}", gates.len()); | ||
| 51 | + | ||
| 52 | + let mut per_tool: BTreeMap<String, (usize, usize, usize)> = BTreeMap::new(); | ||
| 53 | + let mut names: BTreeSet<String> = BTreeSet::new(); | ||
| 54 | + let mut seen: Vec<BTreeMap<String, char>> = Vec::new(); | ||
| 55 | + for gate in &gates { | ||
| 56 | + let mut here = BTreeMap::new(); | ||
| 57 | + for (i, _) in gate.match_indices("\"--enable-") { | ||
| 58 | + let rest = &gate[i + 3..]; | ||
| 59 | + let Some(end) = rest.find('"') else { continue }; | ||
| 60 | + let Some((flag, value)) = rest[..end].split_once('=') else { continue }; | ||
| 61 | + let Some(value) = value.chars().next() else { continue }; | ||
| 62 | + names.insert(flag.to_owned()); | ||
| 63 | + here.insert(flag.to_owned(), value); | ||
| 64 | + } | ||
| 65 | + seen.push(here); | ||
| 66 | + } | ||
| 67 | + for name in names { | ||
| 68 | + let off = seen.iter().filter(|g| g.get(&name) == Some(&'0')).count(); | ||
| 69 | + let on = seen.iter().filter(|g| g.get(&name) == Some(&'1')).count(); | ||
| 70 | + per_tool.insert(name, (off, on, gates.len() - off - on)); | ||
| 71 | + } | ||
| 72 | + (gates.len(), per_tool) | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + #[test] | ||
| 76 | + fn every_gate_disabling_a_tool_is_a_listed_coverage_hole() { | ||
| 77 | + let (gate_count, per_tool) = tool_settings(); | ||
| 78 | + let derived: BTreeSet<&str> = per_tool | ||
| 79 | + .iter() | ||
| 80 | + .filter(|&(_, &(off, on, defaulted))| off == gate_count && on == 0 && defaulted == 0) | ||
| 81 | + .map(|(name, _)| name.as_str()) | ||
| 82 | + .collect(); | ||
| 83 | + let listed: BTreeSet<&str> = NEVER_EXERCISED.iter().map(|&(flag, _)| flag).collect(); | ||
| 84 | + | ||
| 85 | + let unlisted: Vec<&&str> = derived.difference(&listed).collect(); | ||
| 86 | + assert!( | ||
| 87 | + unlisted.is_empty(), | ||
| 88 | + "these aomenc tools are switched off in all {gate_count} real-aomenc gates and on in \ | ||
| 89 | + none, so no real stream exercises them, and they are not listed in NEVER_EXERCISED: \ | ||
| 90 | + {unlisted:?} -- either enable the tool in its own gate or add it to the list with a \ | ||
| 91 | + reason" | ||
| 92 | + ); | ||
| 93 | + let stale: Vec<&&str> = listed.difference(&derived).collect(); | ||
| 94 | + assert!( | ||
| 95 | + stale.is_empty(), | ||
| 96 | + "NEVER_EXERCISED lists {stale:?}, but a gate now enables or defaults them -- delete \ | ||
| 97 | + those entries, the coverage hole is closed" | ||
| 98 | + ); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + /// The derivation is only meaningful if a flag left off a gate's command | ||
| 102 | + /// line really does mean "aomenc's default", i.e. the parser above is | ||
| 103 | + /// reading whole flags and not fragments. | ||
| 104 | + #[test] | ||
| 105 | + fn tool_settings_reads_whole_flags() { | ||
| 106 | + let (gate_count, per_tool) = tool_settings(); | ||
| 107 | + assert!(per_tool.contains_key("enable-cdef"), "expected --enable-cdef among the gate flags"); | ||
| 108 | + for (name, &(off, on, defaulted)) in &per_tool { | ||
| 109 | + assert!(!name.is_empty() && !name.contains(['"', '=']), "malformed flag {name:?}"); | ||
| 110 | + assert_eq!(off + on + defaulted, gate_count, "{name} counts do not cover every gate"); | ||
| 111 | + } | ||
| 112 | + } | ||
| 113 | +} | ||
crates/ec-av1/src/lib.rsmodified+1 -0
| @@ -21,6 +21,7 @@ pub mod encode; | |||
| 21 | pub mod encoder; | 21 | pub mod encoder; |
| 22 | mod film_grain; | 22 | mod film_grain; |
| 23 | pub mod frame; | 23 | pub mod frame; |
| 24 | +mod gate_coverage; | ||
| 24 | pub mod intra; | 25 | pub mod intra; |
| 25 | pub mod mc; | 26 | pub mod mc; |
| 26 | pub mod motion; | 27 | pub mod motion; |