forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB5a2f5efTahinli3 months ago1409 commits

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