blob: afda7bc96fa5bdb3927b47ebeca104a9f444f656 [file] [log] [blame]
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -08001/*
2 * Copyright © 2012 Intel Corporation
3 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07004 * 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:
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080011 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070012 * 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.
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080024 */
25
Neil Roberts40c0c3f2013-10-29 20:13:45 +000026#include "config.h"
27
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030028#include <stdint.h>
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080029#include <stdlib.h>
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080030#include <assert.h>
31#include <signal.h>
32#include <unistd.h>
Marek Chalupac8daf772015-03-30 06:37:55 -040033#include <string.h>
Bryce Harringtona7680262014-11-19 17:18:34 -080034
Pekka Paalanenb5e3ea22016-06-03 17:12:10 +030035#include "compositor.h"
Pekka Paalanen58f98c92016-06-03 16:45:21 +030036#include "compositor/weston.h"
Derek Foremanf6a65922015-02-24 09:32:14 -060037#include "weston-test-server-protocol.h"
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080038
Neil Roberts40c0c3f2013-10-29 20:13:45 +000039#ifdef ENABLE_EGL
40#include <EGL/egl.h>
41#include <EGL/eglext.h>
Pekka Paalanenb5e3ea22016-06-03 17:12:10 +030042#include "weston-egl-ext.h"
Neil Roberts40c0c3f2013-10-29 20:13:45 +000043#endif /* ENABLE_EGL */
44
Jon Cruz867d50e2015-06-15 15:37:10 -070045#include "shared/helpers.h"
46
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080047struct weston_test {
48 struct weston_compositor *compositor;
49 struct weston_layer layer;
50 struct weston_process process;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040051 struct weston_seat seat;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080052};
53
54struct weston_test_surface {
55 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -050056 struct weston_view *view;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080057 int32_t x, y;
58 struct weston_test *test;
59};
60
61static void
62test_client_sigchld(struct weston_process *process, int status)
63{
64 struct weston_test *test =
65 container_of(process, struct weston_test, process);
66
Emilio Pozuelo Monfortdae8a4b2014-02-07 09:34:48 +010067 /* Chain up from weston-test-runner's exit code so that automake
68 * knows the exit status and can report e.g. skipped tests. */
69 if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
70 exit(WEXITSTATUS(status));
71
72 /* In case the child aborted or segfaulted... */
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080073 assert(status == 0);
74
75 wl_display_terminate(test->compositor->wl_display);
76}
77
78static struct weston_seat *
79get_seat(struct weston_test *test)
80{
Marek Chalupac3c3fc42015-03-30 09:17:40 -040081 return &test->seat;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080082}
83
84static void
85notify_pointer_position(struct weston_test *test, struct wl_resource *resource)
86{
87 struct weston_seat *seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -050088 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080089
Derek Foremanf6a65922015-02-24 09:32:14 -060090 weston_test_send_pointer_position(resource, pointer->x, pointer->y);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080091}
92
93static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -060094test_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080095{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +010096 struct weston_test_surface *test_surface = surface->configure_private;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080097 struct weston_test *test = test_surface->test;
98
Giulio Camuffo412e6a52014-07-09 22:12:56 +030099 if (wl_list_empty(&test_surface->view->layer_link.link))
100 weston_layer_entry_insert(&test->layer.view_list,
101 &test_surface->view->layer_link);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800102
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600103 weston_view_set_position(test_surface->view,
104 test_surface->x, test_surface->y);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800105
Kristian Høgsbergace0a392013-11-13 21:55:57 -0800106 weston_view_update_transform(test_surface->view);
Armin Krezovićd0cf4412016-06-30 06:04:32 +0200107
108 test_surface->surface->is_mapped = true;
109 test_surface->view->is_mapped = true;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800110}
111
112static void
113move_surface(struct wl_client *client, struct wl_resource *resource,
114 struct wl_resource *surface_resource,
115 int32_t x, int32_t y)
116{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400117 struct weston_surface *surface =
118 wl_resource_get_user_data(surface_resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800119 struct weston_test_surface *test_surface;
120
Giulio Camuffo7fe01b12013-03-28 18:02:42 +0100121 test_surface = surface->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500122 if (!test_surface) {
123 test_surface = malloc(sizeof *test_surface);
124 if (!test_surface) {
125 wl_resource_post_no_memory(resource);
126 return;
127 }
128
129 test_surface->view = weston_view_create(surface);
130 if (!test_surface->view) {
131 wl_resource_post_no_memory(resource);
132 free(test_surface);
133 return;
134 }
135
136 surface->configure_private = test_surface;
137 surface->configure = test_surface_configure;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800138 }
139
140 test_surface->surface = surface;
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400141 test_surface->test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800142 test_surface->x = x;
143 test_surface->y = y;
144}
145
146static void
147move_pointer(struct wl_client *client, struct wl_resource *resource,
148 int32_t x, int32_t y)
149{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400150 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800151 struct weston_seat *seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -0500152 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
Jonas Ådahld2510102014-10-05 21:39:14 +0200153 struct weston_pointer_motion_event event = { 0 };
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800154
Jonas Ådahld2510102014-10-05 21:39:14 +0200155 event = (struct weston_pointer_motion_event) {
156 .mask = WESTON_POINTER_MOTION_REL,
157 .dx = wl_fixed_to_double(wl_fixed_from_int(x) - pointer->x),
158 .dy = wl_fixed_to_double(wl_fixed_from_int(y) - pointer->y),
159 };
160
161 notify_motion(seat, 100, &event);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800162
163 notify_pointer_position(test, resource);
164}
165
166static void
167send_button(struct wl_client *client, struct wl_resource *resource,
168 int32_t button, uint32_t state)
169{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400170 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800171 struct weston_seat *seat = get_seat(test);
172
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800173 notify_button(seat, 100, button, state);
174}
175
176static void
177activate_surface(struct wl_client *client, struct wl_resource *resource,
178 struct wl_resource *surface_resource)
179{
180 struct weston_surface *surface = surface_resource ?
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400181 wl_resource_get_user_data(surface_resource) : NULL;
182 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800183 struct weston_seat *seat;
Derek Foreman1281a362015-07-31 16:55:32 -0500184 struct weston_keyboard *keyboard;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800185
186 seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -0500187 keyboard = weston_seat_get_keyboard(seat);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800188 if (surface) {
Bryce Harrington260c2ff2016-06-29 19:04:06 -0700189 weston_seat_set_keyboard_focus(seat, surface);
Derek Foreman1281a362015-07-31 16:55:32 -0500190 notify_keyboard_focus_in(seat, &keyboard->keys,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800191 STATE_UPDATE_AUTOMATIC);
192 }
193 else {
194 notify_keyboard_focus_out(seat);
Bryce Harrington260c2ff2016-06-29 19:04:06 -0700195 weston_seat_set_keyboard_focus(seat, surface);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800196 }
197}
198
199static void
200send_key(struct wl_client *client, struct wl_resource *resource,
201 uint32_t key, enum wl_keyboard_key_state state)
202{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400203 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800204 struct weston_seat *seat = get_seat(test);
205
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800206 notify_key(seat, 100, key, state, STATE_UPDATE_AUTOMATIC);
207}
208
Marek Chalupac8daf772015-03-30 06:37:55 -0400209static void
210device_release(struct wl_client *client,
211 struct wl_resource *resource, const char *device)
212{
213 struct weston_test *test = wl_resource_get_user_data(resource);
214 struct weston_seat *seat = get_seat(test);
215
216 if (strcmp(device, "pointer") == 0) {
217 weston_seat_release_pointer(seat);
218 } else if (strcmp(device, "keyboard") == 0) {
219 weston_seat_release_keyboard(seat);
220 } else if (strcmp(device, "touch") == 0) {
221 weston_seat_release_touch(seat);
222 } else if (strcmp(device, "seat") == 0) {
223 weston_seat_release(seat);
224 } else {
225 assert(0 && "Unsupported device");
226 }
227}
228
229static void
230device_add(struct wl_client *client,
231 struct wl_resource *resource, const char *device)
232{
233 struct weston_test *test = wl_resource_get_user_data(resource);
234 struct weston_seat *seat = get_seat(test);
235
236 if (strcmp(device, "pointer") == 0) {
237 weston_seat_init_pointer(seat);
238 } else if (strcmp(device, "keyboard") == 0) {
239 weston_seat_init_keyboard(seat, NULL);
240 } else if (strcmp(device, "touch") == 0) {
241 weston_seat_init_touch(seat);
242 } else {
243 assert(0 && "Unsupported device");
244 }
245}
246
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000247#ifdef ENABLE_EGL
248static int
249is_egl_buffer(struct wl_resource *resource)
250{
251 PFNEGLQUERYWAYLANDBUFFERWL query_buffer =
252 (void *) eglGetProcAddress("eglQueryWaylandBufferWL");
253 EGLint format;
254
255 if (query_buffer(eglGetCurrentDisplay(),
256 resource,
257 EGL_TEXTURE_FORMAT,
258 &format))
259 return 1;
260
261 return 0;
262}
263#endif /* ENABLE_EGL */
264
265static void
266get_n_buffers(struct wl_client *client, struct wl_resource *resource)
267{
268 int n_buffers = 0;
269
270#ifdef ENABLE_EGL
271 struct wl_resource *buffer_resource;
272 int i;
273
274 for (i = 0; i < 1000; i++) {
275 buffer_resource = wl_client_get_object(client, i);
276
277 if (buffer_resource == NULL)
278 continue;
279
280 if (is_egl_buffer(buffer_resource))
281 n_buffers++;
282 }
283#endif /* ENABLE_EGL */
284
Derek Foremanf6a65922015-02-24 09:32:14 -0600285 weston_test_send_n_egl_buffers(resource, n_buffers);
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000286}
287
Bryce Harringtonf280d112015-05-05 15:13:20 -0700288enum weston_test_screenshot_outcome {
289 WESTON_TEST_SCREENSHOT_SUCCESS,
290 WESTON_TEST_SCREENSHOT_NO_MEMORY,
291 WESTON_TEST_SCREENSHOT_BAD_BUFFER
292 };
293
294typedef void (*weston_test_screenshot_done_func_t)(void *data,
295 enum weston_test_screenshot_outcome outcome);
296
297struct test_screenshot {
298 struct weston_compositor *compositor;
299 struct wl_global *global;
300 struct wl_client *client;
301 struct weston_process process;
302 struct wl_listener destroy_listener;
303};
304
305struct test_screenshot_frame_listener {
306 struct wl_listener listener;
307 struct weston_buffer *buffer;
308 weston_test_screenshot_done_func_t done;
309 void *data;
310};
311
312static void
313copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
314{
315 uint8_t *end;
316
317 end = dst + height * stride;
318 while (dst < end) {
319 memcpy(dst, src, stride);
320 dst += stride;
321 src -= stride;
322 }
323}
324
325
326static void
327copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)
328{
329 /* TODO: optimize this out */
330 memcpy(dst, src, height * stride);
331}
332
333static void
334copy_row_swap_RB(void *vdst, void *vsrc, int bytes)
335{
336 uint32_t *dst = vdst;
337 uint32_t *src = vsrc;
338 uint32_t *end = dst + bytes / 4;
339
340 while (dst < end) {
341 uint32_t v = *src++;
342 /* A R G B */
343 uint32_t tmp = v & 0xff00ff00;
344 tmp |= (v >> 16) & 0x000000ff;
345 tmp |= (v << 16) & 0x00ff0000;
346 *dst++ = tmp;
347 }
348}
349
350static void
351copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
352{
353 uint8_t *end;
354
355 end = dst + height * stride;
356 while (dst < end) {
357 copy_row_swap_RB(dst, src, stride);
358 dst += stride;
359 src -= stride;
360 }
361}
362
363static void
364copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)
365{
366 uint8_t *end;
367
368 end = dst + height * stride;
369 while (dst < end) {
370 copy_row_swap_RB(dst, src, stride);
371 dst += stride;
372 src += stride;
373 }
374}
375
376static void
377test_screenshot_frame_notify(struct wl_listener *listener, void *data)
378{
379 struct test_screenshot_frame_listener *l =
380 container_of(listener,
381 struct test_screenshot_frame_listener, listener);
382 struct weston_output *output = data;
383 struct weston_compositor *compositor = output->compositor;
384 int32_t stride;
385 uint8_t *pixels, *d, *s;
386
387 output->disable_planes--;
388 wl_list_remove(&listener->link);
389 stride = l->buffer->width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
390 pixels = malloc(stride * l->buffer->height);
391
392 if (pixels == NULL) {
393 l->done(l->data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
394 free(l);
395 return;
396 }
397
Chris Michael2ec5f2a2015-12-03 12:23:12 -0500398 /* FIXME: Needs to handle output transformations */
Bryce Harringtonf280d112015-05-05 15:13:20 -0700399
400 compositor->renderer->read_pixels(output,
401 compositor->read_format,
402 pixels,
403 0, 0,
404 output->current_mode->width,
405 output->current_mode->height);
406
407 stride = wl_shm_buffer_get_stride(l->buffer->shm_buffer);
408
409 d = wl_shm_buffer_get_data(l->buffer->shm_buffer);
410 s = pixels + stride * (l->buffer->height - 1);
411
412 wl_shm_buffer_begin_access(l->buffer->shm_buffer);
413
414 /* XXX: It would be nice if we used Pixman to do all this rather
415 * than our own implementation
416 */
417 switch (compositor->read_format) {
418 case PIXMAN_a8r8g8b8:
419 case PIXMAN_x8r8g8b8:
420 if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
421 copy_bgra_yflip(d, s, output->current_mode->height, stride);
422 else
423 copy_bgra(d, pixels, output->current_mode->height, stride);
424 break;
425 case PIXMAN_x8b8g8r8:
426 case PIXMAN_a8b8g8r8:
427 if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
428 copy_rgba_yflip(d, s, output->current_mode->height, stride);
429 else
430 copy_rgba(d, pixels, output->current_mode->height, stride);
431 break;
432 default:
433 break;
434 }
435
436 wl_shm_buffer_end_access(l->buffer->shm_buffer);
437
438 l->done(l->data, WESTON_TEST_SCREENSHOT_SUCCESS);
439 free(pixels);
440 free(l);
441}
442
443static bool
444weston_test_screenshot_shoot(struct weston_output *output,
445 struct weston_buffer *buffer,
446 weston_test_screenshot_done_func_t done,
447 void *data)
448{
449 struct test_screenshot_frame_listener *l;
450
451 /* Get the shm buffer resource the client created */
452 if (!wl_shm_buffer_get(buffer->resource)) {
453 done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
454 return false;
455 }
456
457 buffer->shm_buffer = wl_shm_buffer_get(buffer->resource);
458 buffer->width = wl_shm_buffer_get_width(buffer->shm_buffer);
459 buffer->height = wl_shm_buffer_get_height(buffer->shm_buffer);
460
461 /* Verify buffer is big enough */
462 if (buffer->width < output->current_mode->width ||
463 buffer->height < output->current_mode->height) {
464 done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
465 return false;
466 }
467
468 /* allocate the frame listener */
469 l = malloc(sizeof *l);
470 if (l == NULL) {
471 done(data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
472 return false;
473 }
474
475 /* Set up the listener */
476 l->buffer = buffer;
477 l->done = done;
478 l->data = data;
479 l->listener.notify = test_screenshot_frame_notify;
480 wl_signal_add(&output->frame_signal, &l->listener);
481
482 /* Fire off a repaint */
483 output->disable_planes++;
484 weston_output_schedule_repaint(output);
485
486 return true;
487}
488
489static void
490capture_screenshot_done(void *data, enum weston_test_screenshot_outcome outcome)
491{
492 struct wl_resource *resource = data;
493
494 switch (outcome) {
495 case WESTON_TEST_SCREENSHOT_SUCCESS:
496 weston_test_send_capture_screenshot_done(resource);
497 break;
498 case WESTON_TEST_SCREENSHOT_NO_MEMORY:
499 wl_resource_post_no_memory(resource);
500 break;
501 default:
502 break;
503 }
504}
505
506
507/**
508 * Grabs a snapshot of the screen.
509 */
510static void
511capture_screenshot(struct wl_client *client,
512 struct wl_resource *resource,
513 struct wl_resource *output_resource,
514 struct wl_resource *buffer_resource)
515{
516 struct weston_output *output =
517 wl_resource_get_user_data(output_resource);
518 struct weston_buffer *buffer =
519 weston_buffer_from_resource(buffer_resource);
520
521 if (buffer == NULL) {
522 wl_resource_post_no_memory(resource);
523 return;
524 }
525
526 weston_test_screenshot_shoot(output, buffer,
527 capture_screenshot_done, resource);
528}
529
Derek Foremanf6a65922015-02-24 09:32:14 -0600530static const struct weston_test_interface test_implementation = {
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800531 move_surface,
532 move_pointer,
533 send_button,
534 activate_surface,
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000535 send_key,
Marek Chalupac8daf772015-03-30 06:37:55 -0400536 device_release,
537 device_add,
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000538 get_n_buffers,
Bryce Harringtonf280d112015-05-05 15:13:20 -0700539 capture_screenshot,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800540};
541
542static void
543bind_test(struct wl_client *client, void *data, uint32_t version, uint32_t id)
544{
545 struct weston_test *test = data;
546 struct wl_resource *resource;
547
Derek Foremanf6a65922015-02-24 09:32:14 -0600548 resource = wl_resource_create(client, &weston_test_interface, 1, id);
Marek Chalupa42ebdda2014-07-11 12:33:02 +0200549 if (!resource) {
550 wl_client_post_no_memory(client);
551 return;
552 }
553
Kristian Høgsberg442a5fa2013-07-03 18:13:33 -0400554 wl_resource_set_implementation(resource,
555 &test_implementation, test, NULL);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800556
557 notify_pointer_position(test, resource);
558}
559
560static void
561idle_launch_client(void *data)
562{
563 struct weston_test *test = data;
564 pid_t pid;
565 sigset_t allsigs;
566 char *path;
567
568 path = getenv("WESTON_TEST_CLIENT_PATH");
569 if (path == NULL)
Pekka Paalanenf72e4792013-11-21 16:23:57 +0200570 return;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800571 pid = fork();
572 if (pid == -1)
573 exit(EXIT_FAILURE);
574 if (pid == 0) {
575 sigfillset(&allsigs);
576 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
577 execl(path, path, NULL);
578 weston_log("compositor: executing '%s' failed: %m\n", path);
579 exit(EXIT_FAILURE);
580 }
581
582 test->process.pid = pid;
583 test->process.cleanup = test_client_sigchld;
584 weston_watch_process(&test->process);
585}
586
587WL_EXPORT int
Kristian Høgsbergcb4685b2013-02-20 15:37:49 -0500588module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -0700589 int *argc, char *argv[])
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800590{
591 struct weston_test *test;
592 struct wl_event_loop *loop;
593
Peter Huttererf3d62272013-08-08 11:57:05 +1000594 test = zalloc(sizeof *test);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800595 if (test == NULL)
596 return -1;
597
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800598 test->compositor = ec;
599 weston_layer_init(&test->layer, &ec->cursor_layer.link);
600
Derek Foremanf6a65922015-02-24 09:32:14 -0600601 if (wl_global_create(ec->wl_display, &weston_test_interface, 1,
Kristian Høgsberg919cddb2013-07-08 19:03:57 -0400602 test, bind_test) == NULL)
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800603 return -1;
604
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400605 /* create our own seat */
606 weston_seat_init(&test->seat, ec, "test-seat");
607
608 /* add devices */
609 weston_seat_init_pointer(&test->seat);
Pekka Paalanen315bf8c2016-06-16 12:04:53 +0300610 if (weston_seat_init_keyboard(&test->seat, NULL) < 0)
611 return -1;
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400612 weston_seat_init_touch(&test->seat);
613
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800614 loop = wl_display_get_event_loop(ec->wl_display);
615 wl_event_loop_add_idle(loop, idle_launch_client, test);
616
617 return 0;
618}