forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

library_fixture.rs161 lines, 7.4 KiBHistoryRawDownload
1//! Where a REAL-LIBRARY fixture is read from, and the one presence probe every
2//! gate that needs one routes through.
3//!
4//! The clips these gates read (`h264-1080p-23.976-8bit.mp4`,
5//! `h264-2160p-23.976-8bit.mp4`, `real-library-manifest.tsv`) are
6//! multi-megabyte encodes of a shared library, not pins: they cannot be
7//! committed under `crates/<crate>/fixtures/` the way the `.obu` pins are
8//! ([`crate_pin`](crate::stream)), so they live in the gitignored ROOT
9//! `fixtures/` — `.gitignore:2`. A linked worktree therefore never has that
10//! directory, and a gate that skips on its absence reports GREEN having
11//! asserted nothing: the class `lane-av1skipfix` closed for the pins, still open
12//! for the clips.
13//!
14//! TWO defects met here, both of which this module closes:
15//!
16//! 1. **Silent skip.** `h264_clip_frames` and each gate's own
17//! `if !clip.exists() { eprintln!("SKIP …"); return; }` skipped with no env
18//! escape, so `EC_AV1_REQUIRE_FFMPEG=1` — a batch run's way of saying "this
19//! gate must actually run" — did not make the ABSENT CLIP a failure. The
20//! `a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders`
21//! gate printed `SKIP the 1080p tile round trip: no fixture` and libtest
22//! reported `ok` on a tree with no root `fixtures/` at all.
23//!
24//! 2. **Two roots.** `scripts/verify-fixture-library.sh` validates
25//! `$EC_FIXTURES` (defaulting to `$ROOT/fixtures`) while these gates read
26//! `$ROOT/fixtures` unconditionally. Pointing the preflight at a library
27//! elsewhere reported `resolve 0 missing` and `GREEN` while the clip gates'
28//! root was absent — GREEN with an absent root, the exact false green this
29//! module exists to kill. So [`root`] honours `EC_FIXTURES` FIRST: the
30//! preflight and the gates now resolve the same tree, and when it is unset
31//! the preflight's default IS the gates' root, so its mode-(i) finding fires
32//! exactly when the clip gates will skip.
33//!
34//! The shape is the crate's existing convention, not a new one: the
35//! assert-under-require / print-one-line-otherwise probe is the same one
36//! `crates/ec-h264/tests/conformance.rs::require_fixtures` and the per-crate
37//! `require_fixture` helpers use, and the file's own presence check lives HERE,
38//! inside the probe that owns it — a bare `clip.exists()` at a call site is
39//! precisely what the anti-regression scan for the sibling (tool) class
40//! rejects.
41
42use std::path::{Path, PathBuf};
43
44/// The envs that turn an absent library clip into a hard failure.
45///
46/// * `EC_REQUIRE_FIXTURES` — the fleet-wide convention, the same one
47/// `scripts/verify-fixture-library.sh` and every per-crate `require_fixture`
48/// honour, and the one `EC_REQUIRE_FIXTURES=1` in the preflight's docs names.
49/// * `EC_AV1_REQUIRE_FFMPEG` / `EC_AV1_REQUIRE_AOMENC` — this crate's own
50/// requirement flags ([`have_ffmpeg`](crate::encode::tests::have_ffmpeg)).
51/// Every gate reachable through [`require`] also decodes its result through
52/// ffmpeg, so a batch that sets them has already said the gate must run; a
53/// missing clip must not be the softer failure.
54///
55/// All three are checked, not just one: a run that sets only the preflight's
56/// env, and a run that sets only this crate's, both get the failure.
57fn required() -> bool {
58 std::env::var_os("EC_REQUIRE_FIXTURES").is_some()
59 || std::env::var_os("EC_AV1_REQUIRE_FFMPEG").is_some()
60 || std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_some()
61}
62
63/// The fixture root the tests read, in precedence order:
64///
65/// 1. `EC_FIXTURES` — the same variable `scripts/verify-fixture-library.sh`
66/// resolves, so its verdict and these gates' bytes are the same tree. This
67/// is the half of the two-roots mismatch that the preflight cannot fix from
68/// its side.
69/// 2. `<crate>/../../fixtures` — the gitignored root `fixtures/`, the default
70/// the preflight uses when `EC_FIXTURES` is unset.
71pub fn root() -> PathBuf {
72 match std::env::var_os("EC_FIXTURES") {
73 Some(p) if !p.is_empty() => PathBuf::from(p),
74 _ => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures"),
75 }
76}
77
78/// `require` on a path relative to [`root`]:
79/// `require("video/h264-1080p-23.976-8bit.mp4", …)`. The literal is
80/// LIBRARY-RELATIVE, which is the row shape `scripts/gen-fixture-library.sh`
81/// reads back out of this file, so the preflight keeps resolving these paths.
82pub fn path(rel: &str) -> PathBuf {
83 root().join(rel)
84}
85
86/// The one presence probe for a library fixture. Returns the path when the file
87/// is there. When it is not:
88///
89/// * under [`required()`] — PANIC, naming the resolved path, so the gate is RED
90/// instead of green-with-nothing-checked;
91/// * otherwise — prints exactly ONE `SKIP` line naming the resolved path and the
92/// three ways out (link the library, point `EC_FIXTURES` at it, or set a
93/// require env), and returns `None`.
94///
95/// A caller that gets `None` must `return` WITHOUT printing a second line: the
96/// path and the escape hatch are already on the one line above, and a second
97/// "no fixture" line is the noise that hid this defect from a reading of the
98/// output.
99pub fn require(rel: &str, what: &str) -> Option<PathBuf> {
100 require_at(path(rel), what)
101}
102
103/// [`require`] for a path the caller resolved itself — an `EC_AV1_WALL_CLIP`
104/// override, which names a clip OUTSIDE any library root, so it must not be
105/// joined onto one.
106pub fn require_at(clip: PathBuf, what: &str) -> Option<PathBuf> {
107 if clip.is_file() {
108 return Some(clip);
109 }
110 assert!(
111 !required(),
112 "{what}: the library clip is absent at {} -- this gate would prove nothing. A linked \
113 worktree has no gitignored root `fixtures/`: run scripts/link-fixtures.sh, or point \
114 EC_FIXTURES at a library root, or set EC_REQUIRE_FIXTURES=1 / EC_AV1_REQUIRE_FFMPEG=1 \
115 only on a tree that really has the library.",
116 clip.display()
117 );
118 eprintln!(
119 "SKIP {what}: {} absent at {} -- this gate proved nothing; run \
120 scripts/link-fixtures.sh, point EC_FIXTURES at a library root, or set \
121 EC_REQUIRE_FIXTURES=1 / EC_AV1_REQUIRE_FFMPEG=1 to make this a failure.",
122 clip.file_name().unwrap_or_default().to_string_lossy(),
123 clip.display()
124 );
125 None
126}
127
128#[cfg(test)]
129mod tests {
130 use super::*;
131
132 /// The two-roots reconciliation, asserted on the RESOLVER rather than
133 /// described in prose: with `EC_FIXTURES` set, [`root`] is that directory and
134 /// NOT `<crate>/../../fixtures`. (The variable is process-constant in this
135 /// crate — nothing calls `set_var` — so the assertion holds for whatever the
136 /// batch exported; it is the precedence, not a particular value, that is
137 /// under test.)
138 #[test]
139 fn the_resolver_follows_ec_fixtures_over_the_gitignored_root() {
140 let root = super::root();
141 if let Some(p) = std::env::var_os("EC_FIXTURES")
142 && !p.is_empty()
143 {
144 assert_eq!(
145 root,
146 PathBuf::from(p),
147 "EC_FIXTURES must win over the default root"
148 );
149 } else {
150 assert!(
151 root.ends_with("../../fixtures"),
152 "the default root is the gitignored <crate>/../../fixtures, got {}",
153 root.display()
154 );
155 }
156 assert_eq!(
157 super::path("video/h264-1080p-23.976-8bit.mp4"),
158 root.join("video/h264-1080p-23.976-8bit.mp4")
159 );
160 }
161}