mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:42:27 +00:00
craft-ui: unit tests that render take turns with the wgpu renderer
Each egui_kittest wgpu renderer creates its own Vulkan instance and device. When one test uses its device while a test on another thread creates or destroys one, the Vulkan loader now and then crashes the test binary with SIGSEGV. The previous commit serialized the four rendering tests in tests/visual_regression.rs; the craft-ui unit test binary has the same pattern in two tests: combo::tests::the_button_and_menu_look_like_eguis and tabs::dialog::tests::selected_tab_erases_a_baseline_centered_on_its_bottom_edge. Both now take crate::gpu_test_lock() before building their harness and hold it until the harness is dropped. The comment on the lock in visual_regression.rs now names the loader race instead of concurrent rendering alone.
This commit is contained in:
1 parent
eb752a4209
commit
23b10d78fb
4 files changed
+16
-3
No files matched your search
@@ -170,6 +170,7 @@ fn scene(ui: &mut egui::Ui, ours: bool) {
|
||||
}
|
||||
|
||||
fn render(ours: bool, hover: Option<&str>, open: Option<&str>) -> image::RgbaImage {
|
||||
let _gpu = crate::gpu_test_lock();
|
||||
// Two of the combo boxes have no label: the scene compares looks, not names.
|
||||
let mut h = Harness::builder().with_size(egui::vec2(480.0, 700.0)).with_accessibility_check(false).build_ui(move |ui| scene(ui, ours));
|
||||
h.run();
|
||||
|
||||
@@ -27,3 +27,14 @@ pub mod text;
|
||||
pub mod theme;
|
||||
|
||||
pub use combo::ComboBox;
|
||||
|
||||
/// Lets one unit test at a time hold a wgpu renderer. Each renderer creates its own Vulkan instance
|
||||
/// and device. When one test uses its device while a test on another thread creates or destroys
|
||||
/// one, the Vulkan loader now and then crashes the test binary with SIGSEGV. Take the lock before
|
||||
/// building the harness (`let _gpu = crate::gpu_test_lock();`), so it is released after the harness
|
||||
/// is dropped. A test that failed while holding it does not block the others.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn gpu_test_lock() -> std::sync::MutexGuard<'static, ()> {
|
||||
static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
}
|
||||
@@ -123,6 +123,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn selected_tab_erases_a_baseline_centered_on_its_bottom_edge() {
|
||||
let _gpu = crate::gpu_test_lock();
|
||||
let mut h = egui_kittest::Harness::builder().with_size(Vec2::new(120.0, 80.0)).wgpu().build_ui(|ui| {
|
||||
ui.painter().rect_filled(ui.max_rect(), 0.0, Color32::WHITE);
|
||||
let rect = Rect::from_min_size(egui::pos2(10.0, 10.0), Vec2::new(100.0, 26.0));
|
||||
|
||||
@@ -29,9 +29,9 @@ struct Capture {
|
||||
meshes: Option<Vec<Mesh>>,
|
||||
}
|
||||
|
||||
/// Lets one test at a time hold a wgpu renderer. With Mesa's software Vulkan driver, a test
|
||||
/// binary that renders on two devices at once from parallel test threads now and then crashes
|
||||
/// with SIGSEGV.
|
||||
/// Lets one test at a time hold a wgpu renderer. Each renderer creates its own Vulkan instance and
|
||||
/// device. When one test uses its device while a test on another thread creates or destroys one,
|
||||
/// the Vulkan loader now and then crashes the test binary with SIGSEGV.
|
||||
static GPU_LOCK: Mutex<()> = Mutex::new(());
|
||||
|
||||
/// Take this before creating a renderer (`let _gpu = gpu_lock();`), so it is released after the
|
||||
|
||||
Reference in new issue
Block a user