Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

test(windows): make the capture self-test name the step that dies

tonhowtf083d010be46e
diff --git a/src-tauri/omnidisc-media/Cargo.toml b/src-tauri/omnidisc-media/Cargo.toml
index 989b182c..2f1b31ea 100644
--- a/src-tauri/omnidisc-media/Cargo.toml
+++ b/src-tauri/omnidisc-media/Cargo.toml
@@ -75,3 +75,10 @@ windows = { version = "0.61", features = [
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
tokio-tungstenite = { version = "0.30", features = ["native-tls"] }
futures-util = "0.3"
+
+# Plain main instead of libtest: a heap corruption kills the process and libtest
+# discards the buffered output of the test that died, so CI would only show an
+# exit code. See the file header.
+[[test]]
+name = "windows_capture"
+harness = false
diff --git a/src-tauri/omnidisc-media/tests/windows_capture.rs b/src-tauri/omnidisc-media/tests/windows_capture.rs
index 828ac171..f1fb2c15 100644
--- a/src-tauri/omnidisc-media/tests/windows_capture.rs
+++ b/src-tauri/omnidisc-media/tests/windows_capture.rs
@@ -6,20 +6,45 @@
//! written on. The Windows CI job already runs `cargo test --workspace`, so
//! these run there on every push.
//!
+//! `harness = false` on purpose: libtest buffers a test's output and throws it
+//! away if the process dies, which is exactly what a heap corruption does. With
+//! a plain `main` every checkpoint is already on the wire when the process
+//! aborts, so CI names the step that died instead of just the exit code. It
+//! also keeps the steps in one thread, so an apartment-threading bug in the COM
+//! code is not mistaken for a memory bug.
+//!
//! A CI runner is a virtual desktop with no audio endpoint, so the assertions
//! are about behaviour that must hold anywhere: enumeration answers, a capture
//! either starts or fails with a typed error, and nothing panics or hangs.
-#![cfg(windows)]
-use omnidisc_media::capture::{self, CaptureOptions, VideoTick};
-use omnidisc_media::stream::{AudioMode, SourceId};
-use std::sync::atomic::{AtomicU32, Ordering};
-use std::sync::Arc;
-use std::time::{Duration, Instant};
+#[cfg(not(windows))]
+fn main() {}
+
+#[cfg(windows)]
+fn main() {
+ use omnidisc_media::capture::{self, CaptureOptions, VideoTick};
+ use omnidisc_media::stream::{AudioMode, SourceId};
+ use std::sync::atomic::{AtomicU32, Ordering};
+ use std::sync::Arc;
+ use std::time::{Duration, Instant};
+
+ macro_rules! step {
+ ($($arg:tt)*) => {{
+ println!("[windows-capture] {}", format!($($arg)*));
+ std::io::Write::flush(&mut std::io::stdout()).ok();
+ }};
+ }
-#[test]
-fn enumeration_answers_and_reports_what_the_build_supports() {
+ step!("enumerating without thumbnails");
let sources = capture::list_sources(false).expect("list_sources must answer on Windows");
+ step!(
+ "displays={} windows={} apps={} app_audio={} system_audio={}",
+ sources.displays.len(),
+ sources.windows.len(),
+ sources.apps.len(),
+ sources.app_audio_supported,
+ sources.system_audio_supported
+ );
assert!(
!sources.displays.is_empty(),
"a Windows session always has at least one display"
@@ -42,13 +67,13 @@ fn enumeration_answers_and_reports_what_the_build_supports() {
"a build new enough for per-app loopback also has the exclude-self mode"
);
}
-}
-#[test]
-fn thumbnails_do_not_break_enumeration() {
- let sources = capture::list_sources(true).expect("list_sources with thumbnails");
- for s in sources.displays.iter().chain(sources.windows.iter()) {
+ step!("enumerating with thumbnails");
+ let thumbed = capture::list_sources(true).expect("list_sources with thumbnails");
+ let mut thumbs = 0;
+ for s in thumbed.displays.iter().chain(thumbed.windows.iter()) {
if let Some(thumb) = &s.thumbnail {
+ thumbs += 1;
assert!(
thumb.starts_with("data:image/"),
"a thumbnail is a data URL the webview can render, got {:.32}",
@@ -56,11 +81,9 @@ fn thumbnails_do_not_break_enumeration() {
);
}
}
-}
+ step!("thumbnails produced: {thumbs}");
-#[test]
-fn capturing_a_display_delivers_ticks_or_a_typed_error() {
- let sources = capture::list_sources(false).expect("list_sources");
+ step!("starting display capture");
let display = sources
.displays
.first()
@@ -76,70 +99,82 @@ fn capturing_a_display_delivers_ticks_or_a_typed_error() {
f.fetch_add(1, Ordering::Relaxed);
}
});
-
let opts = CaptureOptions {
source: display,
fps: 30,
height: Some(720),
cursor: false,
};
- let started = match capture::start_video(&opts, sink) {
- Ok(started) => started,
+ match capture::start_video(&opts, sink) {
+ Ok((handle, geometry)) => {
+ step!(
+ "capture started {}x{}@{}",
+ geometry.width,
+ geometry.height,
+ geometry.fps
+ );
+ assert!(
+ geometry.width > 0 && geometry.height > 0,
+ "geometry must be real"
+ );
+ assert!(geometry.fps > 0);
+ let deadline = Instant::now() + Duration::from_secs(3);
+ while Instant::now() < deadline && ticks.load(Ordering::Relaxed) == 0 {
+ std::thread::sleep(Duration::from_millis(50));
+ }
+ step!(
+ "ticks={} frames={}",
+ ticks.load(Ordering::Relaxed),
+ frames.load(Ordering::Relaxed)
+ );
+ handle.stop();
+ step!("capture stopped");
+ // A still virtual desktop may produce no *frames*, but the idle ticks
+ // that keep the encoder emitting CFR must arrive regardless — their
+ // absence is what silently freezes a viewer's picture.
+ assert!(
+ ticks.load(Ordering::Relaxed) > 0,
+ "capture started but delivered neither a frame nor an idle tick in 3 s"
+ );
+ }
Err(e) => {
- // A headless or locked session is a legitimate refusal; a panic or a
- // hang is not, and neither is an error with nothing to act on.
+ // A headless or locked session is a legitimate refusal; a panic, a
+ // hang, or an error with nothing to act on is not.
+ step!("capture refused: {e}");
assert!(
!e.to_string().trim().is_empty(),
"a refusal must explain itself"
);
- return;
}
- };
- let (capture_handle, geometry) = started;
- assert!(
- geometry.width > 0 && geometry.height > 0,
- "geometry must be real"
- );
- assert!(geometry.fps > 0);
-
- let deadline = Instant::now() + Duration::from_secs(3);
- while Instant::now() < deadline && ticks.load(Ordering::Relaxed) == 0 {
- std::thread::sleep(Duration::from_millis(50));
}
- capture_handle.stop();
- // A still virtual desktop may produce no *frames*, but the idle ticks that
- // keep the encoder emitting CFR must arrive regardless — their absence is
- // the failure mode that silently freezes a viewer's picture.
- assert!(
- ticks.load(Ordering::Relaxed) > 0,
- "capture started but delivered neither a frame nor an idle tick in 3 s"
- );
-}
-
-#[test]
-fn audio_capture_starts_or_refuses_without_panicking() {
+ step!("starting system audio");
let sink: capture::AudioSink = Arc::new(|_samples: &[f32]| {});
match capture::start_audio(AudioMode::System, sink) {
Ok((handle, mode)) => {
+ step!("audio started as {mode:?}");
// The ladder may have degraded; whatever it reports has to be a mode
// the UI can name, never a claim of something it did not get.
assert!(matches!(mode, AudioMode::System | AudioMode::None));
std::thread::sleep(Duration::from_millis(300));
handle.stop();
+ step!("audio stopped");
}
Err(e) => {
- let msg = e.to_string();
- assert!(!msg.trim().is_empty(), "a refusal must explain itself");
+ step!("audio refused: {e}");
+ assert!(
+ !e.to_string().trim().is_empty(),
+ "a refusal must explain itself"
+ );
}
}
-}
-#[test]
-fn asking_for_no_audio_never_fails() {
+ step!("starting the no-audio path");
let sink: capture::AudioSink = Arc::new(|_samples: &[f32]| {});
let (handle, mode) = capture::start_audio(AudioMode::None, sink)
.expect("AudioMode::None is the path a share with no audio takes");
assert_eq!(mode, AudioMode::None);
handle.stop();
+
+ step!("all checks passed");
}