You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weston/tests/roles-test.c

156 lines
4.0 KiB

/*
* Copyright © 2014 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 <assert.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>
5 years ago
#include "weston-test-fixture-compositor.h"
static enum test_result_code
fixture_setup(struct weston_test_harness *harness)
{
struct compositor_setup setup;
compositor_setup_defaults(&setup);
setup.logging_scopes = "log,proto,test-harness-plugin";
return weston_test_harness_execute_as_client(harness, &setup);
}
DECLARE_FIXTURE_SETUP(fixture_setup);
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;
}
static struct wl_shell *
get_wl_shell(struct client *client)
{
struct global *g;
struct global *global = NULL;
struct wl_shell *shell;
wl_list_for_each(g, &client->global_list, link) {
if (strcmp(g->interface, "wl_shell"))
continue;
if (global)
assert(0 && "multiple wl_shell objects");
global = g;
}
assert(global && "no wl_shell found");
shell = wl_registry_bind(client->wl_registry, global->name,
&wl_shell_interface, 1);
assert(shell);
return shell;
}
TEST(test_role_conflict_sub_wlshell)
{
struct client *client;
struct wl_subcompositor *subco;
struct wl_surface *child;
struct wl_subsurface *sub;
struct wl_shell *shell;
struct wl_shell_surface *shsurf;
client = create_client_and_test_surface(100, 50, 123, 77);
assert(client);
subco = get_subcompositor(client);
shell = get_wl_shell(client);
child = wl_compositor_create_surface(client->wl_compositor);
assert(child);
sub = wl_subcompositor_get_subsurface(subco, child,
client->surface->wl_surface);
assert(sub);
shsurf = wl_shell_get_shell_surface(shell, child);
assert(shsurf);
expect_protocol_error(client, &wl_shell_interface,
WL_SHELL_ERROR_ROLE);
}
TEST(test_role_conflict_wlshell_sub)
{
struct client *client;
struct wl_subcompositor *subco;
struct wl_surface *child;
struct wl_subsurface *sub;
struct wl_shell *shell;
struct wl_shell_surface *shsurf;
client = create_client_and_test_surface(100, 50, 123, 77);
assert(client);
subco = get_subcompositor(client);
shell = get_wl_shell(client);
child = wl_compositor_create_surface(client->wl_compositor);
assert(child);
shsurf = wl_shell_get_shell_surface(shell, child);
assert(shsurf);
sub = wl_subcompositor_get_subsurface(subco, child,
client->surface->wl_surface);
assert(sub);
expect_protocol_error(client, &wl_subcompositor_interface,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE);
}