From 07becfe5b5cc550b04ecbfa303cb6ccfc91357ad Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:59:41 +0200 Subject: [PATCH] [tests] don't create a new instance/adapter for `DEVICE_LIFETIME_CHECK` & `MULTIPLE_DEVICES` tests The test harness creates the instance and adapter that a test should use. Tests should not create these with default configurations or configs from the environment. --- tests/tests/device.rs | 62 ++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 0430f097fe..6edc73868c 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -36,32 +36,23 @@ static CROSS_DEVICE_BIND_GROUP_USAGE: GpuTestConfiguration = GpuTestConfiguratio #[gpu_test] static DEVICE_LIFETIME_CHECK: GpuTestConfiguration = GpuTestConfiguration::new() .parameters(TestParameters::default()) - .run_sync(|_| { - use pollster::FutureExt as _; - - let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - backends: wgpu::util::backend_bits_from_env().unwrap_or(wgpu::Backends::all()), - dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(), - gles_minor_version: wgpu::util::gles_minor_version_from_env().unwrap_or_default(), - flags: wgpu::InstanceFlags::advanced_debugging().with_env(), - }); - - let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, None) - .block_on() - .expect("failed to create adapter"); - - let (device, queue) = adapter - .request_device(&wgpu::DeviceDescriptor::default(), None) - .block_on() - .expect("failed to create device"); + .run_sync(|ctx| { + ctx.instance.poll_all(false); - instance.poll_all(false); + let pre_report = ctx.instance.generate_report().unwrap(); - let pre_report = instance.generate_report().unwrap(); + let TestingContext { + instance, + device, + queue, + .. + } = ctx; drop(queue); drop(device); + let post_report = instance.generate_report().unwrap(); + assert_ne!( pre_report, post_report, "Queue and Device has not been dropped as expected" @@ -72,29 +63,16 @@ static DEVICE_LIFETIME_CHECK: GpuTestConfiguration = GpuTestConfiguration::new() #[gpu_test] static MULTIPLE_DEVICES: GpuTestConfiguration = GpuTestConfiguration::new() .parameters(TestParameters::default()) - .run_sync(|_| { + .run_sync(|ctx| { use pollster::FutureExt as _; - - fn create_device_and_queue() -> (wgpu::Device, wgpu::Queue) { - let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - backends: wgpu::util::backend_bits_from_env().unwrap_or(wgpu::Backends::all()), - dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env() - .unwrap_or_default(), - gles_minor_version: wgpu::util::gles_minor_version_from_env().unwrap_or_default(), - flags: wgpu::InstanceFlags::advanced_debugging().with_env(), - }); - - let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, None) - .block_on() - .expect("failed to create adapter"); - - adapter - .request_device(&wgpu::DeviceDescriptor::default(), None) - .block_on() - .expect("failed to create device") - } - - let _ = vec![create_device_and_queue(), create_device_and_queue()]; + ctx.adapter + .request_device(&wgpu::DeviceDescriptor::default(), None) + .block_on() + .expect("failed to create device"); + ctx.adapter + .request_device(&wgpu::DeviceDescriptor::default(), None) + .block_on() + .expect("failed to create device"); }); #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]