From 0003db18c4e97bcf9635e1e827f38155e6b6b4eb Mon Sep 17 00:00:00 2001 From: vero Date: Sat, 27 Jan 2024 17:42:02 -0800 Subject: [PATCH] Refactor tests to be feature flag bit-width agnostic (#5155) --- CHANGELOG.md | 3 ++- player/tests/data/bind-group.ron | 2 +- player/tests/data/buffer-copy.ron | 2 +- player/tests/data/clear-buffer-texture.ron | 2 +- .../tests/data/pipeline-statistics-query.ron | 2 +- player/tests/data/quad.ron | 2 +- player/tests/data/zero-init-buffer.ron | 2 +- .../tests/data/zero-init-texture-binding.ron | 4 +-- .../data/zero-init-texture-copytobuffer.ron | 2 +- .../data/zero-init-texture-rendertarget.ron | 2 +- player/tests/test.rs | 26 +++++++++++++++++-- 11 files changed, 36 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53a43857b..8abab11a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ Bottom level categories: #### Tests - Fix intermittent crashes on Linux in the `multithreaded_compute` test. By @jimblandy in [#5129](https://github.com/gfx-rs/wgpu/pull/5129). +- Refactor tests to read feature flags by name instead of a hardcoded hexadecimal u64. By @rodolphito in [#5155](https://github.com/gfx-rs/wgpu/pull/5155). ## v0.19.0 (2024-01-17) @@ -193,7 +194,7 @@ let surface = instance.create_surface(my_window.clone())?; ``` All platform specific surface creation using points have moved into `SurfaceTargetUnsafe` as well. -For example: +For example: Safety by @daxpedda in [#4597](https://github.com/gfx-rs/wgpu/pull/4597) Unification by @wumpf in [#4984](https://github.com/gfx-rs/wgpu/pull/4984) diff --git a/player/tests/data/bind-group.ron b/player/tests/data/bind-group.ron index 7b89d456b..eacc36eb6 100644 --- a/player/tests/data/bind-group.ron +++ b/player/tests/data/bind-group.ron @@ -1,5 +1,5 @@ ( - features: 0x0, + features: [], expectations: [], //not crash! actions: [ CreateBuffer(Id(0, 1, Empty), ( diff --git a/player/tests/data/buffer-copy.ron b/player/tests/data/buffer-copy.ron index 05c3a9433..5c66f2c01 100644 --- a/player/tests/data/buffer-copy.ron +++ b/player/tests/data/buffer-copy.ron @@ -1,5 +1,5 @@ ( - features: 0x0000_0004_0000_0000, // MAPPABLE_PRIMARY_BUFFERS + features: ["MAPPABLE_PRIMARY_BUFFERS"], expectations: [ ( name: "basic", diff --git a/player/tests/data/clear-buffer-texture.ron b/player/tests/data/clear-buffer-texture.ron index 592e141c9..7b25fa42c 100644 --- a/player/tests/data/clear-buffer-texture.ron +++ b/player/tests/data/clear-buffer-texture.ron @@ -1,5 +1,5 @@ ( - features: 0x0004_0004_0000_0000, // MAPPABLE_PRIMARY_BUFFERS | CLEAR_TEXTURE + features: ["MAPPABLE_PRIMARY_BUFFERS", "CLEAR_TEXTURE"], expectations: [ ( name: "Quad", diff --git a/player/tests/data/pipeline-statistics-query.ron b/player/tests/data/pipeline-statistics-query.ron index 999c333a3..2565ee737 100644 --- a/player/tests/data/pipeline-statistics-query.ron +++ b/player/tests/data/pipeline-statistics-query.ron @@ -1,5 +1,5 @@ ( - features: 0x0000_0005_0000_0000, // MAPPABLE_PRIMARY_BUFFERS | PIPELINE_STATISTICS_QUERY + features: ["MAPPABLE_PRIMARY_BUFFERS", "PIPELINE_STATISTICS_QUERY"], expectations: [ ( name: "Queried number of compute invocations is correct", diff --git a/player/tests/data/quad.ron b/player/tests/data/quad.ron index 563ba24b8..68bf8ee97 100644 --- a/player/tests/data/quad.ron +++ b/player/tests/data/quad.ron @@ -1,5 +1,5 @@ ( - features: 0x0, + features: [], expectations: [ ( name: "Quad", diff --git a/player/tests/data/zero-init-buffer.ron b/player/tests/data/zero-init-buffer.ron index b93f65c73..73692d10e 100644 --- a/player/tests/data/zero-init-buffer.ron +++ b/player/tests/data/zero-init-buffer.ron @@ -1,5 +1,5 @@ ( - features: 0x0000_0004_0000_0000, // MAPPABLE_PRIMARY_BUFFERS + features: ["MAPPABLE_PRIMARY_BUFFERS"], expectations: [ // Ensuring that mapping zero-inits buffers. ( diff --git a/player/tests/data/zero-init-texture-binding.ron b/player/tests/data/zero-init-texture-binding.ron index 17aa3b427..7dcfa4e2e 100644 --- a/player/tests/data/zero-init-texture-binding.ron +++ b/player/tests/data/zero-init-texture-binding.ron @@ -1,5 +1,5 @@ ( - features: 0x0, + features: [], expectations: [ ( name: "Sampled Texture", @@ -56,7 +56,7 @@ format: "rgba8unorm", usage: 9, // STORAGE + COPY_SRC view_formats: [], - )), + )), CreateTextureView( id: Id(1, 1, Empty), parent_id: Id(1, 1, Empty), diff --git a/player/tests/data/zero-init-texture-copytobuffer.ron b/player/tests/data/zero-init-texture-copytobuffer.ron index 0bb16cceb..599ddbd67 100644 --- a/player/tests/data/zero-init-texture-copytobuffer.ron +++ b/player/tests/data/zero-init-texture-copytobuffer.ron @@ -1,5 +1,5 @@ ( - features: 0x0, + features: [], expectations: [ ( name: "Copy to Buffer", diff --git a/player/tests/data/zero-init-texture-rendertarget.ron b/player/tests/data/zero-init-texture-rendertarget.ron index 831af942a..ec844fe07 100644 --- a/player/tests/data/zero-init-texture-rendertarget.ron +++ b/player/tests/data/zero-init-texture-rendertarget.ron @@ -1,5 +1,5 @@ ( - features: 0x0, + features: [], expectations: [ ( name: "Render Target", diff --git a/player/tests/test.rs b/player/tests/test.rs index 196777d0b..cb09aeceb 100644 --- a/player/tests/test.rs +++ b/player/tests/test.rs @@ -49,7 +49,6 @@ struct Expectation { data: ExpectedData, } -#[derive(serde::Deserialize)] struct Test<'a> { features: wgt::Features, expectations: Vec, @@ -72,7 +71,30 @@ impl Test<'_> { _ => unreachable!(), }; let string = read_to_string(path).unwrap().replace("Empty", backend_name); - ron::de::from_str(&string).unwrap() + + #[derive(serde::Deserialize)] + struct SerializedTest<'a> { + features: Vec, + expectations: Vec, + actions: Vec>, + } + let SerializedTest { + features, + expectations, + actions, + } = ron::de::from_str(&string).unwrap(); + let features = features + .iter() + .map(|feature| { + wgt::Features::from_name(feature) + .unwrap_or_else(|| panic!("Invalid feature flag {}", feature)) + }) + .fold(wgt::Features::empty(), |a, b| a | b); + Test { + features, + expectations, + actions, + } } fn run(