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