forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB66045bcTahinli3 months ago1500 commits

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