2017-01-27 19:30:28 +03:00
|
|
|
/*
|
|
|
|
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
|
|
* Copyright © 2016 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"
|
tests: thread-based client harness
This replaces the old test harness with a new one.
The old harness relied on fork()'ing each test which makes tests independent,
but makes debugging them harder. The new harness runs client code in a thread
instead of a new process. A side-effect of not fork()'ing anymore is that any
failure will stop running a test series short. Fortunately we do not have any
tests that are expected to crash or fail.
The old harness executed 'weston' from Meson, with lots of setup as both
command line options and environment variables. The new harness executes
wet_main() instead: the test program itself calls the compositor main function
to execute the compositor in-process. Command line arguments are configured in
the test program itself, not in meson.build. Environment variables aside, you
are able to run a test by simply executing the test program, even if it is a
plugin test.
The new harness adds a new type of iteration: fixtures. For now, fixtures are
used to set up the compositor for tests that need a compositor. If necessary, a
fixture setup may include a data array of arbitrary type for executing the test
series for each element in the array. This will be most useful for running
screenshooting tests with both Pixman- and GL-renderers.
The new harness outputs TAP formatted results into stdout. Meson is not
switched to consume TAP yet though, because it would require a Meson version
requirement bump and would not have any benefits at this time. OTOH outputting
TAP is trivial and sets up a clear precedent of random test chatter belonging
to stderr.
This commit migrates only few tests to actually make use of the new features:
roles is a basic client test, subsurface-shot is a client test that
demonstrates the fixture array, and plugin-registry is a plugin test. The rest
of the tests will be migrated later.
Once all tests are migrated, we can remove the test-specific setup from
meson.build, leaving only the actual build instructions in there.
The not migrated tests and stand-alone tests suffer only a minor change: they
no longer fork() for each TEST(), otherwise they keep running as before.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-11-01 15:02:15 +03:00
|
|
|
#include "weston-test-fixture-compositor.h"
|
2017-01-27 19:30:28 +03:00
|
|
|
|
2021-02-15 14:46:42 +03:00
|
|
|
struct setup_args {
|
|
|
|
struct fixture_metadata meta;
|
|
|
|
enum renderer_type renderer;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct setup_args my_setup_args[] = {
|
|
|
|
{
|
|
|
|
.renderer = RENDERER_PIXMAN,
|
|
|
|
.meta.name = "pixman"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.renderer = RENDERER_GL,
|
|
|
|
.meta.name = "GL"
|
|
|
|
},
|
tests: thread-based client harness
This replaces the old test harness with a new one.
The old harness relied on fork()'ing each test which makes tests independent,
but makes debugging them harder. The new harness runs client code in a thread
instead of a new process. A side-effect of not fork()'ing anymore is that any
failure will stop running a test series short. Fortunately we do not have any
tests that are expected to crash or fail.
The old harness executed 'weston' from Meson, with lots of setup as both
command line options and environment variables. The new harness executes
wet_main() instead: the test program itself calls the compositor main function
to execute the compositor in-process. Command line arguments are configured in
the test program itself, not in meson.build. Environment variables aside, you
are able to run a test by simply executing the test program, even if it is a
plugin test.
The new harness adds a new type of iteration: fixtures. For now, fixtures are
used to set up the compositor for tests that need a compositor. If necessary, a
fixture setup may include a data array of arbitrary type for executing the test
series for each element in the array. This will be most useful for running
screenshooting tests with both Pixman- and GL-renderers.
The new harness outputs TAP formatted results into stdout. Meson is not
switched to consume TAP yet though, because it would require a Meson version
requirement bump and would not have any benefits at this time. OTOH outputting
TAP is trivial and sets up a clear precedent of random test chatter belonging
to stderr.
This commit migrates only few tests to actually make use of the new features:
roles is a basic client test, subsurface-shot is a client test that
demonstrates the fixture array, and plugin-registry is a plugin test. The rest
of the tests will be migrated later.
Once all tests are migrated, we can remove the test-specific setup from
meson.build, leaving only the actual build instructions in there.
The not migrated tests and stand-alone tests suffer only a minor change: they
no longer fork() for each TEST(), otherwise they keep running as before.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-11-01 15:02:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static enum test_result_code
|
2021-02-15 14:46:42 +03:00
|
|
|
fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg)
|
tests: thread-based client harness
This replaces the old test harness with a new one.
The old harness relied on fork()'ing each test which makes tests independent,
but makes debugging them harder. The new harness runs client code in a thread
instead of a new process. A side-effect of not fork()'ing anymore is that any
failure will stop running a test series short. Fortunately we do not have any
tests that are expected to crash or fail.
The old harness executed 'weston' from Meson, with lots of setup as both
command line options and environment variables. The new harness executes
wet_main() instead: the test program itself calls the compositor main function
to execute the compositor in-process. Command line arguments are configured in
the test program itself, not in meson.build. Environment variables aside, you
are able to run a test by simply executing the test program, even if it is a
plugin test.
The new harness adds a new type of iteration: fixtures. For now, fixtures are
used to set up the compositor for tests that need a compositor. If necessary, a
fixture setup may include a data array of arbitrary type for executing the test
series for each element in the array. This will be most useful for running
screenshooting tests with both Pixman- and GL-renderers.
The new harness outputs TAP formatted results into stdout. Meson is not
switched to consume TAP yet though, because it would require a Meson version
requirement bump and would not have any benefits at this time. OTOH outputting
TAP is trivial and sets up a clear precedent of random test chatter belonging
to stderr.
This commit migrates only few tests to actually make use of the new features:
roles is a basic client test, subsurface-shot is a client test that
demonstrates the fixture array, and plugin-registry is a plugin test. The rest
of the tests will be migrated later.
Once all tests are migrated, we can remove the test-specific setup from
meson.build, leaving only the actual build instructions in there.
The not migrated tests and stand-alone tests suffer only a minor change: they
no longer fork() for each TEST(), otherwise they keep running as before.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-11-01 15:02:15 +03:00
|
|
|
{
|
|
|
|
struct compositor_setup setup;
|
|
|
|
|
|
|
|
compositor_setup_defaults(&setup);
|
2021-02-15 14:46:42 +03:00
|
|
|
setup.renderer = arg->renderer;
|
tests: thread-based client harness
This replaces the old test harness with a new one.
The old harness relied on fork()'ing each test which makes tests independent,
but makes debugging them harder. The new harness runs client code in a thread
instead of a new process. A side-effect of not fork()'ing anymore is that any
failure will stop running a test series short. Fortunately we do not have any
tests that are expected to crash or fail.
The old harness executed 'weston' from Meson, with lots of setup as both
command line options and environment variables. The new harness executes
wet_main() instead: the test program itself calls the compositor main function
to execute the compositor in-process. Command line arguments are configured in
the test program itself, not in meson.build. Environment variables aside, you
are able to run a test by simply executing the test program, even if it is a
plugin test.
The new harness adds a new type of iteration: fixtures. For now, fixtures are
used to set up the compositor for tests that need a compositor. If necessary, a
fixture setup may include a data array of arbitrary type for executing the test
series for each element in the array. This will be most useful for running
screenshooting tests with both Pixman- and GL-renderers.
The new harness outputs TAP formatted results into stdout. Meson is not
switched to consume TAP yet though, because it would require a Meson version
requirement bump and would not have any benefits at this time. OTOH outputting
TAP is trivial and sets up a clear precedent of random test chatter belonging
to stderr.
This commit migrates only few tests to actually make use of the new features:
roles is a basic client test, subsurface-shot is a client test that
demonstrates the fixture array, and plugin-registry is a plugin test. The rest
of the tests will be migrated later.
Once all tests are migrated, we can remove the test-specific setup from
meson.build, leaving only the actual build instructions in there.
The not migrated tests and stand-alone tests suffer only a minor change: they
no longer fork() for each TEST(), otherwise they keep running as before.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-11-01 15:02:15 +03:00
|
|
|
setup.width = 320;
|
|
|
|
setup.height = 240;
|
|
|
|
setup.shell = SHELL_TEST_DESKTOP;
|
|
|
|
setup.logging_scopes = "log,test-harness-plugin";
|
|
|
|
|
|
|
|
return weston_test_harness_execute_as_client(harness, &setup);
|
|
|
|
}
|
2021-02-15 14:46:42 +03:00
|
|
|
DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta);
|
2017-01-27 19:30:28 +03:00
|
|
|
|
|
|
|
static struct wl_subcompositor *
|
|
|
|
get_subcompositor(struct client *client)
|
|
|
|
{
|
|
|
|
struct global *g;
|
|
|
|
struct global *global_sub = NULL;
|
|
|
|
struct wl_subcompositor *sub;
|
|
|
|
|
|
|
|
wl_list_for_each(g, &client->global_list, link) {
|
|
|
|
if (strcmp(g->interface, "wl_subcompositor"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (global_sub)
|
|
|
|
assert(0 && "multiple wl_subcompositor objects");
|
|
|
|
|
|
|
|
global_sub = g;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(global_sub && "no wl_subcompositor found");
|
|
|
|
|
|
|
|
assert(global_sub->version == 1);
|
|
|
|
|
|
|
|
sub = wl_registry_bind(client->wl_registry, global_sub->name,
|
|
|
|
&wl_subcompositor_interface, 1);
|
|
|
|
assert(sub);
|
|
|
|
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2020-01-21 16:37:14 +03:00
|
|
|
static int
|
|
|
|
check_screen(struct client *client,
|
|
|
|
const char *ref_image,
|
|
|
|
int ref_seq_no,
|
|
|
|
const struct rectangle *clip,
|
|
|
|
int seq_no)
|
|
|
|
{
|
|
|
|
bool match;
|
|
|
|
|
|
|
|
match = verify_screen_content(client, ref_image, ref_seq_no, clip,
|
|
|
|
seq_no);
|
|
|
|
|
|
|
|
return match ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2017-01-27 19:30:28 +03:00
|
|
|
static struct buffer *
|
|
|
|
surface_commit_color(struct client *client, struct wl_surface *surface,
|
|
|
|
pixman_color_t *color, int width, int height)
|
|
|
|
{
|
|
|
|
struct buffer *buf;
|
|
|
|
|
|
|
|
buf = create_shm_buffer_a8r8g8b8(client, width, height);
|
2020-03-11 18:24:47 +03:00
|
|
|
fill_image_with_color(buf->image, color);
|
2017-01-27 19:30:28 +03:00
|
|
|
wl_surface_attach(surface, buf->proxy, 0, 0);
|
|
|
|
wl_surface_damage(surface, 0, 0, width, height);
|
|
|
|
wl_surface_commit(surface);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2017-01-27 19:30:29 +03:00
|
|
|
TEST(subsurface_z_order)
|
2017-01-27 19:30:28 +03:00
|
|
|
{
|
|
|
|
struct client *client;
|
|
|
|
struct wl_subcompositor *subco;
|
|
|
|
struct buffer *bufs[5] = { 0 };
|
|
|
|
struct wl_surface *surf[5] = { 0 };
|
|
|
|
struct wl_subsurface *sub[5] = { 0 };
|
|
|
|
struct rectangle clip = { 40, 40, 280, 200 };
|
|
|
|
int fail = 0;
|
|
|
|
unsigned i;
|
|
|
|
pixman_color_t red;
|
|
|
|
pixman_color_t blue;
|
|
|
|
pixman_color_t cyan;
|
|
|
|
pixman_color_t green;
|
|
|
|
|
2020-03-11 18:24:47 +03:00
|
|
|
color_rgb888(&red, 255, 0, 0);
|
|
|
|
color_rgb888(&blue, 0, 0, 255);
|
|
|
|
color_rgb888(&cyan, 0, 255, 255);
|
|
|
|
color_rgb888(&green, 0, 255, 0);
|
2017-01-27 19:30:28 +03:00
|
|
|
|
|
|
|
client = create_client_and_test_surface(100, 50, 100, 100);
|
|
|
|
assert(client);
|
|
|
|
subco = get_subcompositor(client);
|
|
|
|
|
|
|
|
/* move the pointer clearly away from our screenshooting area */
|
2017-12-13 14:27:55 +03:00
|
|
|
weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30);
|
2017-01-27 19:30:28 +03:00
|
|
|
|
|
|
|
/* make the parent surface red */
|
|
|
|
surf[0] = client->surface->wl_surface;
|
2021-06-18 12:52:04 +03:00
|
|
|
client->surface->wl_surface = NULL; /* we stole it and destroy it */
|
2017-01-27 19:30:28 +03:00
|
|
|
bufs[0] = surface_commit_color(client, surf[0], &red, 100, 100);
|
|
|
|
/* sub[0] is not used */
|
|
|
|
|
2019-11-15 16:48:08 +03:00
|
|
|
fail += check_screen(client, "subsurface_z_order", 0, &clip, 0);
|
2017-01-27 19:30:28 +03:00
|
|
|
|
|
|
|
/* create a blue sub-surface above red */
|
|
|
|
surf[1] = wl_compositor_create_surface(client->wl_compositor);
|
|
|
|
sub[1] = wl_subcompositor_get_subsurface(subco, surf[1], surf[0]);
|
|
|
|
bufs[1] = surface_commit_color(client, surf[1], &blue, 100, 100);
|
|
|
|
|
|
|
|
wl_subsurface_set_position(sub[1], 20, 20);
|
|
|
|
wl_surface_commit(surf[0]);
|
|
|
|
|
2019-11-15 16:48:08 +03:00
|
|
|
fail += check_screen(client, "subsurface_z_order", 1, &clip, 1);
|
2017-01-27 19:30:28 +03:00
|
|
|
|
|
|
|
/* create a cyan sub-surface above blue */
|
|
|
|
surf[2] = wl_compositor_create_surface(client->wl_compositor);
|
|
|
|
sub[2] = wl_subcompositor_get_subsurface(subco, surf[2], surf[1]);
|
|
|
|
bufs[2] = surface_commit_color(client, surf[2], &cyan, 100, 100);
|
|
|
|
|
|
|
|
wl_subsurface_set_position(sub[2], 20, 20);
|
|
|
|
wl_surface_commit(surf[1]);
|
|
|
|
wl_surface_commit(surf[0]);
|
|
|
|
|
2019-11-15 16:48:08 +03:00
|
|
|
fail += check_screen(client, "subsurface_z_order", 2, &clip, 2);
|
2017-01-27 19:30:28 +03:00
|
|
|
|
|
|
|
/* create a green sub-surface above blue, sibling to cyan */
|
|
|
|
surf[3] = wl_compositor_create_surface(client->wl_compositor);
|
|
|
|
sub[3] = wl_subcompositor_get_subsurface(subco, surf[3], surf[1]);
|
|
|
|
bufs[3] = surface_commit_color(client, surf[3], &green, 100, 100);
|
|
|
|
|
|
|
|
wl_subsurface_set_position(sub[3], -40, 10);
|
|
|
|
wl_surface_commit(surf[1]);
|
|
|
|
wl_surface_commit(surf[0]);
|
|
|
|
|
2019-11-15 16:48:08 +03:00
|
|
|
fail += check_screen(client, "subsurface_z_order", 3, &clip, 3);
|
2017-01-27 19:30:28 +03:00
|
|
|
|
|
|
|
/* stack blue below red, which brings also cyan and green below red */
|
|
|
|
wl_subsurface_place_below(sub[1], surf[0]);
|
|
|
|
wl_surface_commit(surf[0]);
|
|
|
|
|
2019-11-15 16:48:08 +03:00
|
|
|
fail += check_screen(client, "subsurface_z_order", 4, &clip, 4);
|
2017-01-27 19:30:28 +03:00
|
|
|
|
|
|
|
assert(fail == 0);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(sub); i++)
|
|
|
|
if (sub[i])
|
|
|
|
wl_subsurface_destroy(sub[i]);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(surf); i++)
|
|
|
|
if (surf[i])
|
|
|
|
wl_surface_destroy(surf[i]);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(bufs); i++)
|
|
|
|
if (bufs[i])
|
|
|
|
buffer_destroy(bufs[i]);
|
2021-06-18 12:52:04 +03:00
|
|
|
|
|
|
|
wl_subcompositor_destroy(subco);
|
|
|
|
client_destroy(client);
|
2017-01-27 19:30:28 +03:00
|
|
|
}
|