Skip to content

Commit

Permalink
chore: [wgpu-tests] use concrete error messages for failures
Browse files Browse the repository at this point in the history
resolves #5727
  • Loading branch information
dv29 committed Jul 25, 2024
1 parent 205f1e3 commit d6d0502
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 53 deletions.
4 changes: 2 additions & 2 deletions tests/tests/bind_group_layout_dedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ fn separate_programs_have_incompatible_derived_bgls(ctx: TestingContext) {
|| {
drop(pass);
},
None,
Some("label at index 0 is not compatible with the corresponding bindgrouplayout"),
);
}

Expand Down Expand Up @@ -445,6 +445,6 @@ fn derived_bgls_incompatible_with_regular_bgls(ctx: TestingContext) {
|| {
drop(pass);
},
None,
Some("label at index 0 is not compatible with the corresponding bindgrouplayout"),
)
}
4 changes: 2 additions & 2 deletions tests/tests/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_LAYOUT: GpuTestConfiguration = GpuTestConfigu
cache: None,
});
},
None,
Some("shader global resourcebinding { group: 0, binding: 0 } is not available in the pipeline layout"),
);
});

Expand Down Expand Up @@ -335,7 +335,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_DISPATCH: GpuTestConfiguration = GpuTestConfi
drop(pass);
let _ = encoder.finish();
},
None,
Some("buffer is bound with size 16 where the shader expects 32 in group[0] compact index 0"),
);
});

Expand Down
59 changes: 45 additions & 14 deletions tests/tests/buffer_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,62 @@ fn try_copy(
ctx: &wgpu_test::TestingContext,
offset: BufferAddress,
size: BufferAddress,
should_fail: bool,
error_message: Option<&'static str>,
) {
let buffer = ctx.device.create_buffer(&BUFFER_DESCRIPTOR);
let data = vec![255; size as usize];

fail_if(
&ctx.device,
should_fail,
!matches!(error_message, Option::None),
|| ctx.queue.write_buffer(&buffer, offset, &data),
None,
error_message,
);
}

#[gpu_test]
static COPY_ALIGNMENT: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|ctx| {
try_copy(&ctx, 0, 0, false);
try_copy(&ctx, 4, 16 + 1, true);
try_copy(&ctx, 64, 20 + 2, true);
try_copy(&ctx, 256, 44 + 3, true);
try_copy(&ctx, 1024, 8 + 4, false);

try_copy(&ctx, 0, 4, false);
try_copy(&ctx, 4 + 1, 8, true);
try_copy(&ctx, 64 + 2, 12, true);
try_copy(&ctx, 256 + 3, 16, true);
try_copy(&ctx, 1024 + 4, 4, false);
try_copy(&ctx, 0, 0, Option::None);
try_copy(
&ctx,
4,
16 + 1,
Some("copy size 17 does not respect `copy_buffer_alignment`"),
);
try_copy(
&ctx,
64,
20 + 2,
Some("copy size 22 does not respect `copy_buffer_alignment`"),
);
try_copy(
&ctx,
256,
44 + 3,
Some("copy size 47 does not respect `copy_buffer_alignment`"),
);
try_copy(&ctx, 1024, 8 + 4, None);

try_copy(&ctx, 0, 4, Option::None);
try_copy(
&ctx,
4 + 1,
8,
Some("buffer offset 5 is not aligned to block size or `copy_buffer_alignment`"),
);
try_copy(
&ctx,
64 + 2,
12,
Some("buffer offset 66 is not aligned to block size or `copy_buffer_alignment`"),
);
try_copy(
&ctx,
256 + 3,
16,
Some("buffer offset 259 is not aligned to block size or `copy_buffer_alignment`"),
);
try_copy(&ctx, 1024 + 4, 4, None);
});

const BUFFER_SIZE: BufferAddress = 1234;
Expand Down
40 changes: 20 additions & 20 deletions tests/tests/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
ctx.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
},
None,
Some("device with '' label is invalid"),
);

// Creating a buffer should fail.
Expand All @@ -310,7 +310,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
mapped_at_creation: false,
});
},
None,
Some("device with '' label is invalid"),
);

// Creating a texture should fail.
Expand All @@ -332,7 +332,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
view_formats: &[],
});
},
None,
Some("device with '' label is invalid"),
);

// Texture clear should fail.
Expand All @@ -350,7 +350,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
},
);
},
None,
Some("device with '' label is invalid"),
);

// Creating a compute pass should fail.
Expand All @@ -362,7 +362,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
timestamp_writes: None,
});
},
None,
Some("device with '' label is invalid"),
);

// Creating a render pass should fail.
Expand All @@ -381,7 +381,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
occlusion_query_set: None,
});
},
None,
Some("device with '' label is invalid"),
);

// Copying a buffer to a buffer should fail.
Expand All @@ -396,7 +396,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
256,
);
},
None,
Some("device with '' label is invalid"),
);

// Copying a buffer to a texture should fail.
Expand All @@ -416,7 +416,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
texture_extent,
);
},
None,
Some("device with '' label is invalid"),
);

// Copying a texture to a buffer should fail.
Expand All @@ -436,7 +436,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
texture_extent,
);
},
None,
Some("device with '' label is invalid"),
);

// Copying a texture to a texture should fail.
Expand All @@ -449,7 +449,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
texture_extent,
);
},
None,
Some("device with '' label is invalid"),
);

// Creating a bind group layout should fail.
Expand All @@ -462,7 +462,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
entries: &[],
});
},
None,
Some("device with '' label is invalid"),
);

// Creating a bind group should fail.
Expand All @@ -480,7 +480,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
}],
});
},
None,
Some("device with '' label is invalid"),
);

// Creating a pipeline layout should fail.
Expand All @@ -494,7 +494,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
push_constant_ranges: &[],
});
},
None,
Some("device with '' label is invalid"),
);

// Creating a shader module should fail.
Expand All @@ -507,7 +507,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed("")),
});
},
None,
Some("device with '' label is invalid"),
);

// Creating a shader module spirv should fail.
Expand All @@ -520,7 +520,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
source: std::borrow::Cow::Borrowed(&[]),
});
},
None,
Some("device with '' label is invalid"),
);

// Creating a render pipeline should fail.
Expand All @@ -545,7 +545,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
cache: None,
});
},
None,
Some("device with '' label is invalid"),
);

// Creating a compute pipeline should fail.
Expand All @@ -562,7 +562,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
cache: None,
});
},
None,
Some("device with '' label is invalid"),
);

// Creating a compute pipeline should fail.
Expand All @@ -579,7 +579,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
cache: None,
});
},
None,
Some("device with '' label is invalid"),
);

// Buffer map should fail.
Expand All @@ -590,7 +590,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
.slice(..)
.map_async(wgpu::MapMode::Write, |_| ());
},
None,
Some("device with '' label is invalid"),
);

// Buffer unmap should fail.
Expand All @@ -599,7 +599,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
|| {
buffer_for_unmap.unmap();
},
None,
Some("device with '' label is invalid"),
);
});

Expand Down
2 changes: 1 addition & 1 deletion tests/tests/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static DROP_ENCODER_AFTER_ERROR: GpuTestConfiguration = GpuTestConfiguration::ne
renderpass.set_viewport(0.0, 0.0, -1.0, -1.0, 0.0, 1.0);
drop(renderpass);
},
None,
Some("viewport has invalid rect"),
);

// This is the actual interesting error condition. We've created
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/float32_filterable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static FLOAT32_FILTERABLE_WITHOUT_FEATURE: GpuTestConfiguration = GpuTestConfigu
|| {
create_texture_binding(device, wgpu::TextureFormat::R32Float, true);
},
None,
Some("texture binding 0 expects sample type = float { filterable: true }, but given a view with format = r32float"),
);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/life_cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use wgpu_test::{fail, gpu_test, GpuTestConfiguration};
static BUFFER_DESTROY: GpuTestConfiguration =
GpuTestConfiguration::new().run_async(|ctx| async move {
let buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
label: None,
label: Some("buffer"),
size: 256,
usage: wgpu::BufferUsages::MAP_WRITE | wgpu::BufferUsages::COPY_SRC,
mapped_at_creation: false,
Expand All @@ -25,7 +25,7 @@ static BUFFER_DESTROY: GpuTestConfiguration =
.slice(..)
.map_async(wgpu::MapMode::Write, move |_| {});
},
None,
Some("buffer with 'buffer' label has been destroyed"),
);

buffer.destroy();
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/nv12_texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static NV12_TEXTURE_VIEW_PLANE_ON_NON_PLANAR_FORMAT: GpuTestConfiguration =
..Default::default()
});
},
None,
Some("aspect plane0 is not in the source texture format r8unorm"),
);
});

Expand Down Expand Up @@ -181,7 +181,7 @@ static NV12_TEXTURE_VIEW_PLANE_OUT_OF_BOUNDS: GpuTestConfiguration = GpuTestConf
..Default::default()
});
},
None,
Some("aspect plane2 is not in the source texture format nv12"),
);
});

Expand Down Expand Up @@ -213,7 +213,7 @@ static NV12_TEXTURE_BAD_FORMAT_VIEW_PLANE: GpuTestConfiguration = GpuTestConfigu
..Default::default()
});
},
None,
Some("unable to view texture nv12 as rg8unorm"),
);
});

Expand Down Expand Up @@ -241,6 +241,6 @@ static NV12_TEXTURE_BAD_SIZE: GpuTestConfiguration = GpuTestConfiguration::new()
view_formats: &[],
});
},
None,
Some("width 255 is not a multiple of nv12's width multiple requirement"),
);
});
2 changes: 1 addition & 1 deletion tests/tests/queue_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ static QUEUE_WRITE_TEXTURE_OVERFLOW: GpuTestConfiguration =
},
);
},
None,
Some("end up overrunning the bounds of the destination texture"),
);
});
Loading

0 comments on commit d6d0502

Please sign in to comment.