diff --git a/compositor/executable.c b/compositor/executable.c index 0644077a..e4635194 100644 --- a/compositor/executable.c +++ b/compositor/executable.c @@ -30,5 +30,5 @@ int main(int argc, char *argv[]) { - return wet_main(argc, argv); + return wet_main(argc, argv, NULL); } diff --git a/compositor/main.c b/compositor/main.c index cf3df8bc..e7247c94 100644 --- a/compositor/main.c +++ b/compositor/main.c @@ -3119,7 +3119,7 @@ weston_log_subscribe_to_scopes(struct weston_log_context *log_ctx, } 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; char *cmdline; @@ -3289,6 +3289,9 @@ wet_main(int argc, char *argv[]) goto out; } + if (test_data) + weston_compositor_test_data_init(wet.compositor, test_data); + protocol_scope = weston_log_ctx_add_log_scope(log_ctx, "proto", "Wayland protocol dump for all clients.\n", diff --git a/compositor/meson.build b/compositor/meson.build index 9dc95f3f..4e9a2e27 100644 --- a/compositor/meson.build +++ b/compositor/meson.build @@ -1,7 +1,6 @@ srcs_weston = [ git_version_h, 'main.c', - 'testsuite-util.c', 'text-backend.c', 'weston-screenshooter.c', text_input_unstable_v1_server_protocol_h, diff --git a/compositor/testsuite-util.c b/compositor/testsuite-util.c deleted file mode 100644 index 34882d1f..00000000 --- a/compositor/testsuite-util.c +++ /dev/null @@ -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 -#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; -} diff --git a/compositor/weston.h b/compositor/weston.h index e09397f9..aadb80b5 100644 --- a/compositor/weston.h +++ b/compositor/weston.h @@ -96,7 +96,7 @@ void text_backend_destroy(struct text_backend *text_backend); int -wet_main(int argc, char *argv[]); +wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data); /* test suite utilities */ @@ -104,12 +104,6 @@ wet_main(int argc, char *argv[]); /** Opaque type for a test suite to define. */ 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 } #endif diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index d036c5bb..6a900ef1 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -185,6 +185,27 @@ enum weston_hdcp_protection { 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 * * \rst @@ -1105,6 +1126,9 @@ struct weston_compositor { /* Whether to let the compositor run without any input device. */ bool require_input; + /* Test suite data */ + struct weston_testsuite_data test_data; + /* Signal for a backend to inform a frontend about possible changes * in head status. */ @@ -1776,6 +1800,12 @@ struct weston_compositor * weston_compositor_create(struct wl_display *display, 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 weston_compositor_add_destroy_listener_once(struct weston_compositor *compositor, struct wl_listener *listener, diff --git a/libweston/compositor.c b/libweston/compositor.c index d288b23a..9e91cdf8 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -7327,6 +7327,55 @@ debug_scene_graph_cb(struct weston_log_subscription *sub, void *data) 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. * * This functions creates and initializes a compositor instance. diff --git a/tests/weston-test-fixture-compositor.c b/tests/weston-test-fixture-compositor.c index c1eb26c4..693c39da 100644 --- a/tests/weston-test-fixture-compositor.c +++ b/tests/weston-test-fixture-compositor.c @@ -175,6 +175,7 @@ compositor_setup_defaults_(struct compositor_setup *setup, const char *testset_name) { *setup = (struct compositor_setup) { + .test_quirks = (struct weston_testsuite_quirks){ }, .backend = WESTON_BACKEND_HEADLESS, .renderer = RENDERER_NOOP, .shell = SHELL_DESKTOP, @@ -276,6 +277,7 @@ int execute_compositor(const struct compositor_setup *setup, struct wet_testsuite_data *data) { + struct weston_testsuite_data test_data; struct prog_args args; char *tmp; const char *ctmp, *drm_device; @@ -418,9 +420,10 @@ execute_compositor(const struct compositor_setup *setup, if (setup->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); - ret = wet_main(args.argc, args.argv); + ret = wet_main(args.argc, args.argv, &test_data); prog_args_fini(&args); diff --git a/tests/weston-test-fixture-compositor.h b/tests/weston-test-fixture-compositor.h index a9d440d7..89869bba 100644 --- a/tests/weston-test-fixture-compositor.h +++ b/tests/weston-test-fixture-compositor.h @@ -71,6 +71,8 @@ enum shell_type { * \ingroup testharness */ struct compositor_setup { + /** The test suite quirks. */ + struct weston_testsuite_quirks test_quirks; /** The backend to use. */ enum weston_compositor_backend backend; /** The renderer to use. */ diff --git a/tests/weston-test.c b/tests/weston-test.c index e3a0cb66..ce4dcf29 100644 --- a/tests/weston-test.c +++ b/tests/weston-test.c @@ -750,7 +750,7 @@ static void idle_launch_testsuite(void *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) return;