forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBcfa93c0Tahinli3 months ago1659 commits

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