From a3ac9a7064f49c8e47cc0c3e8316fc9053ae6219 Mon Sep 17 00:00:00 2001 From: relrelb Date: Mon, 20 Jun 2022 21:10:40 +0300 Subject: [PATCH] tests: Have at most one image per test Previously image tests had an image per platform (i.e. Linux, Windows). However, due to containing the LLVM version in their name, which constantly updates on CI, and the fact that those images are actually identical, unify them into a single `expected.png` image. --- tests/tests/regression_tests.rs | 73 ++++++------------ ...-windows-Microsoft Basic Render Driver.png | Bin 1882 -> 0 bytes ...LVM 14.0.1, 256 bits).png => expected.png} | Bin 3 files changed, 22 insertions(+), 51 deletions(-) delete mode 100644 tests/tests/swfs/avm1/color/color-windows-Microsoft Basic Render Driver.png rename tests/tests/swfs/avm1/color/{color-linux-llvmpipe (LLVM 14.0.1, 256 bits).png => expected.png} (100%) diff --git a/tests/tests/regression_tests.rs b/tests/tests/regression_tests.rs index 031c2a8ed..f17befc16 100644 --- a/tests/tests/regression_tests.rs +++ b/tests/tests/regression_tests.rs @@ -20,15 +20,11 @@ use ruffle_render_wgpu::wgpu; use ruffle_render_wgpu::WgpuRenderBackend; use std::cell::RefCell; use std::collections::BTreeMap; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::rc::Rc; use std::sync::{Arc, Mutex}; use std::time::Duration; -fn get_img_platform_suffix(info: &wgpu::AdapterInfo) -> String { - format!("{}-{}", std::env::consts::OS, info.name) -} - const RUN_IMG_TESTS: bool = cfg!(feature = "imgtests"); fn set_logger() { @@ -1185,25 +1181,22 @@ fn run_swf( let movie = SwfMovie::from_path(swf_path, None)?; let frame_time = 1000.0 / movie.frame_rate().to_f64(); let trace_output = Rc::new(RefCell::new(Vec::new())); - - let mut platform_id = None; - let backend_bit = wgpu::Backends::PRIMARY; - let mut builder = PlayerBuilder::new(); + if check_img { - let instance = wgpu::Instance::new(backend_bit); + const BACKEND: wgpu::Backends = wgpu::Backends::PRIMARY; + + let instance = wgpu::Instance::new(BACKEND); let descriptors = futures::executor::block_on(WgpuRenderBackend::::build_descriptors( - backend_bit, + BACKEND, instance, None, Default::default(), None, ))?; - platform_id = Some(get_img_platform_suffix(&descriptors.info)); - let target = TextureTarget::new( &descriptors.device, ( @@ -1216,6 +1209,7 @@ fn run_swf( .with_renderer(WgpuRenderBackend::new(descriptors, target)?) .with_software_video(); }; + let player = builder .with_log(TestLogBackend::new(trace_output.clone())) .with_navigator(NullNavigatorBackend::with_base_path(base_path, &executor)) @@ -1259,55 +1253,32 @@ fn run_swf( // Render the image to disk // FIXME: Determine how we want to compare against on on-disk image if check_img { - player.lock().unwrap().render(); let mut player_lock = player.lock().unwrap(); + player_lock.render(); let renderer = player_lock .renderer_mut() .downcast_mut::>() .unwrap(); let target = renderer.target(); - let image = target + let actual_image = target .capture(renderer.device()) .expect("Failed to capture image"); - // The swf path ends in '/test.swf' - extract `swf_name` - let mut swf_path_buf = PathBuf::from(swf_path); - swf_path_buf.pop(); + let expected_image_path = base_path.join("expected.png"); + let expected_image = + image::open(&expected_image_path).expect("Failed to read expected image"); - let swf_name = swf_path_buf.file_name().unwrap().to_string_lossy(); - let img_name = format!("{}-{}.png", swf_name, platform_id.unwrap()); - - let mut img_path = swf_path_buf.clone(); - img_path.push(&img_name); - - let result = match image::open(&img_path) { - Ok(existing_img) => { - if existing_img - .as_rgba8() - .expect("Expected 8-bit RGBA image") - .as_raw() - == image.as_raw() - { - Ok(()) - } else { - Err(format!( - "Test output does not match existing image `{:?}`", - img_path - )) - } - } - Err(err) => Err(format!( - "Error occured when trying to read existing image `{:?}`: {}", - img_path, err - )), - }; - - if let Err(err) = result { - let new_img_path = img_path.with_file_name(img_name + ".updated"); - image.save_with_format(&new_img_path, image::ImageFormat::Png)?; + if expected_image + .as_rgba8() + .expect("Expected 8-bit RGBA image") + .as_raw() + != actual_image.as_raw() + { + let actual_image_path = base_path.join("actual.png"); + actual_image.save_with_format(&actual_image_path, image::ImageFormat::Png)?; panic!( - "Image test failed - saved new image to `{:?}`\n{}", - new_img_path, err + "Test output does not match expected image - saved actual image to {:?}", + actual_image_path ); } } diff --git a/tests/tests/swfs/avm1/color/color-windows-Microsoft Basic Render Driver.png b/tests/tests/swfs/avm1/color/color-windows-Microsoft Basic Render Driver.png deleted file mode 100644 index c0bca3f0529020b7dda1fe3b42229762a5f1e0ac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1882 zcmeAS@N?(olHy`uVBq!ia0y~yU{YgXV4T3g1{9gKb@gTj26jbH7srr_Id5+q!1gF~AEBZE;3C&L6qABF~=L?(t54q*lb=NSwP zlA}rnNw^%VlKjlfP&2oCG@3@!=4hTBEvQCIXN+2F52Hi3fVg(xmvmsA$>8bg=d#Wz Gp$Pz~0F6Ze diff --git a/tests/tests/swfs/avm1/color/color-linux-llvmpipe (LLVM 14.0.1, 256 bits).png b/tests/tests/swfs/avm1/color/expected.png similarity index 100% rename from tests/tests/swfs/avm1/color/color-linux-llvmpipe (LLVM 14.0.1, 256 bits).png rename to tests/tests/swfs/avm1/color/expected.png