From 636fc15f20becb634eb66830035fc8a56474b5bb Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Wed, 22 Jan 2020 14:20:46 +0200 Subject: [PATCH] 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 --- tests/weston-test-client-helper.c | 42 ++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index b6eaa22d..5f76914a 100644 --- a/tests/weston-test-client-helper.c +++ b/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. * \return True if the screen contents matches the reference image, * 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 verify_screen_content(struct client *client, @@ -1577,31 +1581,39 @@ verify_screen_content(struct client *client, const char *test_name = get_test_name(); const struct range gl_fuzz = { 0, 1 }; struct buffer *shot; - pixman_image_t *ref; - char *ref_fname; + pixman_image_t *ref = NULL; + char *ref_fname = NULL; char *shot_fname; 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); + write_image_as_png(shot->image, shot_fname); - ref = load_image_from_png(ref_fname); - assert(ref); + if (ref_image) { + ref_fname = screenshot_reference_filename(ref_image, ref_seq_no); + ref = load_image_from_png(ref_fname); + } - shot = capture_screenshot_of_output(client); - assert(shot); + if (ref) { + match = check_images_match(ref, shot->image, clip, &gl_fuzz); + testlog("Verify reference image %s vs. shot %s: %s\n", + ref_fname, shot_fname, match ? "PASS" : "FAIL"); - match = check_images_match(ref, shot->image, clip, &gl_fuzz); - testlog("Verify reference image %s vs. shot %s: %s\n", ref_fname, shot_fname, - match ? "PASS" : "FAIL"); + if (!match) { + write_visual_diff(ref, shot, clip, + test_name, seq_no, &gl_fuzz); + } - write_image_as_png(shot->image, shot_fname); - if (!match) - write_visual_diff(ref, shot, clip, test_name, seq_no, &gl_fuzz); + pixman_image_unref(ref); + } else { + testlog("No reference image, shot %s: FAIL\n", shot_fname); + match = false; + } - buffer_destroy(shot); - pixman_image_unref(ref); free(ref_fname); + buffer_destroy(shot); free(shot_fname); return match;