forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB576f72dTahinli3 months ago1275 commits

gate_coverage.rs423 lines, 17.1 KiBHistoryRawDownload
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 is proven to exercise:
22/// switched off in every gate that names them, and on in none.
23///
24/// A gate that simply leaves the flag off its command line does NOT close the
25/// hole. aomenc's default for these is content-dependent -- palette and
26/// intrabc only come on for screen content -- so "defaulted" means "unknown",
27/// not "exercised", and treating it as coverage would retire the entry
28/// without a single stream proving the decoder ever saw the tool. Only an
29/// explicit `--enable-<tool>=1` in a gate that then asserts the feature fired
30/// closes one.
31///
32/// Each entry is `(flag, why)`. Removing an entry is how a lane records that
33/// its tool is now covered by a real stream.
34#[cfg(test)]
35const NEVER_EXERCISED: &[(&str, &str)] = &[
36 // lane-intrabc r1: the DV itself (mv stack against INTRA_FRAME, `ndvc`
37 // full-pel read, `av1_find_ref_dv` fallback) and the block-copy
38 // prediction are now decoded, but every real aomenc intrabc block this
39 // lane could produce sits under TX_MODE_SELECT, whose inter var-tx
40 // partition tree is unread -- so no stream reconstructs one end to end
41 // yet and this entry stays.
42 (
43 "enable-intrabc",
44 "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree",
45 ),
46];
47
48/// The `--enable-*` tools this decoder cares about, whether or not any gate
49/// names one. A flag no gate mentions is *defaulted*, i.e. unknown, and by the
50/// rule above unknown is not coverage -- so the universe is fixed here rather
51/// than derived from the gate source, which would silently shrink to whatever
52/// the gates happen to spell.
53#[cfg(test)]
54const TOOL_UNIVERSE: &[&str] = &[
55 "enable-1to4-partitions",
56 "enable-ab-partitions",
57 "enable-angle-delta",
58 "enable-cdef",
59 "enable-cfl-intra",
60 "enable-dist-wtd-comp",
61 "enable-dual-filter",
62 "enable-filter-intra",
63 "enable-flip-idtx",
64 "enable-global-motion",
65 "enable-interintra-comp",
66 "enable-intra-edge-filter",
67 "enable-intrabc",
68 "enable-masked-comp",
69 "enable-obmc",
70 "enable-order-hint",
71 "enable-paeth-intra",
72 "enable-palette",
73 "enable-rect-partitions",
74 "enable-rect-tx",
75 "enable-ref-frame-mvs",
76 "enable-restoration",
77 "enable-smooth-intra",
78 "enable-superres",
79 "enable-tx64",
80 "enable-warped-motion",
81];
82
83/// Coverage is per (tool x bit depth), not per tool.
84///
85/// lane-hbdinter found two 10-bit-only defects (SGR box sums unscaled, Wiener
86/// clamp pinned at the 8-bit bound) that survived the "10-bit bit-exact"
87/// milestone because every 10-bit gate passed `--enable-restoration=0`:
88/// `enable-restoration` is positively exercised -- at 8 bits only. A tool the
89/// 8-bit gates cover says nothing about the high-bit-depth path through the
90/// same code, so the two lists below are pinned separately.
91///
92/// Each entry is `(flag, why)`. A gate that passes `--enable-<tool>=1` at that
93/// depth retires the entry, and this test fails until it is deleted.
94#[cfg(test)]
95const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[
96 (
97 "enable-1to4-partitions",
98 "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)",
99 ),
100 (
101 "enable-angle-delta",
102 "off in 36 gates, on in none: the directional-intra gates pin it off to isolate the base modes",
103 ),
104 (
105 "enable-cfl-intra",
106 "off in 41 gates, on in none: chroma-from-luma prediction is unimplemented",
107 ),
108 (
109 "enable-dist-wtd-comp",
110 "off in 11 gates, on in none: distance-weighted compound is unimplemented",
111 ),
112 (
113 "enable-dual-filter",
114 "never spelled by any gate, so defaulted = unknown; no stream is proven to carry per-direction interp filters",
115 ),
116 (
117 "enable-flip-idtx",
118 "never spelled; the flip/identity transform types are unproven by a real stream",
119 ),
120 (
121 "enable-global-motion",
122 "off in 5 gates, on in none at 8 bits; lane-gm owns the global-warp prediction that is still missing",
123 ),
124 (
125 "enable-intrabc",
126 "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree",
127 ),
128 (
129 "enable-rect-tx",
130 "never spelled; rect transforms reach the decoder only through partition shape, never through a gate that names the tool",
131 ),
132 (
133 "enable-ref-frame-mvs",
134 "off in 27 gates, on in none: temporal MV projection is unimplemented",
135 ),
136 (
137 "enable-superres",
138 "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",
139 ),
140 (
141 "enable-tx64",
142 "never spelled; TX_64X64 appears only where aomenc's default picks it, which is unknown per stream",
143 ),
144];
145
146#[cfg(test)]
147const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[
148 // Only 4 of the 45 real-aomenc gates encode at 10 bits, and they pin the
149 // pixel filters and the intra tool set off. Every entry the 8-bit list
150 // carries is a hole here too. lane-hbdgates r1 closed six of the seven
151 // 8-bit-only entries with real 10-bit gates (filter-intra, smooth-intra,
152 // paeth-intra, intra-edge-filter, rect-partitions, ab-partitions); the
153 // seventh, `enable-restoration`, has a 10-bit gate that FAILS and is
154 // therefore `#[ignore]`d, so its hole stays open.
155 (
156 "enable-1to4-partitions",
157 "hole at both depths, see the 8-bit list",
158 ),
159 (
160 "enable-angle-delta",
161 "hole at both depths, see the 8-bit list",
162 ),
163 (
164 "enable-cfl-intra",
165 "hole at both depths, see the 8-bit list",
166 ),
167 (
168 "enable-dist-wtd-comp",
169 "hole at both depths, see the 8-bit list",
170 ),
171 (
172 "enable-dual-filter",
173 "hole at both depths, see the 8-bit list",
174 ),
175 (
176 "enable-flip-idtx",
177 "hole at both depths, see the 8-bit list",
178 ),
179 (
180 "enable-global-motion",
181 "hole at both depths, see the 8-bit list",
182 ),
183 ("enable-intrabc", "hole at both depths, see the 8-bit list"),
184 ("enable-rect-tx", "hole at both depths, see the 8-bit list"),
185 (
186 "enable-ref-frame-mvs",
187 "hole at both depths, see the 8-bit list",
188 ),
189 (
190 "enable-restoration",
191 "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). lane-hbdgates r1 WROTE the 10-bit LR gate (`a_real_aomenc_10bit_restoration_stream_decodes_pixel_exact`) and it FAILS pixel-exact on a stream where the LR filters demonstrably ran (lr_hits=2, seed 42, frame 0, Y index 122: ours 351 vs ffmpeg 350), so it is `#[ignore]`d and the hole stays open until that defect is fixed",
192 ),
193 (
194 "enable-superres",
195 "the 10-bit superres gate drives `--superres-mode=1`, not this flag; see the 8-bit entry",
196 ),
197 ("enable-tx64", "hole at both depths, see the 8-bit list"),
198];
199
200#[cfg(test)]
201mod tests {
202 use super::{NEVER_EXERCISED, NEVER_EXERCISED_8BIT, NEVER_EXERCISED_10BIT, TOOL_UNIVERSE};
203 use std::collections::{BTreeMap, BTreeSet};
204
205 /// Bodies of the real-aomenc gates: a `fn` body carrying the shared
206 /// `--passes=1` every one of them passes. Split on the attribute that
207 /// opens a test.
208 fn gate_bodies() -> Vec<&'static str> {
209 let src = include_str!("stream.rs");
210 let gates: Vec<&str> = src
211 .split("\n #[")
212 // lane-hbdgates r1: an `#[ignore]`d gate exercises nothing, so it
213 // must not close a hole. Its body is the segment that opens with
214 // the ignore attribute.
215 .filter(|body| !body.starts_with("ignore"))
216 // lane-hbdgates r1: gates that build their stream through the
217 // shared 10-bit helpers spell `--passes=1` there, not inline.
218 .filter(|body| {
219 body.contains("\"--passes=1\"")
220 || body.contains("ten_bit_tool_gate(")
221 || body.contains("encode_10bit_gradients")
222 })
223 .collect();
224 assert!(
225 gates.len() >= 20,
226 "expected the real-aomenc gates, found {}",
227 gates.len()
228 );
229 gates
230 }
231
232 /// `--enable-<flag>=<value>` settings spelled inside one gate body.
233 fn flags_in(gate: &str) -> BTreeMap<String, char> {
234 let mut here = BTreeMap::new();
235 for (i, _) in gate.match_indices("\"--enable-") {
236 let rest = &gate[i + 3..];
237 let Some(end) = rest.find('"') else { continue };
238 let Some((flag, value)) = rest[..end].split_once('=') else {
239 continue;
240 };
241 let Some(value) = value.chars().next() else {
242 continue;
243 };
244 here.insert(flag.to_owned(), value);
245 }
246 here
247 }
248
249 /// `--enable-*` settings per real-aomenc gate, derived from the gate
250 /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`.
251 fn tool_settings() -> (usize, BTreeMap<String, (usize, usize, usize)>) {
252 let gates = gate_bodies();
253
254 let mut per_tool: BTreeMap<String, (usize, usize, usize)> = BTreeMap::new();
255 let mut names: BTreeSet<String> = BTreeSet::new();
256 let mut seen: Vec<BTreeMap<String, char>> = Vec::new();
257 for gate in &gates {
258 let here = flags_in(gate);
259 names.extend(here.keys().cloned());
260 seen.push(here);
261 }
262 for name in names {
263 let off = seen.iter().filter(|g| g.get(&name) == Some(&'0')).count();
264 let on = seen.iter().filter(|g| g.get(&name) == Some(&'1')).count();
265 per_tool.insert(name, (off, on, gates.len() - off - on));
266 }
267 (gates.len(), per_tool)
268 }
269
270 #[test]
271 fn every_gate_disabling_a_tool_is_a_listed_coverage_hole() {
272 let (gate_count, per_tool) = tool_settings();
273 // A hole OPENS when every gate names the flag and every one of them
274 // says 0 -- then no real stream can exercise the tool.
275 let derived: BTreeSet<&str> = per_tool
276 .iter()
277 .filter(|&(_, &(off, on, defaulted))| off == gate_count && on == 0 && defaulted == 0)
278 .map(|(name, _)| name.as_str())
279 .collect();
280 // A hole CLOSES only on positive evidence: some gate passes `=1`.
281 // A gate that merely leaves the flag off its command line proves
282 // nothing -- aomenc's default for palette and intrabc is content-
283 // dependent -- so "defaulted" must not retire an entry, or a listing
284 // would disappear the moment an unrelated gate is added.
285 let exercised: BTreeSet<&str> = per_tool
286 .iter()
287 .filter(|&(_, &(_, on, _))| on > 0)
288 .map(|(name, _)| name.as_str())
289 .collect();
290 let listed: BTreeSet<&str> = NEVER_EXERCISED.iter().map(|&(flag, _)| flag).collect();
291
292 let unlisted: Vec<&&str> = derived.difference(&listed).collect();
293 assert!(
294 unlisted.is_empty(),
295 "these aomenc tools are switched off in all {gate_count} real-aomenc gates and on in \
296 none, so no real stream exercises them, and they are not listed in NEVER_EXERCISED: \
297 {unlisted:?} -- either enable the tool with `=1` in its own gate or add it to the \
298 list with a reason"
299 );
300 let stale: Vec<&&str> = listed.intersection(&exercised).collect();
301 assert!(
302 stale.is_empty(),
303 "NEVER_EXERCISED lists {stale:?}, but a gate now passes `=1` for them -- delete \
304 those entries, the coverage hole is closed"
305 );
306 }
307
308 /// The derivation is only meaningful if a flag left off a gate's command
309 /// line really does mean "aomenc's default", i.e. the parser above is
310 /// reading whole flags and not fragments.
311 #[test]
312 fn tool_settings_reads_whole_flags() {
313 let (gate_count, per_tool) = tool_settings();
314 assert!(
315 per_tool.contains_key("enable-cdef"),
316 "expected --enable-cdef among the gate flags"
317 );
318 for (name, &(off, on, defaulted)) in &per_tool {
319 assert!(
320 !name.is_empty() && !name.contains(['"', '=']),
321 "malformed flag {name:?}"
322 );
323 assert_eq!(
324 off + on + defaulted,
325 gate_count,
326 "{name} counts do not cover every gate"
327 );
328 }
329 }
330
331 /// A gate encodes at 10 bits when its recipe says so: the shared 10-bit
332 /// helper, an explicit `--bit-depth=10`/`--input-bit-depth=10`, or a
333 /// `yuv420p10le` fixture handed to aomenc. Everything else is aomenc's
334 /// 8-bit default.
335 fn is_ten_bit(body: &str) -> bool {
336 body.contains("encode_10bit_gradients")
337 || body.contains("ten_bit_tool_gate(")
338 || body.contains("--bit-depth=10")
339 || body.contains("--input-bit-depth=10")
340 || body.contains("yuv420p10le")
341 }
342
343 /// Flags a gate positively enables (`=1`), at gates of the given depth.
344 fn enabled_at(ten_bit: bool) -> BTreeSet<String> {
345 let mut on = BTreeSet::new();
346 for gate in gate_bodies() {
347 if is_ten_bit(gate) != ten_bit {
348 continue;
349 }
350 for (flag, value) in flags_in(gate) {
351 if value == '1' {
352 on.insert(flag);
353 }
354 }
355 }
356 on
357 }
358
359 /// The tools of [`TOOL_UNIVERSE`] that no gate of this depth enables.
360 fn never_exercised_at(ten_bit: bool) -> BTreeSet<&'static str> {
361 let on = enabled_at(ten_bit);
362 TOOL_UNIVERSE
363 .iter()
364 .copied()
365 .filter(|t| !on.contains(*t))
366 .collect()
367 }
368
369 fn check_depth(ten_bit: bool, listed: &[(&str, &str)]) {
370 let derived = never_exercised_at(ten_bit);
371 let listed: BTreeSet<&str> = listed.iter().map(|&(flag, _)| flag).collect();
372 let depth = if ten_bit { "10-bit" } else { "8-bit" };
373 let unlisted: Vec<&&str> = derived.difference(&listed).collect();
374 assert!(
375 unlisted.is_empty(),
376 "no {depth} gate passes `=1` for {unlisted:?}, so no real {depth} stream exercises \
377 them -- enable the tool in a {depth} gate that asserts it fired, or list it"
378 );
379 let stale: Vec<&&str> = listed.difference(&derived).collect();
380 assert!(
381 stale.is_empty(),
382 "the {depth} list still names {stale:?}, but a {depth} gate now passes `=1` for them \
383 -- delete those entries, the coverage hole is closed"
384 );
385 }
386
387 #[test]
388 fn never_exercised_8bit_matches_the_gate_recipes() {
389 check_depth(false, NEVER_EXERCISED_8BIT);
390 }
391
392 #[test]
393 fn never_exercised_10bit_matches_the_gate_recipes() {
394 check_depth(true, NEVER_EXERCISED_10BIT);
395 }
396
397 /// `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` prints both
398 /// lists, so the per-depth holes can be read without opening this file.
399 #[test]
400 fn print_never_exercised_per_bit_depth() {
401 let ten: Vec<&str> = gate_bodies()
402 .into_iter()
403 .filter(|b| is_ten_bit(b))
404 .collect();
405 let total = gate_bodies().len();
406 println!(
407 "gate_coverage: {} real-aomenc gates, {} of them 10-bit",
408 total,
409 ten.len()
410 );
411 for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] {
412 let holes = never_exercised_at(ten_bit);
413 println!(
414 "NEVER_EXERCISED_{label} ({} of {}):",
415 holes.len(),
416 TOOL_UNIVERSE.len()
417 );
418 for flag in &holes {
419 println!(" --{flag}");
420 }
421 }
422 }
423}