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.
This commit is contained in:
parent
cc542e4aae
commit
a3ac9a7064
|
@ -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::<TextureTarget>::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::<WgpuRenderBackend<TextureTarget>>()
|
||||
.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 '<swf_name>/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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Loading…
Reference in New Issue