From e10c6ec6fe87e696dc76b2cd4f761745b1392000 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:57:34 +0700 Subject: [PATCH] test(gpu): wait for a timed-out request under the GPU lock, and skip when none timed out bounded_readback's test_gpu now waits for its own timed-out request before releasing GPU_LOCK, so the next GPU test doesn't start beside a request still inside the driver. init_timeout no longer reads the process-wide count. The renderer test skips if the driver answered before the zero timeout, instead of failing. Signed-off-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/automation/tests/it/gpu_backend.rs | 10 ++++++---- crates/gpu/tests/it/bounded_readback.rs | 8 +++++++- crates/gpu/tests/it/init_timeout.rs | 4 +++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/automation/tests/it/gpu_backend.rs b/crates/automation/tests/it/gpu_backend.rs index 43769e51e0..20b9e96181 100644 --- a/crates/automation/tests/it/gpu_backend.rs +++ b/crates/automation/tests/it/gpu_backend.rs @@ -293,10 +293,12 @@ mod tests { let mut gpu_renderer = GpuRenderer::with_options(options); let doc = make_test_doc(16, 16, SampleType::U8); let res = gpu_renderer.render_bands(&doc, doc.bounds(), 16, &photocraft_raster::Interrupt::NONE, &mut |_| Ok::<(), photocraft_io::IoError>(())); - assert!( - matches!(&res, Err(photocraft_io::RenderError::Unavailable(msg)) if msg.contains("timed out")), - "a zero timeout must time the request out: {res:?}" - ); + let Err(photocraft_io::RenderError::Unavailable(msg)) = &res else { panic!("a zero timeout must leave the renderer unavailable: {res:?}") }; + if !msg.contains("timed out") { + // The driver answered before the caller even waited: there is no timed-out request. + eprintln!("SKIPPED: the GPU request did not time out ({msg})"); + return; + } drop(gpu_renderer); assert!(NativeContext::wait_for_abandoned_requests(std::time::Duration::ZERO), "the drop returned with the request still inside the driver"); diff --git a/crates/gpu/tests/it/bounded_readback.rs b/crates/gpu/tests/it/bounded_readback.rs index 8b99c78054..6e604e8ab5 100644 --- a/crates/gpu/tests/it/bounded_readback.rs +++ b/crates/gpu/tests/it/bounded_readback.rs @@ -1,9 +1,11 @@ //! Tests for bounded, checked band readback across chunks, pages, and device failure modes. +use std::time::Duration; + use photocraft_color::{BlendMode, Color, ColorMode, SampleType}; use photocraft_doc::{Document, Effect, Layer, LayerContent}; use photocraft_geom::{Rect, Size}; -use photocraft_gpu::context::{NativeContext, NativeContextOptions}; +use photocraft_gpu::context::{GpuContextError, NativeContext, NativeContextOptions}; use photocraft_gpu::readback::{DEFAULT_MAX_STAGING_BYTES, ReadbackError, render_bands, render_to_vec}; use photocraft_gpu::{Compositor, DeviceHealth}; use photocraft_raster::Surface; @@ -19,6 +21,10 @@ fn test_gpu() -> Option<(NativeContext, Compositor, std::sync::MutexGuard<'stati Ok(c) => c, Err(e) => { eprintln!("skipping bounded readback test: {e}"); + // Under the lock, so the next GPU test does not start beside a request still in the driver. + if let GpuContextError::TimedOut { pending, .. } = &e { + pending.wait(Duration::from_secs(120)); + } return None; } }; diff --git a/crates/gpu/tests/it/init_timeout.rs b/crates/gpu/tests/it/init_timeout.rs index 13f93df8d7..594df1a3bc 100644 --- a/crates/gpu/tests/it/init_timeout.rs +++ b/crates/gpu/tests/it/init_timeout.rs @@ -12,10 +12,12 @@ use crate::GPU_LOCK; #[test] fn a_timed_out_request_can_be_waited_for_before_exit() { let _gpu = GPU_LOCK.lock().unwrap_or_else(PoisonError::into_inner); + // `NativeContext::request` makes and drops an instance of its own; the kept one keeps the + // Vulkan loader from being torn down when it goes. + let _kept = crate::instance(); let opts = NativeContextOptions { timeout: Some(Duration::ZERO), ..Default::default() }; let res = NativeContext::request(&opts); let Err(GpuContextError::TimedOut { pending, .. }) = &res else { panic!("a zero timeout must give up before the adapter is ready: {res:?}") }; assert!(pending.wait(Duration::from_secs(120)), "the abandoned initialization thread never finished"); assert!(pending.is_finished()); - assert!(NativeContext::wait_for_abandoned_requests(Duration::ZERO), "a finished thread must not count as running"); }