forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB231663eTahinli3 months ago1475 commits

gate_coverage.rs643 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 // 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 (
230 "enable-flip-idtx",
231 "hole at both depths, see the 8-bit list",
232 ),
233 ("enable-intrabc", "hole at both depths, see the 8-bit list"),
234 ("enable-rect-tx", "hole at both depths, see the 8-bit list"),
235 (
236 "enable-ref-frame-mvs",
237 "hole at both depths, see the 8-bit list",
238 ),
239 ("enable-tx64", "hole at both depths, see the 8-bit list"),
240];
241
242/// [`DEFAULT_ON_TOOLS`] entries no 8-bit gate spells on, with the reason.
243///
244/// Each entry is `(tool, why)`; the reason states whether the tool is pinned
245/// OFF in every gate that names it (a hard hole -- no stream can carry it) or
246/// merely defaulted (unknown, and unknown is not coverage).
247#[cfg(test)]
248const NEVER_ON_8BIT: &[(&str, &str)] = &[];
249
250/// [`DEFAULT_ON_TOOLS`] entries no 10-bit gate spells on, with the reason.
251#[cfg(test)]
252const NEVER_ON_10BIT: &[(&str, &str)] = &[];
253
254#[cfg(test)]
255mod tests {
256 use super::{
257 ALIASES, DEFAULT_ON_TOOLS, NEVER_EXERCISED, NEVER_EXERCISED_8BIT, NEVER_EXERCISED_10BIT,
258 NEVER_ON_10BIT, NEVER_ON_8BIT, On, TOOL_UNIVERSE,
259 };
260 use std::collections::{BTreeMap, BTreeSet};
261
262 /// Bodies of the real-aomenc gates: a `fn` body carrying the shared
263 /// `--passes=1` every one of them passes. Split on the attribute that
264 /// opens a test.
265 fn gate_bodies() -> Vec<&'static str> {
266 let src = include_str!("stream.rs");
267 let gates: Vec<&str> = src
268 .split("\n #[")
269 // lane-hbdgates r1: an `#[ignore]`d gate exercises nothing, so it
270 // must not close a hole. Its body is the segment that opens with
271 // the ignore attribute.
272 .filter(|body| !body.starts_with("ignore"))
273 // lane-hbdgates r1: gates that build their stream through the
274 // shared 10-bit helpers spell `--passes=1` there, not inline.
275 .filter(|body| {
276 body.contains("\"--passes=1\"")
277 || body.contains("ten_bit_tool_gate(")
278 || body.contains("encode_10bit_gradients")
279 })
280 .collect();
281 assert!(
282 gates.len() >= 20,
283 "expected the real-aomenc gates, found {}",
284 gates.len()
285 );
286 gates
287 }
288
289 /// `--enable-<flag>=<value>` settings spelled inside one gate body.
290 fn flags_in(gate: &str) -> BTreeMap<String, char> {
291 let mut here = BTreeMap::new();
292 for (i, _) in gate.match_indices("\"--enable-") {
293 let rest = &gate[i + 3..];
294 let Some(end) = rest.find('"') else { continue };
295 let Some((flag, value)) = rest[..end].split_once('=') else {
296 continue;
297 };
298 let Some(value) = value.chars().next() else {
299 continue;
300 };
301 here.insert(flag.to_owned(), value);
302 }
303 here
304 }
305
306 /// Every `--flag=value` spelled inside one gate body, values kept whole
307 /// (`--cpu-used=4`, `--tile-columns=2`), not just their first character.
308 fn settings_in(gate: &str) -> BTreeMap<String, String> {
309 let mut here = BTreeMap::new();
310 for (i, _) in gate.match_indices("\"--") {
311 let rest = &gate[i + 3..];
312 let Some(end) = rest.find('"') else { continue };
313 let Some((flag, value)) = rest[..end].split_once('=') else {
314 continue;
315 };
316 here.insert(flag.to_owned(), value.to_owned());
317 }
318 here
319 }
320
321 /// Whether a gate body spells one [`DEFAULT_ON_TOOLS`] entry on / off.
322 fn default_on_state(gate: &str, spellings: &[&str], on: On) -> Option<bool> {
323 let here = settings_in(gate);
324 let mut state = None;
325 for spelling in spellings {
326 let Some(value) = here.get(*spelling) else {
327 continue;
328 };
329 let Ok(value) = value.parse::<u32>() else {
330 continue;
331 };
332 let is_on = match on {
333 On::NonZero => value != 0,
334 On::AtMost(limit) => value <= limit,
335 };
336 // Any spelling that says "on" wins: --tile-columns=0 --tile-rows=1
337 // is a multi-tile stream.
338 state = Some(state.unwrap_or(false) || is_on);
339 }
340 state
341 }
342
343 /// `--enable-*` settings per real-aomenc gate, derived from the gate
344 /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`.
345 fn tool_settings() -> (usize, BTreeMap<String, (usize, usize, usize)>) {
346 let gates = gate_bodies();
347
348 let mut per_tool: BTreeMap<String, (usize, usize, usize)> = BTreeMap::new();
349 let mut names: BTreeSet<String> = BTreeSet::new();
350 let mut seen: Vec<BTreeMap<String, char>> = Vec::new();
351 for gate in &gates {
352 let here = flags_in(gate);
353 names.extend(here.keys().cloned());
354 seen.push(here);
355 }
356 for name in names {
357 let off = seen.iter().filter(|g| g.get(&name) == Some(&'0')).count();
358 let on = seen.iter().filter(|g| g.get(&name) == Some(&'1')).count();
359 per_tool.insert(name, (off, on, gates.len() - off - on));
360 }
361 (gates.len(), per_tool)
362 }
363
364 #[test]
365 fn every_gate_disabling_a_tool_is_a_listed_coverage_hole() {
366 let (gate_count, per_tool) = tool_settings();
367 // A hole OPENS when every gate names the flag and every one of them
368 // says 0 -- then no real stream can exercise the tool.
369 let derived: BTreeSet<&str> = per_tool
370 .iter()
371 .filter(|&(_, &(off, on, defaulted))| off == gate_count && on == 0 && defaulted == 0)
372 .map(|(name, _)| name.as_str())
373 .collect();
374 // A hole CLOSES only on positive evidence: some gate passes `=1`.
375 // A gate that merely leaves the flag off its command line proves
376 // nothing -- aomenc's default for palette and intrabc is content-
377 // dependent -- so "defaulted" must not retire an entry, or a listing
378 // would disappear the moment an unrelated gate is added.
379 let exercised: BTreeSet<&str> = per_tool
380 .iter()
381 .filter(|&(_, &(_, on, _))| on > 0)
382 .map(|(name, _)| name.as_str())
383 .collect();
384 let listed: BTreeSet<&str> = NEVER_EXERCISED.iter().map(|&(flag, _)| flag).collect();
385
386 let unlisted: Vec<&&str> = derived.difference(&listed).collect();
387 assert!(
388 unlisted.is_empty(),
389 "these aomenc tools are switched off in all {gate_count} real-aomenc gates and on in \
390 none, so no real stream exercises them, and they are not listed in NEVER_EXERCISED: \
391 {unlisted:?} -- either enable the tool with `=1` in its own gate or add it to the \
392 list with a reason"
393 );
394 let stale: Vec<&&str> = listed.intersection(&exercised).collect();
395 assert!(
396 stale.is_empty(),
397 "NEVER_EXERCISED lists {stale:?}, but a gate now passes `=1` for them -- delete \
398 those entries, the coverage hole is closed"
399 );
400 }
401
402 /// The derivation is only meaningful if a flag left off a gate's command
403 /// line really does mean "aomenc's default", i.e. the parser above is
404 /// reading whole flags and not fragments.
405 #[test]
406 fn tool_settings_reads_whole_flags() {
407 let (gate_count, per_tool) = tool_settings();
408 assert!(
409 per_tool.contains_key("enable-cdef"),
410 "expected --enable-cdef among the gate flags"
411 );
412 for (name, &(off, on, defaulted)) in &per_tool {
413 assert!(
414 !name.is_empty() && !name.contains(['"', '=']),
415 "malformed flag {name:?}"
416 );
417 assert_eq!(
418 off + on + defaulted,
419 gate_count,
420 "{name} counts do not cover every gate"
421 );
422 }
423 }
424
425 /// A gate encodes at 10 bits when its recipe says so: the shared 10-bit
426 /// helper, an explicit `--bit-depth=10`/`--input-bit-depth=10`, or a
427 /// `yuv420p10le` fixture handed to aomenc. Everything else is aomenc's
428 /// 8-bit default.
429 /// lane-defon r1: a gate helper parameterised on `bit_depth` builds BOTH
430 /// an 8-bit and a 10-bit stream from one recipe, so its flags cover both
431 /// depths -- classifying it by the 10-bit strings inside its conditional
432 /// alone hid `--enable-tx-size-search=1` from the 8-bit list.
433 fn covers_both_depths(body: &str) -> bool {
434 body.contains("if bit_depth == 10")
435 }
436
437 /// Whether a gate body drives a stream at this depth.
438 fn covers_depth(body: &str, ten_bit: bool) -> bool {
439 covers_both_depths(body) || is_ten_bit(body) == ten_bit
440 }
441
442 fn is_ten_bit(body: &str) -> bool {
443 body.contains("encode_10bit_gradients")
444 || body.contains("ten_bit_tool_gate(")
445 || body.contains("--bit-depth=10")
446 || body.contains("--input-bit-depth=10")
447 || body.contains("yuv420p10le")
448 }
449
450 /// Flags a gate positively enables (`=1`), at gates of the given depth.
451 fn enabled_at(ten_bit: bool) -> BTreeSet<String> {
452 let mut on = BTreeSet::new();
453 for gate in gate_bodies() {
454 if !covers_depth(gate, ten_bit) {
455 continue;
456 }
457 for (flag, value) in flags_in(gate) {
458 if value == '1' {
459 on.insert(flag);
460 }
461 }
462 // A tool driven by its own spelling counts as exercised.
463 let here = settings_in(gate);
464 for (alias, tool) in ALIASES {
465 if here.get(*alias).is_some_and(|v| v != "0") {
466 on.insert((*tool).to_owned());
467 }
468 }
469 }
470 on
471 }
472
473 /// The tools of [`TOOL_UNIVERSE`] that no gate of this depth enables.
474 fn never_exercised_at(ten_bit: bool) -> BTreeSet<&'static str> {
475 let on = enabled_at(ten_bit);
476 TOOL_UNIVERSE
477 .iter()
478 .copied()
479 .filter(|t| !on.contains(*t))
480 .collect()
481 }
482
483 fn check_depth(ten_bit: bool, listed: &[(&str, &str)]) {
484 let derived = never_exercised_at(ten_bit);
485 let listed: BTreeSet<&str> = listed.iter().map(|&(flag, _)| flag).collect();
486 let depth = if ten_bit { "10-bit" } else { "8-bit" };
487 let unlisted: Vec<&&str> = derived.difference(&listed).collect();
488 assert!(
489 unlisted.is_empty(),
490 "no {depth} gate passes `=1` for {unlisted:?}, so no real {depth} stream exercises \
491 them -- enable the tool in a {depth} gate that asserts it fired, or list it"
492 );
493 let stale: Vec<&&str> = listed.difference(&derived).collect();
494 assert!(
495 stale.is_empty(),
496 "the {depth} list still names {stale:?}, but a {depth} gate now passes `=1` for them \
497 -- delete those entries, the coverage hole is closed"
498 );
499 }
500
501 #[test]
502 fn never_exercised_8bit_matches_the_gate_recipes() {
503 check_depth(false, NEVER_EXERCISED_8BIT);
504 }
505
506 #[test]
507 fn never_exercised_10bit_matches_the_gate_recipes() {
508 check_depth(true, NEVER_EXERCISED_10BIT);
509 }
510
511 /// `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` prints both
512 /// lists, so the per-depth holes can be read without opening this file.
513 #[test]
514 fn print_never_exercised_per_bit_depth() {
515 let ten: Vec<&str> = gate_bodies()
516 .into_iter()
517 .filter(|b| is_ten_bit(b))
518 .collect();
519 let total = gate_bodies().len();
520 println!(
521 "gate_coverage: {} real-aomenc gates, {} of them 10-bit",
522 total,
523 ten.len()
524 );
525 for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] {
526 let holes = never_exercised_at(ten_bit);
527 println!(
528 "NEVER_EXERCISED_{label} ({} of {}):",
529 holes.len(),
530 TOOL_UNIVERSE.len()
531 );
532 for flag in &holes {
533 println!(" --{flag}");
534 }
535 }
536 }
537
538 /// [`DEFAULT_ON_TOOLS`] per depth: `tool -> (off in N gates, on in N, defaulted in N)`.
539 fn default_on_settings(ten_bit: bool) -> (usize, BTreeMap<&'static str, (usize, usize, usize)>) {
540 let gates: Vec<&str> = gate_bodies()
541 .into_iter()
542 .filter(|b| covers_depth(b, ten_bit))
543 .collect();
544 let mut per_tool = BTreeMap::new();
545 for &(tool, spellings, _, on) in DEFAULT_ON_TOOLS {
546 let states: Vec<Option<bool>> = gates
547 .iter()
548 .map(|g| default_on_state(g, spellings, on))
549 .collect();
550 let turned_on = states.iter().filter(|s| **s == Some(true)).count();
551 let turned_off = states.iter().filter(|s| **s == Some(false)).count();
552 per_tool.insert(
553 tool,
554 (turned_off, turned_on, gates.len() - turned_off - turned_on),
555 );
556 }
557 (gates.len(), per_tool)
558 }
559
560 /// The [`DEFAULT_ON_TOOLS`] no gate of this depth positively enables.
561 fn never_on_at(ten_bit: bool) -> BTreeSet<&'static str> {
562 default_on_settings(ten_bit)
563 .1
564 .into_iter()
565 .filter(|&(_, (_, on, _))| on == 0)
566 .map(|(tool, _)| tool)
567 .collect()
568 }
569
570 fn check_default_on(ten_bit: bool, listed: &[(&str, &str)]) {
571 let derived = never_on_at(ten_bit);
572 let listed: BTreeSet<&str> = listed.iter().map(|&(tool, _)| tool).collect();
573 let depth = if ten_bit { "10-bit" } else { "8-bit" };
574 let unlisted: Vec<&&str> = derived.difference(&listed).collect();
575 assert!(
576 unlisted.is_empty(),
577 "no {depth} gate spells an on-value for {unlisted:?}, so no real {depth} stream is \
578 proven to carry them -- switch the tool on in a {depth} gate that asserts it fired, \
579 or list it with a reason"
580 );
581 let stale: Vec<&&str> = listed.difference(&derived).collect();
582 assert!(
583 stale.is_empty(),
584 "the {depth} default-on list still names {stale:?}, but a {depth} gate now switches \
585 them on -- delete those entries, the coverage hole is closed"
586 );
587 }
588
589 #[test]
590 fn never_on_8bit_matches_the_gate_recipes() {
591 check_default_on(false, NEVER_ON_8BIT);
592 }
593
594 #[test]
595 fn never_on_10bit_matches_the_gate_recipes() {
596 check_default_on(true, NEVER_ON_10BIT);
597 }
598
599 /// A tool must not be pinned twice: [`TOOL_UNIVERSE`] already derives the
600 /// `--enable-*` spellings under the `=1` rule.
601 #[test]
602 fn default_on_tools_do_not_duplicate_the_universe() {
603 for &(tool, spellings, _, _) in DEFAULT_ON_TOOLS {
604 assert!(
605 !TOOL_UNIVERSE.contains(&tool),
606 "{tool} is already covered by TOOL_UNIVERSE"
607 );
608 assert!(!spellings.is_empty(), "{tool} has no aomenc spelling");
609 }
610 for (alias, tool) in ALIASES {
611 assert!(
612 TOOL_UNIVERSE.contains(tool),
613 "alias --{alias} names {tool}, which is not a TOOL_UNIVERSE tool"
614 );
615 }
616 }
617
618 /// `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` prints the
619 /// default-on holes with their off/defaulted split.
620 #[test]
621 fn print_never_on_per_bit_depth() {
622 for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] {
623 let (gate_count, per_tool) = default_on_settings(ten_bit);
624 let holes = never_on_at(ten_bit);
625 println!(
626 "NEVER_ON_{label} ({} of {}, over {gate_count} {label} gates):",
627 holes.len(),
628 DEFAULT_ON_TOOLS.len()
629 );
630 for tool in &holes {
631 let (off, _, defaulted) = per_tool[tool];
632 let spellings = DEFAULT_ON_TOOLS
633 .iter()
634 .find(|e| e.0 == *tool)
635 .map(|e| e.1.join(","))
636 .unwrap_or_default();
637 println!(
638 " {tool} (--{spellings}): off in {off}, defaulted in {defaulted}, on in 0"
639 );
640 }
641 }
642 }
643}