Skip to content

Commit d9e803d

Browse files
committed
Add a test for the noop backend.
1 parent f34a469 commit d9e803d

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

tests/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ name = "wgpu-compile-test"
2222
path = "compile_tests/root.rs"
2323
harness = true
2424

25+
[[test]]
26+
name = "wgpu-validation-test"
27+
path = "validation_tests/root.rs"
28+
harness = true
29+
2530
[features]
2631
webgl = ["wgpu/webgl"]
2732

2833
[dependencies]
29-
wgpu.workspace = true
34+
wgpu = { workspace = true, features = ["noop"] }
3035
wgpu-macros.workspace = true
3136

3237
anyhow.workspace = true

tests/validation_tests/noop.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! Tests of [`wgpu::Backend::Noop`].
2+
3+
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
4+
use std::sync::Arc;
5+
6+
#[test]
7+
fn device_and_buffers() {
8+
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
9+
backends: wgpu::Backends::NOOP,
10+
backend_options: wgpu::BackendOptions {
11+
noop: wgpu::NoopBackendOptions { enable: true },
12+
..Default::default()
13+
},
14+
..Default::default()
15+
});
16+
let adapter =
17+
pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions::default()))
18+
.expect("adapter");
19+
let (device, queue) =
20+
pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default(), None))
21+
.expect("device");
22+
23+
assert_eq!(adapter.get_info().backend, wgpu::Backend::Noop);
24+
25+
// Demonstrate that creating and *writing* to a buffer succeeds.
26+
// This also involves creation of a staging buffer.
27+
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
28+
label: Some("hello world"),
29+
size: 8,
30+
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::COPY_SRC,
31+
mapped_at_creation: false,
32+
});
33+
assert_eq!(buffer.size(), 8);
34+
queue.write_buffer(&buffer, 0, &[1, 2, 3, 4]);
35+
queue.write_buffer(&buffer, 4, &[5, 6, 7, 8]);
36+
37+
// Demonstrate that we can read back data from the buffer.
38+
// This also involves copy_buffer_to_buffer().
39+
let done: Arc<AtomicBool> = Arc::default();
40+
let done2 = done.clone();
41+
wgpu::util::DownloadBuffer::read_buffer(&device, &queue, &buffer.slice(..), move |result| {
42+
assert_eq!(*result.unwrap(), [1, 2, 3, 4, 5, 6, 7, 8],);
43+
done.store(true, Relaxed);
44+
});
45+
device.poll(wgpu::Maintain::Wait);
46+
assert!(done2.load(Relaxed));
47+
}

tests/validation_tests/root.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Tests of the [`wgpu`] library API that are not run against a particular GPU.
2+
3+
mod noop;

0 commit comments

Comments
 (0)