forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBca4790fTahinli3 months ago1157 commits

gate_coverage.rs129 lines, 6.4 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 ("enable-intrabc", "intra block copy syntax is consumed but no block is reconstructed from it"),
37];
38
39#[cfg(test)]
40mod tests {
41 use super::NEVER_EXERCISED;
42 use std::collections::{BTreeMap, BTreeSet};
43
44 /// `--enable-*` settings per real-aomenc gate, derived from the gate
45 /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`.
46 fn tool_settings() -> (usize, BTreeMap<String, (usize, usize, usize)>) {
47 let src = include_str!("stream.rs");
48 // A real-aomenc gate is a `fn` body carrying the shared `--passes=1`
49 // every one of them passes. Split on the attribute that opens a test.
50 let gates: Vec<&str> = src
51 .split("\n #[")
52 .filter(|body| body.contains("\"--passes=1\""))
53 .collect();
54 assert!(gates.len() >= 20, "expected the real-aomenc gates, found {}", gates.len());
55
56 let mut per_tool: BTreeMap<String, (usize, usize, usize)> = BTreeMap::new();
57 let mut names: BTreeSet<String> = BTreeSet::new();
58 let mut seen: Vec<BTreeMap<String, char>> = Vec::new();
59 for gate in &gates {
60 let mut here = BTreeMap::new();
61 for (i, _) in gate.match_indices("\"--enable-") {
62 let rest = &gate[i + 3..];
63 let Some(end) = rest.find('"') else { continue };
64 let Some((flag, value)) = rest[..end].split_once('=') else { continue };
65 let Some(value) = value.chars().next() else { continue };
66 names.insert(flag.to_owned());
67 here.insert(flag.to_owned(), value);
68 }
69 seen.push(here);
70 }
71 for name in names {
72 let off = seen.iter().filter(|g| g.get(&name) == Some(&'0')).count();
73 let on = seen.iter().filter(|g| g.get(&name) == Some(&'1')).count();
74 per_tool.insert(name, (off, on, gates.len() - off - on));
75 }
76 (gates.len(), per_tool)
77 }
78
79 #[test]
80 fn every_gate_disabling_a_tool_is_a_listed_coverage_hole() {
81 let (gate_count, per_tool) = tool_settings();
82 // A hole OPENS when every gate names the flag and every one of them
83 // says 0 -- then no real stream can exercise the tool.
84 let derived: BTreeSet<&str> = per_tool
85 .iter()
86 .filter(|&(_, &(off, on, defaulted))| off == gate_count && on == 0 && defaulted == 0)
87 .map(|(name, _)| name.as_str())
88 .collect();
89 // A hole CLOSES only on positive evidence: some gate passes `=1`.
90 // A gate that merely leaves the flag off its command line proves
91 // nothing -- aomenc's default for palette and intrabc is content-
92 // dependent -- so "defaulted" must not retire an entry, or a listing
93 // would disappear the moment an unrelated gate is added.
94 let exercised: BTreeSet<&str> = per_tool
95 .iter()
96 .filter(|&(_, &(_, on, _))| on > 0)
97 .map(|(name, _)| name.as_str())
98 .collect();
99 let listed: BTreeSet<&str> = NEVER_EXERCISED.iter().map(|&(flag, _)| flag).collect();
100
101 let unlisted: Vec<&&str> = derived.difference(&listed).collect();
102 assert!(
103 unlisted.is_empty(),
104 "these aomenc tools are switched off in all {gate_count} real-aomenc gates and on in \
105 none, so no real stream exercises them, and they are not listed in NEVER_EXERCISED: \
106 {unlisted:?} -- either enable the tool with `=1` in its own gate or add it to the \
107 list with a reason"
108 );
109 let stale: Vec<&&str> = listed.intersection(&exercised).collect();
110 assert!(
111 stale.is_empty(),
112 "NEVER_EXERCISED lists {stale:?}, but a gate now passes `=1` for them -- delete \
113 those entries, the coverage hole is closed"
114 );
115 }
116
117 /// The derivation is only meaningful if a flag left off a gate's command
118 /// line really does mean "aomenc's default", i.e. the parser above is
119 /// reading whole flags and not fragments.
120 #[test]
121 fn tool_settings_reads_whole_flags() {
122 let (gate_count, per_tool) = tool_settings();
123 assert!(per_tool.contains_key("enable-cdef"), "expected --enable-cdef among the gate flags");
124 for (name, &(off, on, defaulted)) in &per_tool {
125 assert!(!name.is_empty() && !name.contains(['"', '=']), "malformed flag {name:?}");
126 assert_eq!(off + on + defaulted, gate_count, "{name} counts do not cover every gate");
127 }
128 }
129}