tests: allow verify_screen_content() w/o ref image
authorPekka Paalanen <pekka.paalanen@collabora.com>
Wed, 22 Jan 2020 12:20:46 +0000 (14:20 +0200)
committerPekka Paalanen <pekka.paalanen@collabora.com>
Thu, 27 Feb 2020 14:08:42 +0000 (16:08 +0200)
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>
tests/weston-test-client-helper.c

index b6eaa22d0dccc2dfc2524c867b86b402923b5eb7..5f76914a9a013a34c3efe43bdd014c876d71bfd4 100644 (file)
@@ -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;