test(wasapi): keep only native cleanup regressions
Preserve the original import layout and remove synthetic stream fixtures covered by the native lifecycle regressions.
This commit is contained in:
parent
a9fae8fac6
commit
f967589db3
2 changed files with 7 additions and 98 deletions
|
|
@ -4,16 +4,12 @@ use crate::{
|
||||||
BackendSpecificError, Data, InputCallbackInfo, OutputCallbackInfo, PauseStreamError,
|
BackendSpecificError, Data, InputCallbackInfo, OutputCallbackInfo, PauseStreamError,
|
||||||
PlayStreamError, SampleFormat, StreamError,
|
PlayStreamError, SampleFormat, StreamError,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::mem;
|
||||||
mem,
|
use std::os::windows::io::{AsRawHandle, FromRawHandle, OwnedHandle};
|
||||||
os::windows::io::{AsRawHandle, FromRawHandle, OwnedHandle},
|
use std::ptr;
|
||||||
ptr,
|
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||||
sync::{
|
use std::sync::Arc;
|
||||||
mpsc::{channel, Receiver, Sender},
|
use std::thread::{self, JoinHandle};
|
||||||
Arc,
|
|
||||||
},
|
|
||||||
thread::{self, JoinHandle},
|
|
||||||
};
|
|
||||||
use windows::Win32::Foundation;
|
use windows::Win32::Foundation;
|
||||||
use windows::Win32::Foundation::WAIT_OBJECT_0;
|
use windows::Win32::Foundation::WAIT_OBJECT_0;
|
||||||
use windows::Win32::Media::Audio;
|
use windows::Win32::Media::Audio;
|
||||||
|
|
|
||||||
|
|
@ -1,93 +1,6 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::traits::{DeviceTrait, HostTrait};
|
use crate::traits::{DeviceTrait, HostTrait};
|
||||||
use std::{
|
use std::time::{Duration, Instant};
|
||||||
ffi::CString,
|
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
|
||||||
|
|
||||||
const WORKER_DEADLINE: Duration = Duration::from_secs(2);
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
enum WorkerExit {
|
|
||||||
Termination,
|
|
||||||
Finished,
|
|
||||||
Panicked,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stream(exit: WorkerExit) -> (Stream, CString) {
|
|
||||||
let name = CString::new(format!(
|
|
||||||
"Local\\cpal-lifecycle-{}-{exit:?}",
|
|
||||||
std::process::id()
|
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
let event = unsafe {
|
|
||||||
Threading::CreateEventA(None, false, false, windows::core::PCSTR(name.as_ptr() as _))
|
|
||||||
}
|
|
||||||
.unwrap();
|
|
||||||
let (tx, rx) = channel();
|
|
||||||
let wait_for_exit = !matches!(exit, WorkerExit::Termination);
|
|
||||||
let worker = thread::spawn(move || match exit {
|
|
||||||
WorkerExit::Termination => assert!(matches!(rx.recv().unwrap(), Command::Terminate)),
|
|
||||||
WorkerExit::Finished => drop(rx),
|
|
||||||
WorkerExit::Panicked => {
|
|
||||||
drop(rx);
|
|
||||||
panic!("Injected worker failure");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if wait_for_exit {
|
|
||||||
let deadline = Instant::now() + WORKER_DEADLINE;
|
|
||||||
while !worker.is_finished() {
|
|
||||||
assert!(Instant::now() < deadline, "Worker failed to exit");
|
|
||||||
thread::yield_now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let owned_event = unsafe { OwnedHandle::from_raw_handle(event.0 as _) };
|
|
||||||
(
|
|
||||||
Stream {
|
|
||||||
thread: Some(worker),
|
|
||||||
commands: tx,
|
|
||||||
pending_scheduled_event: Arc::new(owned_event),
|
|
||||||
},
|
|
||||||
name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn assert_event_closed(exit: WorkerExit) {
|
|
||||||
let (stream, name) = stream(exit);
|
|
||||||
drop(stream);
|
|
||||||
// Another test can reuse a closed handle value; check the event's identity instead.
|
|
||||||
match unsafe {
|
|
||||||
Threading::OpenEventA(
|
|
||||||
Threading::EVENT_MODIFY_STATE,
|
|
||||||
false,
|
|
||||||
windows::core::PCSTR(name.as_ptr() as _),
|
|
||||||
)
|
|
||||||
} {
|
|
||||||
Ok(event) => {
|
|
||||||
let _event = unsafe { OwnedHandle::from_raw_handle(event.0 as _) };
|
|
||||||
panic!("Stream destruction leaked its command event");
|
|
||||||
}
|
|
||||||
Err(error) => assert_eq!(
|
|
||||||
error.code(),
|
|
||||||
windows::core::HRESULT::from_win32(Foundation::ERROR_FILE_NOT_FOUND.0),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn normal_shutdown_closes_command_event() {
|
|
||||||
assert_event_closed(WorkerExit::Termination);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completed_worker_still_closes_command_event() {
|
|
||||||
assert_event_closed(WorkerExit::Finished);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn panicked_worker_does_not_panic_in_drop_or_leak_event() {
|
|
||||||
assert_event_closed(WorkerExit::Panicked);
|
|
||||||
}
|
|
||||||
|
|
||||||
const WARMUP_CYCLES: usize = 4;
|
const WARMUP_CYCLES: usize = 4;
|
||||||
const MEASURED_CYCLES: usize = 16;
|
const MEASURED_CYCLES: usize = 16;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue