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 <[email protected]>
This commit is contained in:
FredApps committed 2026-11-18 15:57:34 +07:00
1 parent c06ae97029
commit e10c6ec6fe
3 files changed
+16 -6

No files matched your search

+6 -4
View File
@@ -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");
+7 -1
View File
@@ -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;
}
};
+3 -1
View File
@@ -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");
}