forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBb07f07aTahinli3 months ago1061 commits

gate_coverage.rs109 lines, 5.3 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 exercises: switched off in
22/// every gate that names them, on in none, defaulted in none.
23///
24/// Each entry is `(flag, why)`. Removing an entry is how a lane records that
25/// its tool is now covered by a real stream.
26#[cfg(test)]
27const NEVER_EXERCISED: &[(&str, &str)] = &[
28 ("enable-intrabc", "intra block copy syntax is consumed but no block is reconstructed from it"),
29];
30
31#[cfg(test)]
32mod tests {
33 use super::NEVER_EXERCISED;
34 use std::collections::{BTreeMap, BTreeSet};
35
36 /// `--enable-*` settings per real-aomenc gate, derived from the gate
37 /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`.
38 fn tool_settings() -> (usize, BTreeMap<String, (usize, usize, usize)>) {
39 let src = include_str!("stream.rs");
40 // A real-aomenc gate is a `fn` body carrying the shared `--passes=1`
41 // every one of them passes. Split on the attribute that opens a test.
42 let gates: Vec<&str> = src
43 .split("\n #[")
44 .filter(|body| body.contains("\"--passes=1\""))
45 .collect();
46 assert!(gates.len() >= 20, "expected the real-aomenc gates, found {}", gates.len());
47
48 let mut per_tool: BTreeMap<String, (usize, usize, usize)> = BTreeMap::new();
49 let mut names: BTreeSet<String> = BTreeSet::new();
50 let mut seen: Vec<BTreeMap<String, char>> = Vec::new();
51 for gate in &gates {
52 let mut here = BTreeMap::new();
53 for (i, _) in gate.match_indices("\"--enable-") {
54 let rest = &gate[i + 3..];
55 let Some(end) = rest.find('"') else { continue };
56 let Some((flag, value)) = rest[..end].split_once('=') else { continue };
57 let Some(value) = value.chars().next() else { continue };
58 names.insert(flag.to_owned());
59 here.insert(flag.to_owned(), value);
60 }
61 seen.push(here);
62 }
63 for name in names {
64 let off = seen.iter().filter(|g| g.get(&name) == Some(&'0')).count();
65 let on = seen.iter().filter(|g| g.get(&name) == Some(&'1')).count();
66 per_tool.insert(name, (off, on, gates.len() - off - on));
67 }
68 (gates.len(), per_tool)
69 }
70
71 #[test]
72 fn every_gate_disabling_a_tool_is_a_listed_coverage_hole() {
73 let (gate_count, per_tool) = tool_settings();
74 let derived: BTreeSet<&str> = per_tool
75 .iter()
76 .filter(|&(_, &(off, on, defaulted))| off == gate_count && on == 0 && defaulted == 0)
77 .map(|(name, _)| name.as_str())
78 .collect();
79 let listed: BTreeSet<&str> = NEVER_EXERCISED.iter().map(|&(flag, _)| flag).collect();
80
81 let unlisted: Vec<&&str> = derived.difference(&listed).collect();
82 assert!(
83 unlisted.is_empty(),
84 "these aomenc tools are switched off in all {gate_count} real-aomenc gates and on in \
85 none, so no real stream exercises them, and they are not listed in NEVER_EXERCISED: \
86 {unlisted:?} -- either enable the tool in its own gate or add it to the list with a \
87 reason"
88 );
89 let stale: Vec<&&str> = listed.difference(&derived).collect();
90 assert!(
91 stale.is_empty(),
92 "NEVER_EXERCISED lists {stale:?}, but a gate now enables or defaults them -- delete \
93 those entries, the coverage hole is closed"
94 );
95 }
96
97 /// The derivation is only meaningful if a flag left off a gate's command
98 /// line really does mean "aomenc's default", i.e. the parser above is
99 /// reading whole flags and not fragments.
100 #[test]
101 fn tool_settings_reads_whole_flags() {
102 let (gate_count, per_tool) = tool_settings();
103 assert!(per_tool.contains_key("enable-cdef"), "expected --enable-cdef among the gate flags");
104 for (name, &(off, on, defaulted)) in &per_tool {
105 assert!(!name.is_empty() && !name.contains(['"', '=']), "malformed flag {name:?}");
106 assert_eq!(off + on + defaulted, gate_count, "{name} counts do not cover every gate");
107 }
108 }
109}