diff --git a/crates/reims-vgpu/src/graphics/tests.rs b/crates/reims-vgpu/src/graphics/tests.rs index f117b567e..7237ca9c3 100644 --- a/crates/reims-vgpu/src/graphics/tests.rs +++ b/crates/reims-vgpu/src/graphics/tests.rs @@ -126,7 +126,9 @@ fn ask_displays(device: &GraphicsDevice

) { /// go of nothing, and returns, never in a deadlock. Once the lock goes, the callback returns, the /// device's threads end, and the next let-go lets go of the GPU device. Each runs on a thread of /// its own, whose answer the test waits for at most 30 s, so a let-go that never returned fails -/// the test at that wait +/// the test at that wait. Not under `rt`: there the platform keeps the process's one device until +/// the exit (`RtPlatform`'s device), so a let-go has nothing to wait for +#[cfg(not(feature = "rt"))] #[test] fn on_vulkan_the_let_go_waits_for_a_callback_blocked_on_the_releasers_lock_only_its_bound() { use std::sync::mpsc; @@ -172,6 +174,44 @@ fn on_vulkan_the_let_go_waits_for_a_callback_blocked_on_the_releasers_lock_only_ assert_eq!(let_go(Duration::from_secs(20)), Ok(Ok(true))); } +/// On the rt platform, which keeps the process's one device until the exit (`RtPlatform`'s +/// device), the let-go after the process's last graphics device lets go of nothing and answers +/// true at once, with no wait: here with a bound of nothing, while the ended device's callback is +/// still blocked on a lock the test holds +#[cfg(feature = "rt")] +#[test] +fn on_vulkan_rt_s_let_go_keeps_the_device_and_answers_true_at_once() { + use reims_vgpu_vulkan::RtPlatform; + use std::sync::mpsc; + let lock = Arc::new(Mutex::new(())); + let (entered, blocked) = mpsc::channel(); + let in_callback = Arc::clone(&lock); + let config = GraphicsConfig { + callbacks: GraphicsCallbacks { + raise_interrupt: Some(Arc::new(move |_| { + let _ = entered.send(()); + drop(in_callback.lock()); + })), + ..GraphicsCallbacks::default() + }, + window: None, + memory_map: None, + guest_arch: GuestArch::X86_64, + doorbell_pages: false, + ..GraphicsConfig::default() + }; + let device = GraphicsDevice::with_platform(crate::singleton::rt_platform(), config).unwrap(); + let held = lock.lock(); + ask_displays(&device); + blocked.recv_timeout(Duration::from_secs(10)).unwrap(); + drop(device); + assert_eq!( + GraphicsDevice::::let_go_of_gpu(Duration::ZERO), + Ok(true) + ); + drop(held); +} + /// The host screen's rate in thousandths of a hertz, rounded; 60 Hz for a rate that is none #[test] fn a_screen_s_rate_is_kept_in_millihertz() {