Skip to content

Commit

Permalink
[tests] don't create a new instance/adapter for `DEVICE_LIFETIME_CHEC…
Browse files Browse the repository at this point in the history
…K` & `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.
  • Loading branch information
teoxoy committed Sep 3, 2024
1 parent 595ae7c commit 07becfe
Showing 1 changed file with 20 additions and 42 deletions.
62 changes: 20 additions & 42 deletions tests/tests/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"))))]
Expand Down

0 comments on commit 07becfe

Please sign in to comment.