forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB8fd360cTahinli2 months ago2655 commits

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