tests: allow verify_screen_content() w/o ref image

Allow the reference image to be NULL or missing so that it does not even
attempt to load a reference image or compare it. You cannot just point the
reference image to an arbitrary image because the comparison functions can
abort due to size mismatch. This makes bootstrapping new tests easier when you
do not yet have a reference image.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 5 years ago
parent 7009806b94
commit 636fc15f20
  1. 38
      tests/weston-test-client-helper.c

@ -1566,6 +1566,10 @@ write_visual_diff(pixman_image_t *ref_image,
* \param seq_no Test sequence number, for writing output files. * \param seq_no Test sequence number, for writing output files.
* \return True if the screen contents matches the reference image, * \return True if the screen contents matches the reference image,
* false otherwise. * false otherwise.
*
* For bootstrapping, ref_image can be NULL or the file can be missing.
* In that case the screenshot file is written but no comparison is performed,
* and false is returned.
*/ */
bool bool
verify_screen_content(struct client *client, verify_screen_content(struct client *client,
@ -1577,31 +1581,39 @@ verify_screen_content(struct client *client,
const char *test_name = get_test_name(); const char *test_name = get_test_name();
const struct range gl_fuzz = { 0, 1 }; const struct range gl_fuzz = { 0, 1 };
struct buffer *shot; struct buffer *shot;
pixman_image_t *ref; pixman_image_t *ref = NULL;
char *ref_fname; char *ref_fname = NULL;
char *shot_fname; char *shot_fname;
bool match; bool match;
ref_fname = screenshot_reference_filename(ref_image, ref_seq_no); shot = capture_screenshot_of_output(client);
assert(shot);
shot_fname = screenshot_output_filename(test_name, seq_no); shot_fname = screenshot_output_filename(test_name, seq_no);
write_image_as_png(shot->image, shot_fname);
if (ref_image) {
ref_fname = screenshot_reference_filename(ref_image, ref_seq_no);
ref = load_image_from_png(ref_fname); ref = load_image_from_png(ref_fname);
assert(ref); }
shot = capture_screenshot_of_output(client);
assert(shot);
if (ref) {
match = check_images_match(ref, shot->image, clip, &gl_fuzz); match = check_images_match(ref, shot->image, clip, &gl_fuzz);
testlog("Verify reference image %s vs. shot %s: %s\n", ref_fname, shot_fname, testlog("Verify reference image %s vs. shot %s: %s\n",
match ? "PASS" : "FAIL"); ref_fname, shot_fname, match ? "PASS" : "FAIL");
write_image_as_png(shot->image, shot_fname); if (!match) {
if (!match) write_visual_diff(ref, shot, clip,
write_visual_diff(ref, shot, clip, test_name, seq_no, &gl_fuzz); test_name, seq_no, &gl_fuzz);
}
buffer_destroy(shot);
pixman_image_unref(ref); pixman_image_unref(ref);
} else {
testlog("No reference image, shot %s: FAIL\n", shot_fname);
match = false;
}
free(ref_fname); free(ref_fname);
buffer_destroy(shot);
free(shot_fname); free(shot_fname);
return match; return match;

Loading…
Cancel
Save