tests: add mechanism to change Weston's behavior when running certain tests

There are some specific cases in which we need Weston to
behave differently when running in the test suite. This
adds a new API to allow the tests to select these behaviors.

For instance, in the DRM backend we plan to add a writeback
connector screenshooter. In case it fails for some
reason, it should fallback to the renderer screenshooter
that all other backends use. But if we add a test to
ensure the correctness of the writeback screenshooter,
we don't want it to fallback to the renderer one, we
want it to fail. With this new API we can choose to
disable the fallback behavior specifically for this test.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
dev
Leandro Ribeiro 4 years ago committed by Pekka Paalanen
parent 526765ddfd
commit 32a5acde5b
  1. 2
      compositor/executable.c
  2. 5
      compositor/main.c
  3. 1
      compositor/meson.build
  4. 62
      compositor/testsuite-util.c
  5. 8
      compositor/weston.h
  6. 30
      include/libweston/libweston.h
  7. 49
      libweston/compositor.c
  8. 7
      tests/weston-test-fixture-compositor.c
  9. 2
      tests/weston-test-fixture-compositor.h
  10. 2
      tests/weston-test.c

@ -30,5 +30,5 @@
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
return wet_main(argc, argv); return wet_main(argc, argv, NULL);
} }

@ -3119,7 +3119,7 @@ weston_log_subscribe_to_scopes(struct weston_log_context *log_ctx,
} }
WL_EXPORT int WL_EXPORT int
wet_main(int argc, char *argv[]) wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
{ {
int ret = EXIT_FAILURE; int ret = EXIT_FAILURE;
char *cmdline; char *cmdline;
@ -3289,6 +3289,9 @@ wet_main(int argc, char *argv[])
goto out; goto out;
} }
if (test_data)
weston_compositor_test_data_init(wet.compositor, test_data);
protocol_scope = protocol_scope =
weston_log_ctx_add_log_scope(log_ctx, "proto", weston_log_ctx_add_log_scope(log_ctx, "proto",
"Wayland protocol dump for all clients.\n", "Wayland protocol dump for all clients.\n",

@ -1,7 +1,6 @@
srcs_weston = [ srcs_weston = [
git_version_h, git_version_h,
'main.c', 'main.c',
'testsuite-util.c',
'text-backend.c', 'text-backend.c',
'weston-screenshooter.c', 'weston-screenshooter.c',
text_input_unstable_v1_server_protocol_h, text_input_unstable_v1_server_protocol_h,

@ -1,62 +0,0 @@
/*
* Copyright 2019 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 <wayland-util.h>
#include "weston.h"
static struct wet_testsuite_data *wet_testsuite_data_global;
/** Set global test suite data
*
* \param data Custom test suite data.
*
* The type struct wet_testsuite_data is free to be defined by any test suite
* in any way they want. This function stores a single pointer to that data
* in a global variable.
*
* The data is expected to be fetched from a test suite specific plugin that
* knows how to interpret it.
*
* \sa wet_testsuite_data_get
*/
WL_EXPORT void
wet_testsuite_data_set(struct wet_testsuite_data *data)
{
wet_testsuite_data_global = data;
}
/** Get global test suite data
*
* \return Custom test suite data.
*
* Returns the value last set with wet_testsuite_data_set().
*/
WL_EXPORT struct wet_testsuite_data *
wet_testsuite_data_get(void)
{
return wet_testsuite_data_global;
}

@ -96,7 +96,7 @@ void
text_backend_destroy(struct text_backend *text_backend); text_backend_destroy(struct text_backend *text_backend);
int int
wet_main(int argc, char *argv[]); wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data);
/* test suite utilities */ /* test suite utilities */
@ -104,12 +104,6 @@ wet_main(int argc, char *argv[]);
/** Opaque type for a test suite to define. */ /** Opaque type for a test suite to define. */
struct wet_testsuite_data; struct wet_testsuite_data;
void
wet_testsuite_data_set(struct wet_testsuite_data *data);
struct wet_testsuite_data *
wet_testsuite_data_get(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -185,6 +185,27 @@ enum weston_hdcp_protection {
WESTON_HDCP_ENABLE_TYPE_1 WESTON_HDCP_ENABLE_TYPE_1
}; };
/** Weston test suite quirks
*
* There are some things that need a specific behavior when we run Weston in the
* test suite. Tests can use this struct to select for certain behaviors.
*
* \sa compositor_setup
* \ingroup testharness
*/
struct weston_testsuite_quirks {
};
/** Weston test suite data that is given to compositor
*
* \sa compositor_setup
* \ingroup testharness
*/
struct weston_testsuite_data {
struct weston_testsuite_quirks test_quirks;
struct wet_testsuite_data *test_private_data;
};
/** Represents a head, usually a display connector /** Represents a head, usually a display connector
* *
* \rst * \rst
@ -1105,6 +1126,9 @@ struct weston_compositor {
/* Whether to let the compositor run without any input device. */ /* Whether to let the compositor run without any input device. */
bool require_input; bool require_input;
/* Test suite data */
struct weston_testsuite_data test_data;
/* Signal for a backend to inform a frontend about possible changes /* Signal for a backend to inform a frontend about possible changes
* in head status. * in head status.
*/ */
@ -1776,6 +1800,12 @@ struct weston_compositor *
weston_compositor_create(struct wl_display *display, weston_compositor_create(struct wl_display *display,
struct weston_log_context *log_ctx, void *user_data); struct weston_log_context *log_ctx, void *user_data);
void
weston_compositor_test_data_init(struct weston_compositor *ec,
const struct weston_testsuite_data *test_data);
void *
weston_compositor_get_test_data(struct weston_compositor *ec);
bool bool
weston_compositor_add_destroy_listener_once(struct weston_compositor *compositor, weston_compositor_add_destroy_listener_once(struct weston_compositor *compositor,
struct wl_listener *listener, struct wl_listener *listener,

@ -7327,6 +7327,55 @@ debug_scene_graph_cb(struct weston_log_subscription *sub, void *data)
weston_log_subscription_complete(sub); weston_log_subscription_complete(sub);
} }
/** Init the compositor testsuite data
*
* The struct weston_testsuite_data contains two members:
*
* 1. The struct weston_testsuite_quirks, which can be used by the tests to
* change certain behavior of Weston when running these tests.
*
* 2. The struct wet_testsuite_data member, which can be used by the test suite
* of projects that uses libweston in order to give arbitrary test data to the
* compositor.
*
* This function can be called at most once per compositor instance, just after
* creating the weston_compositor object and never again. This happens because
* changing the quirks after e.g. loading the backend is not going to work,
* there are certain behaviors that need to be set up before this point.
*
* \param ec The weston compositor.
* \param test_data The testsuite data.
*
* \ingroup compositor
* \sa weston_compositor_get_test_data
*/
WL_EXPORT void
weston_compositor_test_data_init(struct weston_compositor *ec,
const struct weston_testsuite_data *test_data)
{
assert(ec->backend == NULL);
ec->test_data = *test_data;
}
/** Retrieve testsuite data from compositor
*
* The testsuite data can be defined by the test suite of projects that uses
* libweston and given to the compositor at the moment of its creation. This
* function should be used when we need to retrieve the testsuite private data
* from the compositor.
*
* \param ec The weston compositor.
* \return The testsuite data.
*
* \ingroup compositor
* \sa weston_compositor_test_data_init
*/
WL_EXPORT void *
weston_compositor_get_test_data(struct weston_compositor *ec)
{
return ec->test_data.test_private_data;
}
/** Create the compositor. /** Create the compositor.
* *
* This functions creates and initializes a compositor instance. * This functions creates and initializes a compositor instance.

@ -175,6 +175,7 @@ compositor_setup_defaults_(struct compositor_setup *setup,
const char *testset_name) const char *testset_name)
{ {
*setup = (struct compositor_setup) { *setup = (struct compositor_setup) {
.test_quirks = (struct weston_testsuite_quirks){ },
.backend = WESTON_BACKEND_HEADLESS, .backend = WESTON_BACKEND_HEADLESS,
.renderer = RENDERER_NOOP, .renderer = RENDERER_NOOP,
.shell = SHELL_DESKTOP, .shell = SHELL_DESKTOP,
@ -276,6 +277,7 @@ int
execute_compositor(const struct compositor_setup *setup, execute_compositor(const struct compositor_setup *setup,
struct wet_testsuite_data *data) struct wet_testsuite_data *data)
{ {
struct weston_testsuite_data test_data;
struct prog_args args; struct prog_args args;
char *tmp; char *tmp;
const char *ctmp, *drm_device; const char *ctmp, *drm_device;
@ -418,9 +420,10 @@ execute_compositor(const struct compositor_setup *setup,
if (setup->xwayland) if (setup->xwayland)
prog_args_take(&args, strdup("--xwayland")); prog_args_take(&args, strdup("--xwayland"));
wet_testsuite_data_set(data); test_data.test_quirks = setup->test_quirks;
test_data.test_private_data = data;
prog_args_save(&args); prog_args_save(&args);
ret = wet_main(args.argc, args.argv); ret = wet_main(args.argc, args.argv, &test_data);
prog_args_fini(&args); prog_args_fini(&args);

@ -71,6 +71,8 @@ enum shell_type {
* \ingroup testharness * \ingroup testharness
*/ */
struct compositor_setup { struct compositor_setup {
/** The test suite quirks. */
struct weston_testsuite_quirks test_quirks;
/** The backend to use. */ /** The backend to use. */
enum weston_compositor_backend backend; enum weston_compositor_backend backend;
/** The renderer to use. */ /** The renderer to use. */

@ -750,7 +750,7 @@ static void
idle_launch_testsuite(void *test_) idle_launch_testsuite(void *test_)
{ {
struct weston_test *test = test_; struct weston_test *test = test_;
struct wet_testsuite_data *data = wet_testsuite_data_get(); struct wet_testsuite_data *data = weston_compositor_get_test_data(test->compositor);
if (!data) if (!data)
return; return;

Loading…
Cancel
Save