Skip to content

Commit

Permalink
Give test image snapshots distinctive names.
Browse files Browse the repository at this point in the history
Include the adapter name and driver name in the filenames generated to
store the `-actual.png` and `-difference.png` files holding
screenshots of test program output.

Previously, the filename only incorporated the backend, but since we
test the Vulkan backend on both Mac and Windows, one was overwriting
the other in the artifacts.
  • Loading branch information
jimblandy committed Aug 29, 2023
1 parent bc8a8dc commit 6c274a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/common/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ pub fn test<E: Example>(mut params: FrameworkRefTest) {

wgpu_test::image::compare_image_output(
env!("CARGO_MANIFEST_DIR").to_string() + "/../../" + params.image_path,
ctx.adapter_info.backend,
&ctx.adapter_info,
params.width,
params.height,
&bytes,
Expand Down
25 changes: 16 additions & 9 deletions tests/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl ComparisonType {

pub fn compare_image_output(
path: impl AsRef<Path> + AsRef<OsStr>,
backend: Backend,
adapter_info: &wgt::AdapterInfo,
width: u32,
height: u32,
test_with_alpha: &[u8],
Expand Down Expand Up @@ -205,17 +205,18 @@ pub fn compare_image_output(
}

let file_stem = reference_path.file_stem().unwrap().to_string_lossy();
let renderer = format!(
"{}-{}-{}",
adapter_info.backend.to_str(),
sanitize_for_path(&adapter_info.name),
sanitize_for_path(&adapter_info.driver)
);
// Determine the paths to write out the various intermediate files
let actual_path = Path::new(&path).with_file_name(
OsString::from_str(&format!("{}-{}-actual.png", file_stem, backend.to_str(),)).unwrap(),
OsString::from_str(&format!("{}-{}-actual.png", file_stem, renderer)).unwrap(),
);
let difference_path = Path::new(&path).with_file_name(
OsString::from_str(&format!(
"{}-{}-difference.png",
file_stem,
backend.to_str(),
))
.unwrap(),
OsString::from_str(&format!("{}-{}-difference.png", file_stem, renderer,)).unwrap(),
);

// Convert the error values to a false color reprensentation
Expand Down Expand Up @@ -246,10 +247,16 @@ pub fn compare_image_output(

#[cfg(target_arch = "wasm32")]
{
let _ = (path, backend, width, height, test_with_alpha, checks);
let _ = (path, adapter_info, width, height, test_with_alpha, checks);
}
}

fn sanitize_for_path(s: &str) -> String {
s.chars()
.map(|ch| if ch.is_ascii_alphanumeric() { ch } else { '_' })
.collect()
}

fn copy_via_compute(
device: &Device,
encoder: &mut CommandEncoder,
Expand Down

0 comments on commit 6c274a9

Please sign in to comment.