forge
Explore
Log in

Don't you dare go Hollow

The seat, the gap and the silent pin are witnessed where they can be

Browse files at this commit

9e8397d0d7592812376bc86b2f9dca25d64618a7Ahmet Kaan GümüşParent: b747d45
  • test
    • the seat, the gap and the silent pin are witnessed where they can be
Show full message
✅ test(engine): the seat, the gap and the silent pin are witnessed where they can be

Two witnesses and one determinism fix, from the refute-first pass on the
decode and wave lanes:

- the visualizer's declared canvas dims are masked to the even size the
  planes really have, so a one-pixel-high canvas and an odd one paint
  through the real seat instead of killing its worker. The witness drives
  `open_visualizer` at 1920x1 and 1921x1081; with the unmasked
  declaration put back it dies with the dead channel the probe saw. The
  export side already masks its own dims (`ClipDecoder::next`).
- a span whose codec has no seat at all reports `Backend::Gap`, not the
  hardware session that produced nothing: witnessed through `run_span`
  itself on a VP8 file under the `VE_SW` pin, since every public door
  refuses a plugin-only codec before a span exists.
- the audio device counter is no longer claimed absolutely in a parallel
  suite: the silent pin is asserted on the session the test owns, with
  the counter read as a delta under a module lock.

Also states the run_hw abort-path defect this box cannot reach (no
plugin): see the integration report.
crates/engine/src/ao.rsmodified+32 -1
@@ -227,6 +227,14 @@ impl AoSession {
227227 DEVICES_OPENED.load(Ordering::Relaxed)
228228 }
229229
230+ /// Whether this session is the silent sink rather than a real stream --
231+ /// what the `VE_NO_AO` pin buys, and the one form of that claim a caller can
232+ /// own: [`AoSession::devices_opened`] is process-wide and moves under any
233+ /// other session this process opens.
234+ pub fn is_silent(&self) -> bool {
235+ matches!(self.backend, Backend::Silent(_))
236+ }
237+
230238 /// Whether the plugin itself is loadable. Says nothing about the daemon --
231239 /// only [`AoSession::open`] answers that, and it is cheap enough to be the
232240 /// real probe.
@@ -354,12 +362,35 @@ unsafe impl Send for AoSession {}
354362 mod tests {
355363 use super::AoSession;
356364
365+ /// This module's counter assertions, one test at a time: the counters are
366+ /// process-wide, so two of these tests measuring at once would see each
367+ /// other's opens. Same shape as `waveform::counters_serial`, and for the
368+ /// same reason -- the counters stay readable, and one at a time is the
369+ /// whole point.
370+ fn counters_serial() -> std::sync::MutexGuard<'static, ()> {
371+ static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
372+ LOCK.lock().unwrap_or_else(|poisoned| poisoned.into_inner())
373+ }
374+
357375 #[test]
358376 fn a_silent_pin_never_opens_a_device() {
377+ let _serial = counters_serial();
359378 // SAFETY: this is the engine's own unit-test process.
360379 unsafe { std::env::set_var("VE_NO_AO", "1") };
380+ let before = AoSession::devices_opened();
361381 let mut ao = AoSession::open(48_000, 2).expect("silent opens");
362- assert_eq!(AoSession::devices_opened(), 0);
382+ // The pin's effect, on the session this test owns: no other test in
383+ // this binary can open one for it, and no absolute claim is made on a
384+ // counter *any* session in the process moves.
385+ assert!(
386+ ao.is_silent(),
387+ "the pin must route the open to the silent sink"
388+ );
389+ assert_eq!(
390+ AoSession::devices_opened(),
391+ before,
392+ "the silent open moved the process's device counter"
393+ );
363394 assert!(ao.set_volume(0.0));
364395 assert!(!ao.set_volume(1.5));
365396 assert!(ao.set_active(true));
crates/engine/src/decode.rsmodified+114 -0
@@ -2861,6 +2861,120 @@ mod tests {
28612861 assert!(frame.bgra.is_empty());
28622862 }
28632863
2864+ /// The same seat, at the two canvas sizes whose *declared* dims used to
2865+ /// disagree with the planes the painter handed back: one pixel high (the
2866+ /// planes floor to nothing) and odd (they floor to the even size below).
2867+ /// The worker declares the size it renders at -- masked and floored the way
2868+ /// the painter masks -- so the conversion below always has the chroma plane
2869+ /// it indexes, and a picture arrives at the canvas's own size.
2870+ #[test]
2871+ fn a_thin_and_an_odd_visualizer_canvas_paint_through_the_seat() {
2872+ for (w, h) in [(1920u32, 1u32), (1921, 1081)] {
2873+ let stream = DecodeSession::open_visualizer(
2874+ &asset("test_opus_51.mka"),
2875+ 0,
2876+ 0,
2877+ 2,
2878+ 30.0,
2879+ ColorParams::default(),
2880+ TransformParams::default(),
2881+ Composer::new(w, h, crate::scale::FitPolicy::Fit),
2882+ VIZ_STYLE_WAVE,
2883+ 0,
2884+ )
2885+ .unwrap_or_else(|e| panic!("open the visualizer at {w}x{h}: {e}"));
2886+ let frame = stream.frames.recv_timeout(Duration::from_secs(30)).unwrap_or_else(|e| {
2887+ panic!("a picture for a {w}x{h} canvas, not a worker that died instead: {e}")
2888+ });
2889+ assert_eq!(
2890+ (frame.width, frame.height),
2891+ (w, h),
2892+ "a {w}x{h} canvas is handed back at its own size"
2893+ );
2894+ assert_eq!(
2895+ frame.bgra.len(),
2896+ (w * h * 4) as usize,
2897+ "and converted across the whole canvas at {w}x{h}"
2898+ );
2899+ }
2900+ }
2901+
2902+ /// The `VE_SW=1` pin, borrowed for one test and put back as it was: it is
2903+ /// process-wide, and this file's unit tests share one process.
2904+ struct SwPin(Option<std::ffi::OsString>);
2905+
2906+ impl SwPin {
2907+ fn set() -> Self {
2908+ let had = std::env::var_os("VE_SW");
2909+ unsafe { std::env::set_var("VE_SW", "1") };
2910+ Self(had)
2911+ }
2912+ }
2913+
2914+ impl Drop for SwPin {
2915+ fn drop(&mut self) {
2916+ match &self.0 {
2917+ Some(was) => unsafe { std::env::set_var("VE_SW", was) },
2918+ None => unsafe { std::env::remove_var("VE_SW") },
2919+ }
2920+ }
2921+ }
2922+
2923+ /// A span whose codec has no seat at all -- the plugin never opened one and
2924+ /// there is no software decoder for these bytes -- must report the *gap* it
2925+ /// is. The cell used to be left claiming `Hardware`: the arm below the
2926+ /// software fallback set it before the session that produced nothing, and
2927+ /// the front-end then named a decoder that had decoded no frame.
2928+ ///
2929+ /// Driven through [`run_span`] itself, which is the only door that reaches
2930+ /// the arm: every public one refuses a plugin-only codec at `hw_decodes`
2931+ /// before a span exists (VP8, VP9 and HEVC all refuse on this machine), and
2932+ /// the arm is for the box where the plugin was there and then was not.
2933+ /// `VE_SW=1` is what makes that box-independent; see [`SwPin`].
2934+ #[test]
2935+ fn a_span_with_no_seat_at_all_reports_the_gap() {
2936+ let _pin = SwPin::set();
2937+ let path = asset("test_vp8.mp4");
2938+ let mut source = None;
2939+ let cancel = AtomicBool::new(false);
2940+ let generation = AtomicU64::new(0);
2941+ let floor = AtomicU32::new(0);
2942+ let abort = Abort {
2943+ cancel: &cancel,
2944+ generation: &generation,
2945+ mine: 0,
2946+ floor: &floor,
2947+ };
2948+ let (tx, rx) = sync_channel(2);
2949+ let cell = BackendCell::new(Backend::Opening);
2950+ run_span(
2951+ &path,
2952+ &mut source,
2953+ SpanCmd {
2954+ generation: 0,
2955+ start: 0,
2956+ end: 2,
2957+ color: ColorParams::default(),
2958+ transform: TransformParams::default(),
2959+ canvas: Composer::passthrough(),
2960+ tone: tonemap::Preset::default(),
2961+ speed: Speed::NORMAL,
2962+ tx,
2963+ },
2964+ &abort,
2965+ &cell,
2966+ );
2967+ assert_eq!(
2968+ cell.get(),
2969+ Backend::Gap,
2970+ "a VP8 span with no hardware must report the gap, not a hardware seat"
2971+ );
2972+ assert!(
2973+ rx.try_recv().is_err(),
2974+ "a gap decodes nothing: no picture may come down the channel"
2975+ );
2976+ }
2977+
28642978 #[test]
28652979 fn visualizer_default_is_a_blue_envelope() {
28662980 let mut peaks = vec![(0.0, 0.0); 12_000];