forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBdfeffbcTahinli2 months ago3180 commits

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