2 * Copyright 2019 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include "shared/helpers.h"
36 #include "weston-test-fixture-compositor.h"
37 #include <weston/weston.h>
38 #include "test-config.h"
48 prog_args_init(struct prog_args *p)
50 memset(p, 0, sizeof(*p));
54 prog_args_take(struct prog_args *p, char *arg)
58 if (p->argc == p->alloc) {
60 p->argv = realloc(p->argv, sizeof(char *) * p->alloc);
64 p->argv[p->argc++] = arg;
68 * The program to be executed will trample on argv, hence we need a copy to
69 * be able to free all our args.
72 prog_args_save(struct prog_args *p)
74 assert(p->saved == NULL);
76 p->saved = calloc(p->argc, sizeof(char *));
79 memcpy(p->saved, p->argv, sizeof(char *) * p->argc);
83 prog_args_fini(struct prog_args *p)
89 for (i = 0; i < p->argc; i++)
99 const char *env_path, *suffix;
102 suffix = "weston-test-suite-drm-lock";
103 env_path = getenv("XDG_RUNTIME_DIR");
105 fprintf(stderr, "Failed to compute lock file path. " \
106 "XDG_RUNTIME_DIR is not set.\n");
110 if (asprintf(&lock_path, "%s/%s", env_path, suffix) == -1)
117 * DRM-backend tests need to be run sequentially, since there can only be
118 * one user at a time with master status in a DRM KMS device. Since the
119 * test suite runs the tests in parallel, there's a mechanism to assure
120 * only one DRM-backend test is running at a time: tests of this type keep
121 * waiting until they acquire a lock (which is hold until they end).
123 * Returns -1 in failure and fd in success.
131 lock_path = get_lock_path();
135 fd = open(lock_path, O_RDWR | O_CLOEXEC | O_CREAT, 00700);
137 fprintf(stderr, "Could not open lock file %s: %s\n", lock_path, strerror(errno));
140 fprintf(stderr, "Waiting for lock on %s...\n", lock_path);
142 /* The call is blocking, so we don't need a 'while'. Also, as we
143 * have a timeout for each test, this won't get stuck waiting. */
144 if (flock(fd, LOCK_EX) == -1) {
145 fprintf(stderr, "Could not lock %s: %s\n", lock_path, strerror(errno));
148 fprintf(stderr, "Lock %s acquired.\n", lock_path);
161 /** Initialize part of compositor setup
163 * \param setup The variable to initialize.
164 * \param testset_name Value for testset_name member.
166 * \ingroup testharness_private
169 compositor_setup_defaults_(struct compositor_setup *setup,
170 const char *testset_name)
172 *setup = (struct compositor_setup) {
173 .test_quirks = (struct weston_testsuite_quirks){ },
174 .backend = WESTON_BACKEND_HEADLESS,
175 .renderer = RENDERER_NOOP,
176 .shell = SHELL_DESKTOP,
181 .transform = WL_OUTPUT_TRANSFORM_NORMAL,
183 .extra_module = NULL,
184 .logging_scopes = NULL,
185 .testset_name = testset_name,
190 backend_to_str(enum weston_compositor_backend b)
192 static const char * const names[] = {
193 [WESTON_BACKEND_DRM] = "drm-backend.so",
194 [WESTON_BACKEND_FBDEV] = "fbdev-backend.so",
195 [WESTON_BACKEND_HEADLESS] = "headless-backend.so",
196 [WESTON_BACKEND_RDP] = "rdp-backend.so",
197 [WESTON_BACKEND_WAYLAND] = "wayland-backend.so",
198 [WESTON_BACKEND_X11] = "X11-backend.so",
200 assert(b >= 0 && b < ARRAY_LENGTH(names));
205 renderer_to_arg(enum weston_compositor_backend b, enum renderer_type r)
207 static const char * const headless_names[] = {
208 [RENDERER_NOOP] = NULL,
209 [RENDERER_PIXMAN] = "--use-pixman",
210 [RENDERER_GL] = "--use-gl",
212 static const char * const drm_names[] = {
213 [RENDERER_PIXMAN] = "--use-pixman",
214 [RENDERER_GL] = NULL,
218 case WESTON_BACKEND_HEADLESS:
219 assert(r >= RENDERER_NOOP && r <= RENDERER_GL);
220 return headless_names[r];
221 case WESTON_BACKEND_DRM:
222 assert(r >= RENDERER_PIXMAN && r <= RENDERER_GL);
225 assert(0 && "renderer_to_str() does not know the backend");
232 shell_to_str(enum shell_type t)
234 static const char * const names[] = {
235 [SHELL_TEST_DESKTOP] = "weston-test-desktop-shell.so",
236 [SHELL_DESKTOP] = "desktop-shell.so",
237 [SHELL_FULLSCREEN] = "fullscreen-shell.so",
238 [SHELL_IVI] = "ivi-shell.so",
240 assert(t >= 0 && t < ARRAY_LENGTH(names));
245 transform_to_str(enum wl_output_transform t)
247 static const char * const names[] = {
248 [WL_OUTPUT_TRANSFORM_NORMAL] = "normal",
249 [WL_OUTPUT_TRANSFORM_90] = "rotate-90",
250 [WL_OUTPUT_TRANSFORM_180] = "rotate-180",
251 [WL_OUTPUT_TRANSFORM_270] = "rotate-270",
252 [WL_OUTPUT_TRANSFORM_FLIPPED] = "flipped",
253 [WL_OUTPUT_TRANSFORM_FLIPPED_90] = "flipped-rotate-90",
254 [WL_OUTPUT_TRANSFORM_FLIPPED_180] = "flipped-rotate-180",
255 [WL_OUTPUT_TRANSFORM_FLIPPED_270] = "flipped-rotate-270",
258 assert(t < ARRAY_LENGTH(names) && names[t]);
262 /** Execute compositor
264 * Manufactures the compositor command line and calls wet_main().
266 * Returns RESULT_SKIP if the given setup contains features that were disabled
267 * in the build, e.g. GL-renderer or DRM-backend.
269 * \ingroup testharness_private
272 execute_compositor(const struct compositor_setup *setup,
273 struct wet_testsuite_data *data)
275 struct weston_testsuite_data test_data;
276 struct prog_args args;
278 const char *ctmp, *drm_device;
279 int ret, lock_fd = -1;
281 if (setenv("WESTON_MODULE_MAP", WESTON_MODULE_MAP, 0) < 0 ||
282 setenv("WESTON_DATA_DIR", WESTON_DATA_DIR, 0) < 0) {
283 fprintf(stderr, "Error: environment setup failed.\n");
284 return RESULT_HARD_ERROR;
287 #ifndef BUILD_DRM_COMPOSITOR
288 if (setup->backend == WESTON_BACKEND_DRM) {
289 fprintf(stderr, "DRM-backend required but not built, skipping.\n");
294 #ifndef BUILD_FBDEV_COMPOSITOR
295 if (setup->backend == WESTON_BACKEND_FBDEV) {
296 fprintf(stderr, "fbdev-backend required but not built, skipping.\n");
301 #ifndef BUILD_RDP_COMPOSITOR
302 if (setup->backend == WESTON_BACKEND_RDP) {
303 fprintf(stderr, "RDP-backend required but not built, skipping.\n");
308 #ifndef BUILD_WAYLAND_COMPOSITOR
309 if (setup->backend == WESTON_BACKEND_WAYLAND) {
310 fprintf(stderr, "wayland-backend required but not built, skipping.\n");
315 #ifndef BUILD_X11_COMPOSITOR
316 if (setup->backend == WESTON_BACKEND_X11) {
317 fprintf(stderr, "X11-backend required but not built, skipping.\n");
323 if (setup->renderer == RENDERER_GL) {
324 fprintf(stderr, "GL-renderer required but not built, skipping.\n");
329 #if !TEST_GL_RENDERER
330 if (setup->renderer == RENDERER_GL) {
331 fprintf(stderr, "GL-renderer disabled for tests, skipping.\n");
336 prog_args_init(&args);
339 asprintf(&tmp, "weston-%s", setup->testset_name);
340 prog_args_take(&args, tmp);
342 asprintf(&tmp, "--backend=%s", backend_to_str(setup->backend));
343 prog_args_take(&args, tmp);
345 if (setup->backend == WESTON_BACKEND_DRM) {
347 drm_device = getenv("WESTON_TEST_SUITE_DRM_DEVICE");
349 fprintf(stderr, "Skipping DRM-backend tests because " \
350 "WESTON_TEST_SUITE_DRM_DEVICE is not set. " \
351 "See test suite documentation to learn how " \
355 asprintf(&tmp, "--drm-device=%s", drm_device);
356 prog_args_take(&args, tmp);
358 prog_args_take(&args, strdup("--seat=weston-test-seat"));
360 prog_args_take(&args, strdup("--continue-without-input"));
362 lock_fd = wait_for_lock();
367 asprintf(&tmp, "--socket=%s", setup->testset_name);
368 prog_args_take(&args, tmp);
370 asprintf(&tmp, "--modules=%s%s%s", TESTSUITE_PLUGIN_PATH,
371 setup->extra_module ? "," : "",
372 setup->extra_module ? setup->extra_module : "");
373 prog_args_take(&args, tmp);
375 if (setup->backend != WESTON_BACKEND_DRM &&
376 setup->backend != WESTON_BACKEND_FBDEV) {
377 asprintf(&tmp, "--width=%d", setup->width);
378 prog_args_take(&args, tmp);
380 asprintf(&tmp, "--height=%d", setup->height);
381 prog_args_take(&args, tmp);
384 if (setup->scale != 1) {
385 asprintf(&tmp, "--scale=%d", setup->scale);
386 prog_args_take(&args, tmp);
389 if (setup->transform != WL_OUTPUT_TRANSFORM_NORMAL) {
390 asprintf(&tmp, "--transform=%s",
391 transform_to_str(setup->transform));
392 prog_args_take(&args, tmp);
395 if (setup->config_file) {
396 asprintf(&tmp, "--config=%s", setup->config_file);
397 prog_args_take(&args, tmp);
399 prog_args_take(&args, strdup("--no-config"));
402 ctmp = renderer_to_arg(setup->backend, setup->renderer);
404 prog_args_take(&args, strdup(ctmp));
406 asprintf(&tmp, "--shell=%s", shell_to_str(setup->shell));
407 prog_args_take(&args, tmp);
409 if (setup->logging_scopes) {
410 asprintf(&tmp, "--logger-scopes=%s", setup->logging_scopes);
411 prog_args_take(&args, tmp);
415 prog_args_take(&args, strdup("--xwayland"));
417 test_data.test_quirks = setup->test_quirks;
418 test_data.test_private_data = data;
419 prog_args_save(&args);
420 ret = wet_main(args.argc, args.argv, &test_data);
422 prog_args_fini(&args);
424 /* We acquired a lock (if this is a DRM-backend test) and now we can
425 * close its fd and release it, as it has already been run. */