2023-10-19 16:06:42 +00:00
|
|
|
//! Test utilities for the wgpu repository.
|
2021-06-15 09:07:06 +00:00
|
|
|
|
2024-02-27 19:43:05 +00:00
|
|
|
#![allow(clippy::arc_with_non_send_sync)] // False positive on wasm
|
|
|
|
|
2023-10-19 16:06:42 +00:00
|
|
|
mod config;
|
2023-11-23 08:49:01 +00:00
|
|
|
mod expectations;
|
2021-06-20 02:55:57 +00:00
|
|
|
pub mod image;
|
2023-10-19 16:06:42 +00:00
|
|
|
mod init;
|
2022-12-15 00:09:04 +00:00
|
|
|
mod isolation;
|
2023-10-19 16:06:42 +00:00
|
|
|
pub mod native;
|
|
|
|
mod params;
|
2024-01-13 17:34:51 +00:00
|
|
|
mod poll;
|
2023-10-19 16:06:42 +00:00
|
|
|
mod report;
|
|
|
|
mod run;
|
2022-12-09 01:02:39 +00:00
|
|
|
|
2023-09-01 05:48:31 +00:00
|
|
|
#[cfg(target_arch = "wasm32")]
|
2023-10-19 16:06:42 +00:00
|
|
|
pub use init::initialize_html_canvas;
|
2022-12-09 01:02:39 +00:00
|
|
|
|
2023-10-19 16:06:42 +00:00
|
|
|
pub use self::image::ComparisonType;
|
|
|
|
pub use config::GpuTestConfiguration;
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub use ctor::ctor;
|
2023-11-23 08:49:01 +00:00
|
|
|
pub use expectations::{FailureApplicationReasons, FailureBehavior, FailureCase, FailureReason};
|
2023-10-19 16:06:42 +00:00
|
|
|
pub use init::{initialize_adapter, initialize_device, initialize_instance};
|
2023-11-23 08:49:01 +00:00
|
|
|
pub use params::TestParameters;
|
2023-10-19 16:06:42 +00:00
|
|
|
pub use run::{execute_test, TestingContext};
|
|
|
|
pub use wgpu_macros::gpu_test;
|
|
|
|
|
|
|
|
/// Run some code in an error scope and assert that validation fails.
|
2024-02-22 19:21:35 +00:00
|
|
|
pub fn fail<T>(
|
|
|
|
device: &wgpu::Device,
|
|
|
|
callback: impl FnOnce() -> T,
|
|
|
|
expected_msg_substring: Option<&'static str>,
|
|
|
|
) -> T {
|
2022-10-11 17:40:30 +00:00
|
|
|
device.push_error_scope(wgpu::ErrorFilter::Validation);
|
|
|
|
let result = callback();
|
2024-02-22 19:21:35 +00:00
|
|
|
let validation_error = pollster::block_on(device.pop_error_scope())
|
|
|
|
.expect("expected validation error in callback, but no validation error was emitted");
|
|
|
|
if let Some(expected_msg_substring) = expected_msg_substring {
|
|
|
|
let lowered_expected = expected_msg_substring.to_lowercase();
|
|
|
|
let lowered_actual = validation_error.to_string().to_lowercase();
|
|
|
|
assert!(
|
|
|
|
lowered_actual.contains(&lowered_expected),
|
|
|
|
concat!(
|
|
|
|
"expected validation error case-insensitively containing {:?}, ",
|
|
|
|
"but it was not present in actual error message:\n{:?}"
|
|
|
|
),
|
|
|
|
expected_msg_substring,
|
|
|
|
validation_error
|
|
|
|
);
|
|
|
|
}
|
2022-10-11 17:40:30 +00:00
|
|
|
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2023-10-19 16:06:42 +00:00
|
|
|
/// Run some code in an error scope and assert that validation succeeds.
|
2024-08-23 14:17:28 +00:00
|
|
|
#[track_caller]
|
2022-10-11 17:40:30 +00:00
|
|
|
pub fn valid<T>(device: &wgpu::Device, callback: impl FnOnce() -> T) -> T {
|
|
|
|
device.push_error_scope(wgpu::ErrorFilter::Validation);
|
|
|
|
let result = callback();
|
2024-08-23 14:17:28 +00:00
|
|
|
if let Some(error) = pollster::block_on(device.pop_error_scope()) {
|
|
|
|
panic!(
|
|
|
|
"`valid` block at {} encountered wgpu error:\n{error}",
|
|
|
|
std::panic::Location::caller()
|
|
|
|
);
|
|
|
|
}
|
2022-10-11 17:40:30 +00:00
|
|
|
|
|
|
|
result
|
|
|
|
}
|
2022-11-02 05:43:44 +00:00
|
|
|
|
2023-10-19 16:06:42 +00:00
|
|
|
/// Run some code in an error scope and assert that validation succeeds or fails depending on the
|
|
|
|
/// provided `should_fail` boolean.
|
2024-02-22 19:21:35 +00:00
|
|
|
pub fn fail_if<T>(
|
|
|
|
device: &wgpu::Device,
|
|
|
|
should_fail: bool,
|
|
|
|
callback: impl FnOnce() -> T,
|
|
|
|
expected_msg_substring: Option<&'static str>,
|
|
|
|
) -> T {
|
2022-11-02 05:43:44 +00:00
|
|
|
if should_fail {
|
2024-02-22 19:21:35 +00:00
|
|
|
fail(device, callback, expected_msg_substring)
|
2022-11-02 05:43:44 +00:00
|
|
|
} else {
|
|
|
|
valid(device, callback)
|
|
|
|
}
|
|
|
|
}
|
2023-10-19 16:06:42 +00:00
|
|
|
|
|
|
|
/// Adds the necissary main function for our gpu test harness.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! gpu_test_main {
|
|
|
|
() => {
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
fn main() -> $crate::native::MainResult {
|
|
|
|
$crate::native::main()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|