tests: add output transform tests
authorPekka Paalanen <pekka.paalanen@collabora.com>
Tue, 21 Jan 2020 10:00:28 +0000 (12:00 +0200)
committerPekka Paalanen <pekka.paalanen@collabora.com>
Fri, 28 Feb 2020 13:07:51 +0000 (15:07 +0200)
This goes through all output transforms with two different buffer transforms
and verifies the visual output against reference images.

This commit introduces a new test input image 'basic-test-card.png'. It is a
small image with deliberately odd and indivisible dimensions to provoke bad
assumptions about image sizes. It contains red, green and blue areas which are
actually text that makes it very obvious if you have e.g. color channels
swapped. It has a white thick circle to highlight aspect ratio issues, and an
orange cross to show a mixed color. The white border is for contrast and a 1px
wide detail. The whole design makes it clear if the image happens to be rotated
or flipped in any way.

The image has one pixel wide transparent border so that bilinear sampling
filter near the edges of the image would produce the same colors with both
Pixman- and GL-renderers which handle the out-of-image samples fundamentally
differently: Pixman assumes (0, 0, 0, 0) samples outside of the image, while
GL-renderer clamps sample coordinates to the edge essentially repeating the
edge pixels.

It would have been "easy" to create a full matrix of
every output scale & transform x every buffer scale & transform, but that
would have resulted in 2 renderers * 8 output transforms * 3 output scales *
8 buffer transforms * 3 buffer scales = 1152 test cases that would have all
ran strictly serially because our test harness has no parallelism inside one
test program. That would have been slow to run, and need a lot more reference
images too.

Instead, I chose to iterate separately through all output scales & transforms
(this patch) and all buffer scales & transforms (next patch). This limits the
number of test cases in this patch to 56, and allows the two test programs to
run in parallel.

I did not even pick all possible scale & transform combinations here, but just
what I think is a representative sub-set to hopefully exercise all the code
paths.

https://gitlab.freedesktop.org/wayland/weston/issues/52

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
33 files changed:
tests/meson.build
tests/output-transforms-test.c [new file with mode: 0644]
tests/reference/basic-test-card.png [new file with mode: 0644]
tests/reference/output_1-180_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_1-180_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_1-270_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_1-270_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_1-90_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_1-90_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_1-FLIPPED_180_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_1-FLIPPED_180_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_1-FLIPPED_270_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_1-FLIPPED_270_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_1-FLIPPED_90_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_1-FLIPPED_90_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_1-FLIPPED_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_1-FLIPPED_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_1-NORMAL_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_1-NORMAL_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_2-180_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_2-180_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_2-90_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_2-90_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_2-FLIPPED_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_2-FLIPPED_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_2-NORMAL_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_2-NORMAL_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_3-FLIPPED_270_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_3-FLIPPED_270_buffer_2-90-00.png [new file with mode: 0644]
tests/reference/output_3-NORMAL_buffer_1-NORMAL-00.png [new file with mode: 0644]
tests/reference/output_3-NORMAL_buffer_2-90-00.png [new file with mode: 0644]
tests/weston-test-client-helper.c
tests/weston-test-client-helper.h

index 87dad82ef71d15e9626560413619cac90b30b46a..705319c0711662c343b2503885d19f032e1ceae1 100644 (file)
@@ -132,6 +132,7 @@ tests = [
                        linux_explicit_synchronization_unstable_v1_protocol_c,
                ],
        },
+       {       'name': 'output-transforms', },
        {       'name': 'plugin-registry', },
        {
                'name': 'pointer',
diff --git a/tests/output-transforms-test.c b/tests/output-transforms-test.c
new file mode 100644 (file)
index 0000000..3ed19e3
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2020 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/mman.h>
+
+#include "weston-test-client-helper.h"
+#include "weston-test-fixture-compositor.h"
+
+#define TRANSFORM(x) WL_OUTPUT_TRANSFORM_ ## x, #x
+#define RENDERERS(s, t) \
+       { RENDERER_PIXMAN, s, TRANSFORM(t) }, \
+       { RENDERER_GL,     s, TRANSFORM(t) }
+
+struct setup_args {
+       enum renderer_type renderer;
+       int scale;
+       enum wl_output_transform transform;
+       const char *transform_name;
+};
+
+static const struct setup_args my_setup_args[] = {
+       RENDERERS(1, NORMAL),
+       RENDERERS(1, 90),
+       RENDERERS(1, 180),
+       RENDERERS(1, 270),
+       RENDERERS(1, FLIPPED),
+       RENDERERS(1, FLIPPED_90),
+       RENDERERS(1, FLIPPED_180),
+       RENDERERS(1, FLIPPED_270),
+       RENDERERS(2, NORMAL),
+       RENDERERS(3, NORMAL),
+       RENDERERS(2, 90),
+       RENDERERS(2, 180),
+       RENDERERS(2, FLIPPED),
+       RENDERERS(3, FLIPPED_270),
+};
+
+static enum test_result_code
+fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg)
+{
+       struct compositor_setup setup;
+
+       /* The width and height are chosen to produce 324x240 framebuffer, to
+        * emulate keeping the video mode constant.
+        * This resolution is divisible by 2 and 3.
+        * Headless multiplies the given size by scale.
+        */
+
+       compositor_setup_defaults(&setup);
+       setup.renderer = arg->renderer;
+       setup.width = 324 / arg->scale;
+       setup.height = 240 / arg->scale;
+       setup.scale = arg->scale;
+       setup.transform = arg->transform;
+       setup.shell = SHELL_TEST_DESKTOP;
+
+       return weston_test_harness_execute_as_client(harness, &setup);
+}
+DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args);
+
+struct buffer_args {
+       int scale;
+       enum wl_output_transform transform;
+       const char *transform_name;
+};
+
+static const struct buffer_args my_buffer_args[] = {
+       { 1, TRANSFORM(NORMAL) },
+       { 2, TRANSFORM(90) },
+};
+
+TEST_P(output_transform, my_buffer_args)
+{
+       const struct buffer_args *bargs = data;
+       const struct setup_args *oargs;
+       struct client *client;
+       bool match;
+       char *refname;
+       int ret;
+
+       oargs = &my_setup_args[get_test_fixture_index()];
+
+       ret = asprintf(&refname, "output_%d-%s_buffer_%d-%s",
+                      oargs->scale, oargs->transform_name,
+                      bargs->scale, bargs->transform_name);
+       assert(ret);
+
+       testlog("%s: %s\n", get_test_name(), refname);
+
+       /*
+        * NOTE! The transform set below is a lie.
+        * Take that into account when analyzing screenshots.
+        */
+
+       client = create_client();
+       client->surface = create_test_surface(client);
+       client->surface->width = 10000; /* used only for damage */
+       client->surface->height = 10000;
+       client->surface->buffer = client_buffer_from_image_file(client,
+                                                       "basic-test-card",
+                                                       bargs->scale);
+       wl_surface_set_buffer_scale(client->surface->wl_surface, bargs->scale);
+       wl_surface_set_buffer_transform(client->surface->wl_surface,
+                                       bargs->transform);
+       move_client(client, 19, 19);
+
+       match = verify_screen_content(client, refname, 0, NULL, 0);
+       assert(match);
+
+       client_destroy(client);
+}
diff --git a/tests/reference/basic-test-card.png b/tests/reference/basic-test-card.png
new file mode 100644 (file)
index 0000000..027ca85
Binary files /dev/null and b/tests/reference/basic-test-card.png differ
diff --git a/tests/reference/output_1-180_buffer_1-NORMAL-00.png b/tests/reference/output_1-180_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..cd60739
Binary files /dev/null and b/tests/reference/output_1-180_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_1-180_buffer_2-90-00.png b/tests/reference/output_1-180_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..8aa9a1f
Binary files /dev/null and b/tests/reference/output_1-180_buffer_2-90-00.png differ
diff --git a/tests/reference/output_1-270_buffer_1-NORMAL-00.png b/tests/reference/output_1-270_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..2f1e976
Binary files /dev/null and b/tests/reference/output_1-270_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_1-270_buffer_2-90-00.png b/tests/reference/output_1-270_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..8a3b03f
Binary files /dev/null and b/tests/reference/output_1-270_buffer_2-90-00.png differ
diff --git a/tests/reference/output_1-90_buffer_1-NORMAL-00.png b/tests/reference/output_1-90_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..f17d21d
Binary files /dev/null and b/tests/reference/output_1-90_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_1-90_buffer_2-90-00.png b/tests/reference/output_1-90_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..f3bb62c
Binary files /dev/null and b/tests/reference/output_1-90_buffer_2-90-00.png differ
diff --git a/tests/reference/output_1-FLIPPED_180_buffer_1-NORMAL-00.png b/tests/reference/output_1-FLIPPED_180_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..f93d7e3
Binary files /dev/null and b/tests/reference/output_1-FLIPPED_180_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_1-FLIPPED_180_buffer_2-90-00.png b/tests/reference/output_1-FLIPPED_180_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..381ef74
Binary files /dev/null and b/tests/reference/output_1-FLIPPED_180_buffer_2-90-00.png differ
diff --git a/tests/reference/output_1-FLIPPED_270_buffer_1-NORMAL-00.png b/tests/reference/output_1-FLIPPED_270_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..91c5cdb
Binary files /dev/null and b/tests/reference/output_1-FLIPPED_270_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_1-FLIPPED_270_buffer_2-90-00.png b/tests/reference/output_1-FLIPPED_270_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..15333fc
Binary files /dev/null and b/tests/reference/output_1-FLIPPED_270_buffer_2-90-00.png differ
diff --git a/tests/reference/output_1-FLIPPED_90_buffer_1-NORMAL-00.png b/tests/reference/output_1-FLIPPED_90_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..bdb129b
Binary files /dev/null and b/tests/reference/output_1-FLIPPED_90_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_1-FLIPPED_90_buffer_2-90-00.png b/tests/reference/output_1-FLIPPED_90_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..1ed5cba
Binary files /dev/null and b/tests/reference/output_1-FLIPPED_90_buffer_2-90-00.png differ
diff --git a/tests/reference/output_1-FLIPPED_buffer_1-NORMAL-00.png b/tests/reference/output_1-FLIPPED_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..4e361c3
Binary files /dev/null and b/tests/reference/output_1-FLIPPED_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_1-FLIPPED_buffer_2-90-00.png b/tests/reference/output_1-FLIPPED_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..0e32a86
Binary files /dev/null and b/tests/reference/output_1-FLIPPED_buffer_2-90-00.png differ
diff --git a/tests/reference/output_1-NORMAL_buffer_1-NORMAL-00.png b/tests/reference/output_1-NORMAL_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..83ff885
Binary files /dev/null and b/tests/reference/output_1-NORMAL_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_1-NORMAL_buffer_2-90-00.png b/tests/reference/output_1-NORMAL_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..f95cec5
Binary files /dev/null and b/tests/reference/output_1-NORMAL_buffer_2-90-00.png differ
diff --git a/tests/reference/output_2-180_buffer_1-NORMAL-00.png b/tests/reference/output_2-180_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..3a507f7
Binary files /dev/null and b/tests/reference/output_2-180_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_2-180_buffer_2-90-00.png b/tests/reference/output_2-180_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..edd425e
Binary files /dev/null and b/tests/reference/output_2-180_buffer_2-90-00.png differ
diff --git a/tests/reference/output_2-90_buffer_1-NORMAL-00.png b/tests/reference/output_2-90_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..127cd51
Binary files /dev/null and b/tests/reference/output_2-90_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_2-90_buffer_2-90-00.png b/tests/reference/output_2-90_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..bd526ca
Binary files /dev/null and b/tests/reference/output_2-90_buffer_2-90-00.png differ
diff --git a/tests/reference/output_2-FLIPPED_buffer_1-NORMAL-00.png b/tests/reference/output_2-FLIPPED_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..8c456b5
Binary files /dev/null and b/tests/reference/output_2-FLIPPED_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_2-FLIPPED_buffer_2-90-00.png b/tests/reference/output_2-FLIPPED_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..58206d1
Binary files /dev/null and b/tests/reference/output_2-FLIPPED_buffer_2-90-00.png differ
diff --git a/tests/reference/output_2-NORMAL_buffer_1-NORMAL-00.png b/tests/reference/output_2-NORMAL_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..b1d2a37
Binary files /dev/null and b/tests/reference/output_2-NORMAL_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_2-NORMAL_buffer_2-90-00.png b/tests/reference/output_2-NORMAL_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..26b5789
Binary files /dev/null and b/tests/reference/output_2-NORMAL_buffer_2-90-00.png differ
diff --git a/tests/reference/output_3-FLIPPED_270_buffer_1-NORMAL-00.png b/tests/reference/output_3-FLIPPED_270_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..878307d
Binary files /dev/null and b/tests/reference/output_3-FLIPPED_270_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_3-FLIPPED_270_buffer_2-90-00.png b/tests/reference/output_3-FLIPPED_270_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..e4a5ccc
Binary files /dev/null and b/tests/reference/output_3-FLIPPED_270_buffer_2-90-00.png differ
diff --git a/tests/reference/output_3-NORMAL_buffer_1-NORMAL-00.png b/tests/reference/output_3-NORMAL_buffer_1-NORMAL-00.png
new file mode 100644 (file)
index 0000000..7ab0ba0
Binary files /dev/null and b/tests/reference/output_3-NORMAL_buffer_1-NORMAL-00.png differ
diff --git a/tests/reference/output_3-NORMAL_buffer_2-90-00.png b/tests/reference/output_3-NORMAL_buffer_2-90-00.png
new file mode 100644 (file)
index 0000000..b1133ef
Binary files /dev/null and b/tests/reference/output_3-NORMAL_buffer_2-90-00.png differ
index 27ea0f1fc84052cba6c3eea37e1307408724944b..6e270d379c24d5624e27849ff400bddbe8f723ce 100644 (file)
@@ -1118,6 +1118,16 @@ screenshot_reference_filename(const char *basename, uint32_t seq)
        return filename;
 }
 
+char *
+image_filename(const char *basename)
+{
+       char *filename;
+
+       if (asprintf(&filename, "%s/%s.png", reference_path(), basename) < 0)
+               assert(0);
+       return filename;
+}
+
 struct format_map_entry {
        cairo_format_t cairo;
        pixman_format_code_t pixman;
@@ -1694,3 +1704,55 @@ verify_screen_content(struct client *client,
 
        return match;
 }
+
+/**
+ * Create a wl_buffer from a PNG file
+ *
+ * Loads the named PNG file from the directory of reference images,
+ * creates a wl_buffer with scale times the image dimensions in pixels,
+ * and copies the image content into the buffer using nearest-neighbor filter.
+ *
+ * \param client The client, for the Wayland connection.
+ * \param basename The PNG file name without .png suffix.
+ * \param scale Upscaling factor >= 1.
+ */
+struct buffer *
+client_buffer_from_image_file(struct client *client,
+                             const char *basename,
+                             int scale)
+{
+       struct buffer *buf;
+       char *fname;
+       pixman_image_t *img;
+       int buf_w, buf_h;
+       pixman_transform_t scaling;
+
+       assert(scale >= 1);
+
+       fname = image_filename(basename);
+       img = load_image_from_png(fname);
+       free(fname);
+       assert(img);
+
+       buf_w = scale * pixman_image_get_width(img);
+       buf_h = scale * pixman_image_get_height(img);
+       buf = create_shm_buffer_a8r8g8b8(client, buf_w, buf_h);
+
+       pixman_transform_init_scale(&scaling,
+                                   pixman_fixed_1 / scale,
+                                   pixman_fixed_1 / scale);
+       pixman_image_set_transform(img, &scaling);
+       pixman_image_set_filter(img, PIXMAN_FILTER_NEAREST, NULL, 0);
+
+       pixman_image_composite32(PIXMAN_OP_SRC,
+                                img, /* src */
+                                NULL, /* mask */
+                                buf->image, /* dst */
+                                0, 0, /* src x,y */
+                                0, 0, /* mask x,y */
+                                0, 0, /* dst x,y */
+                                buf_w, buf_h);
+       pixman_image_unref(img);
+
+       return buf;
+}
index f4ed919f8cc47c44883105fd2e42017295e5b936..a8253137aec9136a45be12127635ccd6f488aa19 100644 (file)
@@ -235,6 +235,9 @@ screenshot_output_filename(const char *basename, uint32_t seq);
 char *
 screenshot_reference_filename(const char *basename, uint32_t seq);
 
+char *
+image_filename(const char *basename);
+
 bool
 check_images_match(pixman_image_t *img_a, pixman_image_t *img_b,
                   const struct rectangle *clip,
@@ -261,4 +264,9 @@ verify_screen_content(struct client *client,
                      const struct rectangle *clip,
                      int seq_no);
 
+struct buffer *
+client_buffer_from_image_file(struct client *client,
+                             const char *basename,
+                             int scale);
+
 #endif