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.
24pub struct ValidationCanary {
25 inner: Mutex<Vec<String>>,
26}
27
28impl ValidationCanary {
29 #[allow(dead_code)] // in some configurations this function is dead
30 pub(crate) fn add(&self, msg: String) {
31 self.inner.lock().push(msg);
32 }
33
34 /// Returns any API validation errors that have occurred in this process
35 /// since the last call to this function.
36 pub fn get_and_reset(&self) -> Vec<String> {
37 self.inner.lock().drain(..).collect()
38 }
39}