pub(crate) fn in_subprocess(test_path: &str, body: impl FnOnce()) {
const CHILD: &str = "MEDIADECODE_FFMPEG_FAULT_CHILD";
if std::env::var(CHILD).as_deref() == Ok(test_path) {
body();
return;
}
let exe = std::env::current_exe().expect("the test binary's own path");
let output = std::process::Command::new(exe)
.args(["--exact", test_path, "--nocapture", "--test-threads=1"])
.env(CHILD, test_path)
.output()
.expect("spawning the child test process");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
assert_eq!(
output.status.code(),
Some(0),
"the child running `{test_path}` did not exit cleanly ({:?})\n--- stdout ---\n{stdout}\n--- stderr ---\n{stderr}",
output.status,
);
assert!(
stdout.contains("1 passed"),
"the child ran no test — is `{test_path}` still the name?\n--- stdout ---\n{stdout}",
);
}
pub(crate) fn cap_ffmpeg_allocations(max: usize) {
unsafe { ffmpeg_next::ffi::av_max_alloc(max) };
}
pub(crate) fn uncap_ffmpeg_allocations() {
cap_ffmpeg_allocations(i32::MAX as usize);
}