blob: 04c06409bb54a293b66fce0ec16454e1791d30da [file] [log] [blame]
Pekka Paalanenbabb3b32019-11-01 14:02:15 +02001/*
2 * Copyright 2019 Collabora, Ltd.
3 *
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:
11 *
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.
15 *
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
23 * SOFTWARE.
24 */
25
26#include "config.h"
27
28#include <string.h>
29#include <assert.h>
30
31#include "shared/helpers.h"
32#include "weston-test-fixture-compositor.h"
33#include "weston.h"
34
35struct prog_args {
36 int argc;
37 char **argv;
38 char **saved;
39 int alloc;
40};
41
42static void
43prog_args_init(struct prog_args *p)
44{
45 memset(p, 0, sizeof(*p));
46}
47
48static void
49prog_args_take(struct prog_args *p, char *arg)
50{
51 assert(arg);
52
53 if (p->argc == p->alloc) {
54 p->alloc += 10;
55 p->argv = realloc(p->argv, sizeof(char *) * p->alloc);
56 assert(p->argv);
57 }
58
59 p->argv[p->argc++] = arg;
60}
61
62/*
63 * The program to be executed will trample on argv, hence we need a copy to
64 * be able to free all our args.
65 */
66static void
67prog_args_save(struct prog_args *p)
68{
69 assert(p->saved == NULL);
70
71 p->saved = calloc(p->argc, sizeof(char *));
72 assert(p->saved);
73
74 memcpy(p->saved, p->argv, sizeof(char *) * p->argc);
75}
76
77static void
78prog_args_fini(struct prog_args *p)
79{
80 int i;
81
82 assert(p->saved);
83
84 for (i = 0; i < p->argc; i++)
85 free(p->saved[i]);
86 free(p->saved);
87 free(p->argv);
88 prog_args_init(p);
89}
90
91/** Initialize part of compositor setup
92 *
93 * \param setup The variable to initialize.
94 * \param testset_name Value for testset_name member.
95 *
96 * \ingroup testharness_private
97 */
98void
99compositor_setup_defaults_(struct compositor_setup *setup,
100 const char *testset_name)
101{
102 *setup = (struct compositor_setup) {
103 .backend = WESTON_BACKEND_HEADLESS,
104 .renderer = RENDERER_NOOP,
105 .shell = SHELL_DESKTOP,
106 .xwayland = false,
107 .width = 320,
108 .height = 240,
109 .config_file = NULL,
110 .extra_module = NULL,
111 .logging_scopes = NULL,
112 .testset_name = testset_name,
113 };
114}
115
116static const char *
117backend_to_str(enum weston_compositor_backend b)
118{
119 static const char * const names[] = {
120 [WESTON_BACKEND_DRM] = "drm-backend.so",
121 [WESTON_BACKEND_FBDEV] = "fbdev-backend.so",
122 [WESTON_BACKEND_HEADLESS] = "headless-backend.so",
123 [WESTON_BACKEND_RDP] = "rdp-backend.so",
124 [WESTON_BACKEND_WAYLAND] = "wayland-backend.so",
125 [WESTON_BACKEND_X11] = "X11-backend.so",
126 };
127 assert(b >= 0 && b < ARRAY_LENGTH(names));
128 return names[b];
129}
130
131static const char *
132renderer_to_arg(enum weston_compositor_backend b, enum renderer_type r)
133{
134 static const char * const headless_names[] = {
135 [RENDERER_NOOP] = NULL,
136 [RENDERER_PIXMAN] = "--use-pixman",
137 [RENDERER_GL] = "--use-gl",
138 };
139
140 assert(r >= 0 && r < ARRAY_LENGTH(headless_names));
141
142 switch (b) {
143 case WESTON_BACKEND_HEADLESS:
144 return headless_names[r];
145 default:
146 assert(0 && "renderer_to_str() does not know the backend");
147 }
148
149 return NULL;
150}
151
152static const char *
153shell_to_str(enum shell_type t)
154{
155 static const char * const names[] = {
156 [SHELL_TEST_DESKTOP] = "weston-test-desktop-shell.so",
157 [SHELL_DESKTOP] = "desktop-shell.so",
158 [SHELL_FULLSCREEN] = "fullscreen-shell.so",
159 [SHELL_IVI] = "ivi-shell.so",
160 };
161 assert(t >= 0 && t < ARRAY_LENGTH(names));
162 return names[t];
163}
164
165/** Execute compositor
166 *
167 * Manufactures the compositor command line and calls wet_main().
168 *
169 * Returns RESULT_SKIP if the given setup contains features that were disabled
170 * in the build, e.g. GL-renderer or DRM-backend.
171 *
172 * \ingroup testharness_private
173 */
174int
175execute_compositor(const struct compositor_setup *setup,
176 struct wet_testsuite_data *data)
177{
178 struct prog_args args;
179 char *tmp;
180 const char *ctmp;
181 int ret;
182
183#ifndef BUILD_DRM_COMPOSITOR
184 if (setup->backend == WESTON_BACKEND_DRM) {
185 fprintf(stderr, "DRM-backend required but not built, skipping.\n");
186 return RESULT_SKIP;
187 }
188#endif
189
190#ifndef BUILD_FBDEV_COMPOSITOR
191 if (setup->backend == WESTON_BACKEND_FBDEV) {
192 fprintf(stderr, "fbdev-backend required but not built, skipping.\n");
193 return RESULT_SKIP;
194 }
195#endif
196
197#ifndef BUILD_RDP_COMPOSITOR
198 if (setup->backend == WESTON_BACKEND_RDP) {
199 fprintf(stderr, "RDP-backend required but not built, skipping.\n");
200 return RESULT_SKIP;
201 }
202#endif
203
204#ifndef BUILD_WAYLAND_COMPOSITOR
205 if (setup->backend == WESTON_BACKEND_WAYLAND) {
206 fprintf(stderr, "wayland-backend required but not built, skipping.\n");
207 return RESULT_SKIP;
208 }
209#endif
210
211#ifndef BUILD_X11_COMPOSITOR
212 if (setup->backend == WESTON_BACKEND_X11) {
213 fprintf(stderr, "X11-backend required but not built, skipping.\n");
214 return RESULT_SKIP;
215 }
216#endif
217
218#ifndef ENABLE_EGL
219 if (setup->renderer == RENDERER_GL) {
220 fprintf(stderr, "GL-renderer required but not built, skipping.\n");
221 return RESULT_SKIP;
222 }
223#endif
224
225 prog_args_init(&args);
226
227 /* argv[0] */
228 asprintf(&tmp, "weston-%s", setup->testset_name);
229 prog_args_take(&args, tmp);
230
231 asprintf(&tmp, "--backend=%s", backend_to_str(setup->backend));
232 prog_args_take(&args, tmp);
233
234 asprintf(&tmp, "--socket=%s", setup->testset_name);
235 prog_args_take(&args, tmp);
236
237 asprintf(&tmp, "--modules=%s%s%s", TESTSUITE_PLUGIN_PATH,
238 setup->extra_module ? "," : "",
239 setup->extra_module ? setup->extra_module : "");
240 prog_args_take(&args, tmp);
241
242 asprintf(&tmp, "--width=%d", setup->width);
243 prog_args_take(&args, tmp);
244
245 asprintf(&tmp, "--height=%d", setup->height);
246 prog_args_take(&args, tmp);
247
248 if (setup->config_file) {
249 asprintf(&tmp, "--config=%s", setup->config_file);
250 prog_args_take(&args, tmp);
251 } else {
252 prog_args_take(&args, strdup("--no-config"));
253 }
254
255 ctmp = renderer_to_arg(setup->backend, setup->renderer);
256 if (ctmp)
257 prog_args_take(&args, strdup(ctmp));
258
259 asprintf(&tmp, "--shell=%s", shell_to_str(setup->shell));
260 prog_args_take(&args, tmp);
261
262 if (setup->logging_scopes) {
263 asprintf(&tmp, "--logger-scopes=%s", setup->logging_scopes);
264 prog_args_take(&args, tmp);
265 }
266
267 if (setup->xwayland)
268 prog_args_take(&args, strdup("--xwayland"));
269
270 wet_testsuite_data_set(data);
271 prog_args_save(&args);
272 ret = wet_main(args.argc, args.argv);
273
274 prog_args_fini(&args);
275
276 return ret;
277}