wgpu_hal/validation_canary.rs
1use alloc::{string::String, vec::Vec};
2
3use parking_lot::Mutex;
4
5/// Stores the text of any validation errors that have occurred since
6/// the last call to `get_and_reset`.
7///
8/// Each value is a validation error and a message associated with it,
9/// or `None` if the error has no message from the api.
10///
11/// This is used for internal wgpu testing only and _must not_ be used
12/// as a way to check for errors.
13///
14/// This works as a static because `cargo nextest` runs all of our
15/// tests in separate processes, so each test gets its own canary.
16///
17/// This prevents the issue of one validation error terminating the
18/// entire process.
19pub static VALIDATION_CANARY: ValidationCanary = ValidationCanary {
20 inner: Mutex::new(Vec::new()),
21};
22
23/// Flag for internal testing.
24#[derive(Debug)]
25pub struct ValidationCanary {
26 inner: Mutex<Vec<String>>,
27}
28
29impl ValidationCanary {
30 #[allow(dead_code, reason = "in some configurations this function is dead")]
31 pub(crate) fn add(&self, msg: String) {
32 self.inner.lock().push(msg);
33 }
34
35 /// Returns any API validation errors that have occurred in this process
36 /// since the last call to this function.
37 pub fn get_and_reset(&self) -> Vec<String> {
38 self.inner.lock().drain(..).collect()
39 }
40}