forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB84fa44cTahinli2 months ago3331 commits

gate_coverage.rs691 lines, 29.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// TILING is deliberately NOT in this derivation (lane-tiles r11): the check
22// keys on `--enable-<tool>=0/1`, and `--tile-columns=<log2>` has no such
23// shape -- a `--tile-columns=` presence check would also read `=0` (one tile)
24// as coverage, which is the opposite of what it would claim. It needs no
25// entry either: 13 gates spell `--tile-columns`/`--tile-rows` with a nonzero
26// log2 and assert the parsed `tile_info` really carries the grid, and
27// `run_multi_tile_gate` covers a 2D grid with the coding tools ON at both
28// bit depths.
29
30/// aomenc coding tools that no real-`aomenc` gate is proven to exercise:
31/// switched off in every gate that names them, and on in none.
32///
33/// A gate that simply leaves the flag off its command line does NOT close the
34/// hole. aomenc's default for these is content-dependent -- palette and
35/// intrabc only come on for screen content -- so "defaulted" means "unknown",
36/// not "exercised", and treating it as coverage would retire the entry
37/// without a single stream proving the decoder ever saw the tool. Only an
38/// explicit `--enable-<tool>=1` in a gate that then asserts the feature fired
39/// closes one.
40///
41/// Each entry is `(flag, why)`. Removing an entry is how a lane records that
42/// its tool is now covered by a real stream.
43#[cfg(test)]
44const NEVER_EXERCISED: &[(&str, &str)] = &[
45 // `enable-intrabc` LEFT this list on 2026-09-02 (lane-kf900 r6). The
46 // premise it carried -- "every real stream's intrabc block sits under
47 // TX_MODE_SELECT" -- was false: with `--enable-tx-size-search=0` aomenc
48 // codes intrabc blocks under TX_MODE_LARGEST, and
49 // `a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips`
50 // spells `--enable-intrabc=1` and decodes three such 8-bit streams whole-
51 // frame pixel-exact against ffmpeg, with the block counter asserted > 0.
52 // Re-verified 2026-09-17 (lane-av1-intrabc) at main f715d70c: 185 rect
53 // `use_intrabc` symbols read, and 5 blocks took the DV path -- 4 of them
54 // DECODED whole-frame pixel-exact across 4 arms (7 frames compared, 0
55 // mismatches). The fifth is the testsrc2 rectangle-strip arm, which reads
56 // the symbol and then refuses by name (the `intrabc_hits` bump happens on
57 // the READ), so "5 blocks decoded" would overcount: 4 decoded + 1 refused,
58 // exactly the single `refused == 1` the gate asserts.
59];
60
61/// The `--enable-*` tools this decoder cares about, whether or not any gate
62/// names one. A flag no gate mentions is *defaulted*, i.e. unknown, and by the
63/// rule above unknown is not coverage -- so the universe is fixed here rather
64/// than derived from the gate source, which would silently shrink to whatever
65/// the gates happen to spell.
66#[cfg(test)]
67const TOOL_UNIVERSE: &[&str] = &[
68 "enable-1to4-partitions",
69 "enable-ab-partitions",
70 "enable-angle-delta",
71 "enable-cdef",
72 "enable-cfl-intra",
73 "enable-dist-wtd-comp",
74 "enable-dual-filter",
75 "enable-filter-intra",
76 "enable-flip-idtx",
77 "enable-global-motion",
78 "enable-interintra-comp",
79 "enable-intra-edge-filter",
80 "enable-intrabc",
81 "enable-masked-comp",
82 "enable-obmc",
83 "enable-order-hint",
84 "enable-paeth-intra",
85 "enable-palette",
86 "enable-rect-partitions",
87 "enable-rect-tx",
88 "enable-ref-frame-mvs",
89 "enable-restoration",
90 "enable-smooth-intra",
91 "enable-superres",
92 "enable-tx64",
93 "enable-warped-motion",
94];
95
96/// How a non-boolean aomenc knob reads as "the tool is on".
97#[cfg(test)]
98#[derive(Clone, Copy, PartialEq)]
99enum On {
100 /// Any non-zero value enables the tool (`--tile-columns=1`, `--loopfilter-control=1`).
101 NonZero,
102 /// The tool's search only runs at or below this speed (`--cpu-used`).
103 AtMost(u32),
104}
105
106/// Coding tools aomenc drives through a spelling [`TOOL_UNIVERSE`] does not
107/// cover, listed with their aomenc default.
108///
109/// lane-covbd's derivation read `--enable-*` flags only, so a tool a gate pins
110/// off through another spelling was invisible: all 49 gates that name it pass
111/// `--enable-tx-size-search=0`, and the real-stream PANIC hiding behind that
112/// pin was found by lane-ab16, not by this guard. `--loopfilter-control=0`,
113/// `--tile-columns=0` and a `--cpu-used` high enough to switch a search off are
114/// the same shape.
115///
116/// Each entry is `(tool, spellings, aomenc default, what counts as on)`. The
117/// "defaulted means unknown" rule of [`NEVER_EXERCISED`] applies unchanged: a
118/// default of `1` does not prove the encoder picked the tool for any stream, so
119/// only a gate that spells an on-value at that bit depth retires an entry.
120#[cfg(test)]
121const DEFAULT_ON_TOOLS: &[(&str, &[&str], &str, On)] = &[
122 (
123 "enable-tx-size-search",
124 &["enable-tx-size-search"],
125 "1",
126 On::NonZero,
127 ),
128 (
129 "enable-directional-intra",
130 &["enable-directional-intra"],
131 "1",
132 On::NonZero,
133 ),
134 (
135 "enable-smooth-interintra",
136 &["enable-smooth-interintra"],
137 "1",
138 On::NonZero,
139 ),
140 (
141 "enable-interintra-wedge",
142 &["enable-interintra-wedge"],
143 "1",
144 On::NonZero,
145 ),
146 (
147 "enable-diff-wtd-comp",
148 &["enable-diff-wtd-comp"],
149 "1",
150 On::NonZero,
151 ),
152 (
153 "enable-onesided-comp",
154 &["enable-onesided-comp"],
155 "1",
156 On::NonZero,
157 ),
158 ("enable-fwd-kf", &["enable-fwd-kf"], "0", On::NonZero),
159 ("deblocking", &["loopfilter-control"], "1", On::NonZero),
160 (
161 "multi-tile",
162 &["tile-columns", "tile-rows"],
163 "0",
164 On::NonZero,
165 ),
166 ("intrabc-search", &["cpu-used"], "0", On::AtMost(2)),
167];
168
169/// Non-`--enable-*` spellings that drive a [`TOOL_UNIVERSE`] tool.
170///
171/// `--superres-mode=1` is how all three superres gates switch superres on;
172/// without this map they read as an `enable-superres` hole while a real stream
173/// exercises the tool (lane-covbd deferred exactly this).
174#[cfg(test)]
175const ALIASES: &[(&str, &str)] = &[("superres-mode", "enable-superres")];
176
177/// Coverage is per (tool x bit depth), not per tool.
178///
179/// lane-hbdinter found two 10-bit-only defects (SGR box sums unscaled, Wiener
180/// clamp pinned at the 8-bit bound) that survived the "10-bit bit-exact"
181/// milestone because every 10-bit gate passed `--enable-restoration=0`:
182/// `enable-restoration` is positively exercised -- at 8 bits only. A tool the
183/// 8-bit gates cover says nothing about the high-bit-depth path through the
184/// same code, so the two lists below are pinned separately.
185///
186/// Each entry is `(flag, why)`. A gate that passes `--enable-<tool>=1` at that
187/// depth retires the entry, and this test fails until it is deleted.
188#[cfg(test)]
189const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[
190 // `enable-cfl-intra` LEFT both lists on 2026-09-02 (lane-reelckf r1): the
191 // sb128 skipped-CfL / 1:4-chroma gate passes `--enable-cfl-intra=1` at 8
192 // AND 10 bits and pixel-compares both arms.
193 (
194 "enable-dist-wtd-comp",
195 "off in 11 gates, on in none: distance-weighted compound is unimplemented",
196 ),
197 (
198 "enable-dual-filter",
199 "never spelled by any gate, so defaulted = unknown; no stream is proven to carry per-direction interp filters",
200 ),
201 (
202 "enable-flip-idtx",
203 "never spelled; the flip/identity transform types are unproven by a real stream",
204 ),
205 // `enable-global-motion` LEFT this list on 2026-09-25 (lane-av1gwarp12 r2):
206 // `a_real_affine_global_motion_stream_decodes_pixel_exact` loops
207 // `for depth in [8u32, 10u32]` passing `--enable-global-motion=1` and
208 // pixel-compares both depths, so the 8-bit hole has been closed since
209 // lane-gmaffine r1 -- the entry survived because no suite ran a tree
210 // containing both the gate and this test until the ROTZOOM suite.
211 // The 12-bit ROTZOOM gate rides the high-depth bucket via `encode_12bit(`
212 // in `is_ten_bit`, so it plays no part in this retirement.
213 (
214 "enable-rect-tx",
215 "never spelled; rect transforms reach the decoder only through partition shape, never through a gate that names the tool",
216 ),
217];
218
219#[cfg(test)]
220const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[
221 // lane-cwarp's 10-bit compound-global-warp gate closed `enable-global-motion`
222 // and `enable-dist-wtd-comp` at 10 bits without deleting their entries here,
223 // so this list was already stale (and this test already red) at main 9c35ecc;
224 // lane-tiles r11's multi-tile 10-bit gates then closed `enable-ab-partitions`,
225 // `enable-rect-partitions` and `enable-restoration` at 10 bits. All five
226 // deleted together.
227
228 // Only 4 of the 45 real-aomenc gates encode at 10 bits, and they pin the
229 // pixel filters and the intra tool set off. Every entry the 8-bit list
230 // carries is a hole here too. lane-hbdgates r1 closed six of the seven
231 // 8-bit-only entries with real 10-bit gates (filter-intra, smooth-intra,
232 // paeth-intra, intra-edge-filter, rect-partitions, ab-partitions); its
233 // seventh, the 10-bit LR gate, was `#[ignore]`d on that branch and passes
234 // un-ignored on main, which carries the fix.
235 // `enable-restoration` LEFT this list on 2026-09-01: lane-hbdinter's
236 // 10-bit inter gate passes `--enable-restoration=1` and asserts a real
237 // Wiener/SGR unit fired, which is what caught the two defects (SGR box
238 // sums never brought back to the 8-bit scale, Wiener clamp at the wrong
239 // bound). `enable-dist-wtd-comp` and `enable-global-motion` left it the
240 // same day for the same reason: lane-cwarp's 10-bit compound global-warp
241 // gate passes `=1` for both. `enable-1to4-partitions` left it on 2026-09-02:
242 // lane-tx64x16 r4's 32-level 1:4 gate has a 10-bit arm that asserts both
243 // orientations and coded strips inside pixel-exact attempts.
244 (
245 "enable-dual-filter",
246 "hole at both depths, see the 8-bit list",
247 ),
248 // `enable-flip-idtx` LEFT this list on 2026-09-02 (lane-rect1d r1):
249 // `a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact`
250 // passes `=1` at both depths and pixel-compares six 10-bit decodes, so the
251 // flip/identity/1D transform types are proven to reach a real 10-bit stream
252 // this decoder reconstructs exactly (10 of its rect coefficient TUs carry a
253 // 1D tx class).
254 // `enable-intrabc` LEFT this 10-bit list on 2026-09-02 (lane-kf900 r6).
255 // The entry it first rested on was a flag spelling -- the palette gate's
256 // `smptebars-screen-txs-cq40/cq55` arms pass `--enable-intrabc=1` -- and
257 // lane-av1-intrabc MEASURED that those arms decode ZERO intrabc blocks at
258 // both depths, so they retired the entry without a stream carrying the
259 // tool (class `tool-disabled-in-every-gate`, the same defect this list
260 // exists for). The closing evidence is now
261 // `an_sb128_screen_stream_with_intrabc_decodes_pixel_exact`: its sb128
262 // screen recipes run at 10 bits and hard-assert a decoded intrabc block
263 // per depth (4-6 per arm), every frame pixel-compared against ffmpeg's own
264 // 10-bit decode.
265 ("enable-rect-tx", "hole at both depths, see the 8-bit list"),
266];
267
268/// [`DEFAULT_ON_TOOLS`] entries no 8-bit gate spells on, with the reason.
269///
270/// Each entry is `(tool, why)`; the reason states whether the tool is pinned
271/// OFF in every gate that names it (a hard hole -- no stream can carry it) or
272/// merely defaulted (unknown, and unknown is not coverage).
273#[cfg(test)]
274const NEVER_ON_8BIT: &[(&str, &str)] = &[];
275
276/// [`DEFAULT_ON_TOOLS`] entries no 10-bit gate spells on, with the reason.
277#[cfg(test)]
278const NEVER_ON_10BIT: &[(&str, &str)] = &[];
279
280#[cfg(test)]
281mod tests {
282 use super::{
283 On, ALIASES, DEFAULT_ON_TOOLS, NEVER_EXERCISED, NEVER_EXERCISED_10BIT,
284 NEVER_EXERCISED_8BIT, NEVER_ON_10BIT, NEVER_ON_8BIT, TOOL_UNIVERSE,
285 };
286 use std::collections::{BTreeMap, BTreeSet};
287
288 /// Bodies of the real-aomenc gates: a `fn` body carrying the shared
289 /// `--passes=1` every one of them passes. Split on the attribute that
290 /// opens a test.
291 fn gate_bodies() -> Vec<&'static str> {
292 let src = include_str!("stream.rs");
293 let gates: Vec<&str> = src
294 .split("\n #[")
295 // lane-hbdgates r1: an `#[ignore]`d gate exercises nothing, so it
296 // must not close a hole. Its body is the segment that opens with
297 // the ignore attribute.
298 .filter(|body| !body.starts_with("ignore"))
299 // lane-hbdgates r1: gates that build their stream through the
300 // shared 10-bit helpers spell `--passes=1` there, not inline.
301 .filter(|body| {
302 body.contains("\"--passes=1\"")
303 || body.contains("ten_bit_tool_gate(")
304 || body.contains("encode_10bit_gradients")
305 })
306 .collect();
307 assert!(
308 gates.len() >= 20,
309 "expected the real-aomenc gates, found {}",
310 gates.len()
311 );
312 gates
313 }
314
315 /// `--enable-<flag>=<value>` settings spelled inside one gate body.
316 fn flags_in(gate: &str) -> BTreeMap<String, char> {
317 let mut here = BTreeMap::new();
318 for (i, _) in gate.match_indices("\"--enable-") {
319 let rest = &gate[i + 3..];
320 let Some(end) = rest.find('"') else { continue };
321 let Some((flag, value)) = rest[..end].split_once('=') else {
322 continue;
323 };
324 let Some(value) = value.chars().next() else {
325 continue;
326 };
327 here.insert(flag.to_owned(), value);
328 }
329 here
330 }
331
332 /// Every `--flag=value` spelled inside one gate body, values kept whole
333 /// (`--cpu-used=4`, `--tile-columns=2`), not just their first character.
334 fn settings_in(gate: &str) -> BTreeMap<String, String> {
335 let mut here = BTreeMap::new();
336 for (i, _) in gate.match_indices("\"--") {
337 let rest = &gate[i + 3..];
338 let Some(end) = rest.find('"') else { continue };
339 let Some((flag, value)) = rest[..end].split_once('=') else {
340 continue;
341 };
342 here.insert(flag.to_owned(), value.to_owned());
343 }
344 here
345 }
346
347 /// Whether a gate body spells one [`DEFAULT_ON_TOOLS`] entry on / off.
348 fn default_on_state(gate: &str, spellings: &[&str], on: On) -> Option<bool> {
349 let here = settings_in(gate);
350 let mut state = None;
351 for spelling in spellings {
352 let Some(value) = here.get(*spelling) else {
353 continue;
354 };
355 let Ok(value) = value.parse::<u32>() else {
356 continue;
357 };
358 let is_on = match on {
359 On::NonZero => value != 0,
360 On::AtMost(limit) => value <= limit,
361 };
362 // Any spelling that says "on" wins: --tile-columns=0 --tile-rows=1
363 // is a multi-tile stream.
364 state = Some(state.unwrap_or(false) || is_on);
365 }
366 state
367 }
368
369 /// `--enable-*` settings per real-aomenc gate, derived from the gate
370 /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`.
371 fn tool_settings() -> (usize, BTreeMap<String, (usize, usize, usize)>) {
372 let gates = gate_bodies();
373
374 let mut per_tool: BTreeMap<String, (usize, usize, usize)> = BTreeMap::new();
375 let mut names: BTreeSet<String> = BTreeSet::new();
376 let mut seen: Vec<BTreeMap<String, char>> = Vec::new();
377 for gate in &gates {
378 let here = flags_in(gate);
379 names.extend(here.keys().cloned());
380 seen.push(here);
381 }
382 for name in names {
383 let off = seen.iter().filter(|g| g.get(&name) == Some(&'0')).count();
384 let on = seen.iter().filter(|g| g.get(&name) == Some(&'1')).count();
385 per_tool.insert(name, (off, on, gates.len() - off - on));
386 }
387 (gates.len(), per_tool)
388 }
389
390 #[test]
391 fn every_gate_disabling_a_tool_is_a_listed_coverage_hole() {
392 let (gate_count, per_tool) = tool_settings();
393 // A hole OPENS when every gate names the flag and every one of them
394 // says 0 -- then no real stream can exercise the tool.
395 let derived: BTreeSet<&str> = per_tool
396 .iter()
397 .filter(|&(_, &(off, on, defaulted))| off == gate_count && on == 0 && defaulted == 0)
398 .map(|(name, _)| name.as_str())
399 .collect();
400 // A hole CLOSES only on positive evidence: some gate passes `=1`.
401 // A gate that merely leaves the flag off its command line proves
402 // nothing -- aomenc's default for palette and intrabc is content-
403 // dependent -- so "defaulted" must not retire an entry, or a listing
404 // would disappear the moment an unrelated gate is added.
405 let exercised: BTreeSet<&str> = per_tool
406 .iter()
407 .filter(|&(_, &(_, on, _))| on > 0)
408 .map(|(name, _)| name.as_str())
409 .collect();
410 let listed: BTreeSet<&str> = NEVER_EXERCISED.iter().map(|&(flag, _)| flag).collect();
411
412 let unlisted: Vec<&&str> = derived.difference(&listed).collect();
413 assert!(
414 unlisted.is_empty(),
415 "these aomenc tools are switched off in all {gate_count} real-aomenc gates and on in \
416 none, so no real stream exercises them, and they are not listed in NEVER_EXERCISED: \
417 {unlisted:?} -- either enable the tool with `=1` in its own gate or add it to the \
418 list with a reason"
419 );
420 let stale: Vec<&&str> = listed.intersection(&exercised).collect();
421 assert!(
422 stale.is_empty(),
423 "NEVER_EXERCISED lists {stale:?}, but a gate now passes `=1` for them -- delete \
424 those entries, the coverage hole is closed"
425 );
426 }
427
428 /// The derivation is only meaningful if a flag left off a gate's command
429 /// line really does mean "aomenc's default", i.e. the parser above is
430 /// reading whole flags and not fragments.
431 #[test]
432 fn tool_settings_reads_whole_flags() {
433 let (gate_count, per_tool) = tool_settings();
434 assert!(
435 per_tool.contains_key("enable-cdef"),
436 "expected --enable-cdef among the gate flags"
437 );
438 for (name, &(off, on, defaulted)) in &per_tool {
439 assert!(
440 !name.is_empty() && !name.contains(['"', '=']),
441 "malformed flag {name:?}"
442 );
443 assert_eq!(
444 off + on + defaulted,
445 gate_count,
446 "{name} counts do not cover every gate"
447 );
448 }
449 }
450
451 /// A gate encodes at 10 bits when its recipe says so: the shared 10-bit
452 /// helper, an explicit `--bit-depth=10`/`--input-bit-depth=10`, or a
453 /// `yuv420p10le` fixture handed to aomenc. Everything else is aomenc's
454 /// 8-bit default.
455 /// lane-defon r1: a gate helper parameterised on `bit_depth` builds BOTH
456 /// an 8-bit and a 10-bit stream from one recipe, so its flags cover both
457 /// depths -- classifying it by the 10-bit strings inside its conditional
458 /// alone hid `--enable-tx-size-search=1` from the 8-bit list.
459 /// lane-reelckf r1: the same blind spot with the other spelling -- a gate
460 /// that loops `for depth in [8usize, 10]` builds BOTH streams from one
461 /// recipe, but its `yuv420p10le` arm made `is_ten_bit` classify it as
462 /// 10-bit only, hiding `--enable-cfl-intra=1` from the 8-bit list.
463 /// lane-av1-intrabc r1: the shared recipe helper
464 /// `screen_intrabc_stream_at_depth` is parameterised on `depth` and sits in
465 /// the segment that opens at the PRECEDING gate's `#[test]`, so without
466 /// this marker that gate's own 8-bit-only flags read as 10-bit-only -- the
467 /// lane-defon/reelckf blind spot with `depth` spelled instead of
468 /// `bit_depth`. Three gates share the helper, at both depths.
469 fn covers_both_depths(body: &str) -> bool {
470 body.contains("if bit_depth == 10")
471 || body.contains("if depth == 10")
472 || body.contains("for depth in [8usize, 10]")
473 }
474
475 /// Whether a gate body drives a stream at this depth.
476 fn covers_depth(body: &str, ten_bit: bool) -> bool {
477 covers_both_depths(body) || is_ten_bit(body) == ten_bit
478 }
479
480 fn is_ten_bit(body: &str) -> bool {
481 // The lists pin two buckets, 8-bit and high-bit-depth; 12-bit gates
482 // count in the high-depth bucket (lane-av1gwarp12's ROTZOOM gate was
483 // the first 12-bit gate to positively enable a listed tool, and the
484 // 10-bit-only spellings mis-filed it as 8-bit).
485 body.contains("encode_10bit_gradients")
486 || body.contains("ten_bit_tool_gate(")
487 || body.contains("--bit-depth=10")
488 || body.contains("--input-bit-depth=10")
489 || body.contains("yuv420p10le")
490 || body.contains("encode_12bit(")
491 || body.contains("--bit-depth=12")
492 || body.contains("--input-bit-depth=12")
493 || body.contains("yuv420p12le")
494 }
495
496 /// Flags a gate positively enables (`=1`), at gates of the given depth.
497 fn enabled_at(ten_bit: bool) -> BTreeSet<String> {
498 let mut on = BTreeSet::new();
499 for gate in gate_bodies() {
500 if !covers_depth(gate, ten_bit) {
501 continue;
502 }
503 for (flag, value) in flags_in(gate) {
504 if value == '1' {
505 on.insert(flag);
506 }
507 }
508 // A tool driven by its own spelling counts as exercised.
509 let here = settings_in(gate);
510 for (alias, tool) in ALIASES {
511 if here.get(*alias).is_some_and(|v| v != "0") {
512 on.insert((*tool).to_owned());
513 }
514 }
515 }
516 on
517 }
518
519 /// The tools of [`TOOL_UNIVERSE`] that no gate of this depth enables.
520 fn never_exercised_at(ten_bit: bool) -> BTreeSet<&'static str> {
521 let on = enabled_at(ten_bit);
522 TOOL_UNIVERSE
523 .iter()
524 .copied()
525 .filter(|t| !on.contains(*t))
526 .collect()
527 }
528
529 fn check_depth(ten_bit: bool, listed: &[(&str, &str)]) {
530 let derived = never_exercised_at(ten_bit);
531 let listed: BTreeSet<&str> = listed.iter().map(|&(flag, _)| flag).collect();
532 let depth = if ten_bit { "10-bit" } else { "8-bit" };
533 let unlisted: Vec<&&str> = derived.difference(&listed).collect();
534 assert!(
535 unlisted.is_empty(),
536 "no {depth} gate passes `=1` for {unlisted:?}, so no real {depth} stream exercises \
537 them -- enable the tool in a {depth} gate that asserts it fired, or list it"
538 );
539 let stale: Vec<&&str> = listed.difference(&derived).collect();
540 assert!(
541 stale.is_empty(),
542 "the {depth} list still names {stale:?}, but a {depth} gate now passes `=1` for them \
543 -- delete those entries, the coverage hole is closed"
544 );
545 }
546
547 #[test]
548 fn never_exercised_8bit_matches_the_gate_recipes() {
549 check_depth(false, NEVER_EXERCISED_8BIT);
550 }
551
552 #[test]
553 fn never_exercised_10bit_matches_the_gate_recipes() {
554 check_depth(true, NEVER_EXERCISED_10BIT);
555 }
556
557 /// `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` prints both
558 /// lists, so the per-depth holes can be read without opening this file.
559 #[test]
560 fn print_never_exercised_per_bit_depth() {
561 let ten: Vec<&str> = gate_bodies()
562 .into_iter()
563 .filter(|b| is_ten_bit(b))
564 .collect();
565 let total = gate_bodies().len();
566 println!(
567 "gate_coverage: {} real-aomenc gates, {} of them 10-bit",
568 total,
569 ten.len()
570 );
571 for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] {
572 let holes = never_exercised_at(ten_bit);
573 println!(
574 "NEVER_EXERCISED_{label} ({} of {}):",
575 holes.len(),
576 TOOL_UNIVERSE.len()
577 );
578 for flag in &holes {
579 println!(" --{flag}");
580 }
581 }
582 }
583
584 /// [`DEFAULT_ON_TOOLS`] per depth: `tool -> (off in N gates, on in N, defaulted in N)`.
585 fn default_on_settings(
586 ten_bit: bool,
587 ) -> (usize, BTreeMap<&'static str, (usize, usize, usize)>) {
588 let gates: Vec<&str> = gate_bodies()
589 .into_iter()
590 .filter(|b| covers_depth(b, ten_bit))
591 .collect();
592 let mut per_tool = BTreeMap::new();
593 for &(tool, spellings, _, on) in DEFAULT_ON_TOOLS {
594 let states: Vec<Option<bool>> = gates
595 .iter()
596 .map(|g| default_on_state(g, spellings, on))
597 .collect();
598 let turned_on = states.iter().filter(|s| **s == Some(true)).count();
599 let turned_off = states.iter().filter(|s| **s == Some(false)).count();
600 per_tool.insert(
601 tool,
602 (turned_off, turned_on, gates.len() - turned_off - turned_on),
603 );
604 }
605 (gates.len(), per_tool)
606 }
607
608 /// The [`DEFAULT_ON_TOOLS`] no gate of this depth positively enables.
609 fn never_on_at(ten_bit: bool) -> BTreeSet<&'static str> {
610 default_on_settings(ten_bit)
611 .1
612 .into_iter()
613 .filter(|&(_, (_, on, _))| on == 0)
614 .map(|(tool, _)| tool)
615 .collect()
616 }
617
618 fn check_default_on(ten_bit: bool, listed: &[(&str, &str)]) {
619 let derived = never_on_at(ten_bit);
620 let listed: BTreeSet<&str> = listed.iter().map(|&(tool, _)| tool).collect();
621 let depth = if ten_bit { "10-bit" } else { "8-bit" };
622 let unlisted: Vec<&&str> = derived.difference(&listed).collect();
623 assert!(
624 unlisted.is_empty(),
625 "no {depth} gate spells an on-value for {unlisted:?}, so no real {depth} stream is \
626 proven to carry them -- switch the tool on in a {depth} gate that asserts it fired, \
627 or list it with a reason"
628 );
629 let stale: Vec<&&str> = listed.difference(&derived).collect();
630 assert!(
631 stale.is_empty(),
632 "the {depth} default-on list still names {stale:?}, but a {depth} gate now switches \
633 them on -- delete those entries, the coverage hole is closed"
634 );
635 }
636
637 #[test]
638 fn never_on_8bit_matches_the_gate_recipes() {
639 check_default_on(false, NEVER_ON_8BIT);
640 }
641
642 #[test]
643 fn never_on_10bit_matches_the_gate_recipes() {
644 check_default_on(true, NEVER_ON_10BIT);
645 }
646
647 /// A tool must not be pinned twice: [`TOOL_UNIVERSE`] already derives the
648 /// `--enable-*` spellings under the `=1` rule.
649 #[test]
650 fn default_on_tools_do_not_duplicate_the_universe() {
651 for &(tool, spellings, _, _) in DEFAULT_ON_TOOLS {
652 assert!(
653 !TOOL_UNIVERSE.contains(&tool),
654 "{tool} is already covered by TOOL_UNIVERSE"
655 );
656 assert!(!spellings.is_empty(), "{tool} has no aomenc spelling");
657 }
658 for (alias, tool) in ALIASES {
659 assert!(
660 TOOL_UNIVERSE.contains(tool),
661 "alias --{alias} names {tool}, which is not a TOOL_UNIVERSE tool"
662 );
663 }
664 }
665
666 /// `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` prints the
667 /// default-on holes with their off/defaulted split.
668 #[test]
669 fn print_never_on_per_bit_depth() {
670 for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] {
671 let (gate_count, per_tool) = default_on_settings(ten_bit);
672 let holes = never_on_at(ten_bit);
673 println!(
674 "NEVER_ON_{label} ({} of {}, over {gate_count} {label} gates):",
675 holes.len(),
676 DEFAULT_ON_TOOLS.len()
677 );
678 for tool in &holes {
679 let (off, _, defaulted) = per_tool[tool];
680 let spellings = DEFAULT_ON_TOOLS
681 .iter()
682 .find(|e| e.0 == *tool)
683 .map(|e| e.1.join(","))
684 .unwrap_or_default();
685 println!(
686 " {tool} (--{spellings}): off in {off}, defaulted in {defaulted}, on in 0"
687 );
688 }
689 }
690 }
691}