[PATCH 2/4] tests: promote subsurface-shot-test's write_visual_diff() to a utility function

Micah Fedke micah.fedke at collabora.co.uk
Tue Feb 7 14:42:02 UTC 2017


This function writes out a png file containing the visual diff between a
reference image and a screenshot.
---
 tests/subsurface-shot-test.c      | 24 ---------------------
 tests/weston-test-client-helper.c | 44 +++++++++++++++++++++++++++++++++++++++
 tests/weston-test-client-helper.h |  5 +++++
 3 files changed, 49 insertions(+), 24 deletions(-)

diff --git a/tests/subsurface-shot-test.c b/tests/subsurface-shot-test.c
index 10415ec7..a8dfebad 100644
--- a/tests/subsurface-shot-test.c
+++ b/tests/subsurface-shot-test.c
@@ -96,30 +96,6 @@ color(pixman_color_t *tmp, uint8_t r, uint8_t g, uint8_t b)
 	return tmp;
 }
 
-static void
-write_visual_diff(pixman_image_t *ref_image,
-		  struct buffer *shot,
-		  const struct rectangle *clip,
-		  const char *test_name,
-		  int seq_no)
-{
-	char *fname;
-	char *ext_test_name;
-	pixman_image_t *diff;
-	int ret;
-
-	ret = asprintf(&ext_test_name, "%s-diff", test_name);
-	assert(ret >= 0);
-
-	fname = screenshot_output_filename(ext_test_name, seq_no);
-	diff = visualize_image_difference(shot->image, ref_image, clip);
-	write_image_as_png(diff, fname);
-
-	pixman_image_unref(diff);
-	free(fname);
-	free(ext_test_name);
-}
-
 static int
 check_screen(struct client *client,
 	     const char *ref_image,
diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index fd6d5c84..43a76eb3 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -1211,6 +1211,49 @@ visualize_image_difference(pixman_image_t *img_a, pixman_image_t *img_b,
 }
 
 /**
+ * Write out a png file containing the visual diff between a reference image
+ * and a screenshot
+ *
+ * \param ref_image The reference image.
+ * \param shot A screenshot containing an image to compare to the reference.
+ * \param clip The region of interest, or NULL for comparing the whole
+ * image.
+ * \param test_name The name of the test, which will be used to name the output
+ * file.
+ * \param seq_no The sequence number of the subtest, which will be appended to
+ * the output file name.
+ *
+ * The screenshot must be captured before providing it to this function.  A
+ * NULL reference images or NULL screenshot buffer will trigger an assert.
+ */
+void
+write_visual_diff(pixman_image_t *ref_image,
+		  struct buffer *shot,
+		  const struct rectangle *clip,
+		  const char *test_name,
+		  int seq_no)
+{
+	char *fname;
+	char *ext_test_name;
+	pixman_image_t *diff;
+	int ret;
+
+	assert(ref_image);
+	assert(shot);
+
+	ret = asprintf(&ext_test_name, "%s-diff", test_name);
+	assert(ret >= 0);
+
+	fname = screenshot_output_filename(ext_test_name, seq_no);
+	diff = visualize_image_difference(shot->image, ref_image, clip);
+	write_image_as_png(diff, fname);
+
+	pixman_image_unref(diff);
+	free(fname);
+	free(ext_test_name);
+}
+
+/**
  * Write an image into a PNG file.
  *
  * \param image The image.
@@ -1371,3 +1414,4 @@ capture_screenshot_of_output(struct client *client)
 
 	return buffer;
 }
+
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index a288af7e..8c497e24 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -203,6 +203,11 @@ pixman_image_t *
 visualize_image_difference(pixman_image_t *img_a, pixman_image_t *img_b,
 			   const struct rectangle *clip_rect);
 
+void
+write_visual_diff(pixman_image_t *ref_image, struct buffer *shot,
+		  const struct rectangle *clip, const char *test_name,
+		  int seq_no);
+
 bool
 write_image_as_png(pixman_image_t *image, const char *fname);
 
-- 
2.11.0



More information about the wayland-devel mailing list