blob: 09d8b5e581176d5260203cc1fff9fda2cf054681 [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
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080028#include <stdlib.h>
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080029#include <assert.h>
30#include <signal.h>
31#include <unistd.h>
Marek Chalupac8daf772015-03-30 06:37:55 -040032#include <string.h>
Bryce Harringtona7680262014-11-19 17:18:34 -080033
Pekka Paalanenb5e3ea22016-06-03 17:12:10 +030034#include "compositor.h"
Pekka Paalanen58f98c92016-06-03 16:45:21 +030035#include "compositor/weston.h"
Derek Foremanf6a65922015-02-24 09:32:14 -060036#include "weston-test-server-protocol.h"
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080037
Neil Roberts40c0c3f2013-10-29 20:13:45 +000038#ifdef ENABLE_EGL
39#include <EGL/egl.h>
40#include <EGL/eglext.h>
Pekka Paalanenb5e3ea22016-06-03 17:12:10 +030041#include "weston-egl-ext.h"
Neil Roberts40c0c3f2013-10-29 20:13:45 +000042#endif /* ENABLE_EGL */
43
Jon Cruz867d50e2015-06-15 15:37:10 -070044#include "shared/helpers.h"
45
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080046struct weston_test {
47 struct weston_compositor *compositor;
48 struct weston_layer layer;
49 struct weston_process process;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040050 struct weston_seat seat;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080051};
52
53struct weston_test_surface {
54 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -050055 struct weston_view *view;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080056 int32_t x, y;
57 struct weston_test *test;
58};
59
60static void
61test_client_sigchld(struct weston_process *process, int status)
62{
63 struct weston_test *test =
64 container_of(process, struct weston_test, process);
65
Emilio Pozuelo Monfortdae8a4b2014-02-07 09:34:48 +010066 /* Chain up from weston-test-runner's exit code so that automake
67 * knows the exit status and can report e.g. skipped tests. */
68 if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
69 exit(WEXITSTATUS(status));
70
71 /* In case the child aborted or segfaulted... */
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080072 assert(status == 0);
73
74 wl_display_terminate(test->compositor->wl_display);
75}
76
77static struct weston_seat *
78get_seat(struct weston_test *test)
79{
Marek Chalupac3c3fc42015-03-30 09:17:40 -040080 return &test->seat;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080081}
82
83static void
84notify_pointer_position(struct weston_test *test, struct wl_resource *resource)
85{
86 struct weston_seat *seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -050087 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080088
Derek Foremanf6a65922015-02-24 09:32:14 -060089 weston_test_send_pointer_position(resource, pointer->x, pointer->y);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080090}
91
92static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -060093test_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080094{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +010095 struct weston_test_surface *test_surface = surface->configure_private;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080096 struct weston_test *test = test_surface->test;
97
Giulio Camuffo412e6a52014-07-09 22:12:56 +030098 if (wl_list_empty(&test_surface->view->layer_link.link))
99 weston_layer_entry_insert(&test->layer.view_list,
100 &test_surface->view->layer_link);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800101
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600102 weston_view_set_position(test_surface->view,
103 test_surface->x, test_surface->y);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800104
Kristian Høgsbergace0a392013-11-13 21:55:57 -0800105 weston_view_update_transform(test_surface->view);
Armin Krezovićd0cf4412016-06-30 06:04:32 +0200106
107 test_surface->surface->is_mapped = true;
108 test_surface->view->is_mapped = true;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800109}
110
111static void
112move_surface(struct wl_client *client, struct wl_resource *resource,
113 struct wl_resource *surface_resource,
114 int32_t x, int32_t y)
115{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400116 struct weston_surface *surface =
117 wl_resource_get_user_data(surface_resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800118 struct weston_test_surface *test_surface;
119
Giulio Camuffo7fe01b12013-03-28 18:02:42 +0100120 test_surface = surface->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500121 if (!test_surface) {
122 test_surface = malloc(sizeof *test_surface);
123 if (!test_surface) {
124 wl_resource_post_no_memory(resource);
125 return;
126 }
127
128 test_surface->view = weston_view_create(surface);
129 if (!test_surface->view) {
130 wl_resource_post_no_memory(resource);
131 free(test_surface);
132 return;
133 }
134
135 surface->configure_private = test_surface;
136 surface->configure = test_surface_configure;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800137 }
138
139 test_surface->surface = surface;
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400140 test_surface->test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800141 test_surface->x = x;
142 test_surface->y = y;
143}
144
145static void
146move_pointer(struct wl_client *client, struct wl_resource *resource,
147 int32_t x, int32_t y)
148{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400149 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800150 struct weston_seat *seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -0500151 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
Jonas Ådahld2510102014-10-05 21:39:14 +0200152 struct weston_pointer_motion_event event = { 0 };
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800153
Jonas Ådahld2510102014-10-05 21:39:14 +0200154 event = (struct weston_pointer_motion_event) {
155 .mask = WESTON_POINTER_MOTION_REL,
156 .dx = wl_fixed_to_double(wl_fixed_from_int(x) - pointer->x),
157 .dy = wl_fixed_to_double(wl_fixed_from_int(y) - pointer->y),
158 };
159
160 notify_motion(seat, 100, &event);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800161
162 notify_pointer_position(test, resource);
163}
164
165static void
166send_button(struct wl_client *client, struct wl_resource *resource,
167 int32_t button, uint32_t state)
168{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400169 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800170 struct weston_seat *seat = get_seat(test);
171
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800172 notify_button(seat, 100, button, state);
173}
174
175static void
176activate_surface(struct wl_client *client, struct wl_resource *resource,
177 struct wl_resource *surface_resource)
178{
179 struct weston_surface *surface = surface_resource ?
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400180 wl_resource_get_user_data(surface_resource) : NULL;
181 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800182 struct weston_seat *seat;
Derek Foreman1281a362015-07-31 16:55:32 -0500183 struct weston_keyboard *keyboard;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800184
185 seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -0500186 keyboard = weston_seat_get_keyboard(seat);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800187 if (surface) {
Bryce Harrington260c2ff2016-06-29 19:04:06 -0700188 weston_seat_set_keyboard_focus(seat, surface);
Derek Foreman1281a362015-07-31 16:55:32 -0500189 notify_keyboard_focus_in(seat, &keyboard->keys,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800190 STATE_UPDATE_AUTOMATIC);
191 }
192 else {
193 notify_keyboard_focus_out(seat);
Bryce Harrington260c2ff2016-06-29 19:04:06 -0700194 weston_seat_set_keyboard_focus(seat, surface);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800195 }
196}
197
198static void
199send_key(struct wl_client *client, struct wl_resource *resource,
200 uint32_t key, enum wl_keyboard_key_state state)
201{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400202 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800203 struct weston_seat *seat = get_seat(test);
204
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800205 notify_key(seat, 100, key, state, STATE_UPDATE_AUTOMATIC);
206}
207
Marek Chalupac8daf772015-03-30 06:37:55 -0400208static void
209device_release(struct wl_client *client,
210 struct wl_resource *resource, const char *device)
211{
212 struct weston_test *test = wl_resource_get_user_data(resource);
213 struct weston_seat *seat = get_seat(test);
214
215 if (strcmp(device, "pointer") == 0) {
216 weston_seat_release_pointer(seat);
217 } else if (strcmp(device, "keyboard") == 0) {
218 weston_seat_release_keyboard(seat);
219 } else if (strcmp(device, "touch") == 0) {
220 weston_seat_release_touch(seat);
221 } else if (strcmp(device, "seat") == 0) {
222 weston_seat_release(seat);
223 } else {
224 assert(0 && "Unsupported device");
225 }
226}
227
228static void
229device_add(struct wl_client *client,
230 struct wl_resource *resource, const char *device)
231{
232 struct weston_test *test = wl_resource_get_user_data(resource);
233 struct weston_seat *seat = get_seat(test);
234
235 if (strcmp(device, "pointer") == 0) {
236 weston_seat_init_pointer(seat);
237 } else if (strcmp(device, "keyboard") == 0) {
238 weston_seat_init_keyboard(seat, NULL);
239 } else if (strcmp(device, "touch") == 0) {
240 weston_seat_init_touch(seat);
241 } else {
242 assert(0 && "Unsupported device");
243 }
244}
245
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000246#ifdef ENABLE_EGL
247static int
248is_egl_buffer(struct wl_resource *resource)
249{
250 PFNEGLQUERYWAYLANDBUFFERWL query_buffer =
251 (void *) eglGetProcAddress("eglQueryWaylandBufferWL");
252 EGLint format;
253
254 if (query_buffer(eglGetCurrentDisplay(),
255 resource,
256 EGL_TEXTURE_FORMAT,
257 &format))
258 return 1;
259
260 return 0;
261}
262#endif /* ENABLE_EGL */
263
264static void
265get_n_buffers(struct wl_client *client, struct wl_resource *resource)
266{
267 int n_buffers = 0;
268
269#ifdef ENABLE_EGL
270 struct wl_resource *buffer_resource;
271 int i;
272
273 for (i = 0; i < 1000; i++) {
274 buffer_resource = wl_client_get_object(client, i);
275
276 if (buffer_resource == NULL)
277 continue;
278
279 if (is_egl_buffer(buffer_resource))
280 n_buffers++;
281 }
282#endif /* ENABLE_EGL */
283
Derek Foremanf6a65922015-02-24 09:32:14 -0600284 weston_test_send_n_egl_buffers(resource, n_buffers);
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000285}
286
Bryce Harringtonf280d112015-05-05 15:13:20 -0700287enum weston_test_screenshot_outcome {
288 WESTON_TEST_SCREENSHOT_SUCCESS,
289 WESTON_TEST_SCREENSHOT_NO_MEMORY,
290 WESTON_TEST_SCREENSHOT_BAD_BUFFER
291 };
292
293typedef void (*weston_test_screenshot_done_func_t)(void *data,
294 enum weston_test_screenshot_outcome outcome);
295
296struct test_screenshot {
297 struct weston_compositor *compositor;
298 struct wl_global *global;
299 struct wl_client *client;
300 struct weston_process process;
301 struct wl_listener destroy_listener;
302};
303
304struct test_screenshot_frame_listener {
305 struct wl_listener listener;
306 struct weston_buffer *buffer;
307 weston_test_screenshot_done_func_t done;
308 void *data;
309};
310
311static void
312copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
313{
314 uint8_t *end;
315
316 end = dst + height * stride;
317 while (dst < end) {
318 memcpy(dst, src, stride);
319 dst += stride;
320 src -= stride;
321 }
322}
323
324
325static void
326copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)
327{
328 /* TODO: optimize this out */
329 memcpy(dst, src, height * stride);
330}
331
332static void
333copy_row_swap_RB(void *vdst, void *vsrc, int bytes)
334{
335 uint32_t *dst = vdst;
336 uint32_t *src = vsrc;
337 uint32_t *end = dst + bytes / 4;
338
339 while (dst < end) {
340 uint32_t v = *src++;
341 /* A R G B */
342 uint32_t tmp = v & 0xff00ff00;
343 tmp |= (v >> 16) & 0x000000ff;
344 tmp |= (v << 16) & 0x00ff0000;
345 *dst++ = tmp;
346 }
347}
348
349static void
350copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
351{
352 uint8_t *end;
353
354 end = dst + height * stride;
355 while (dst < end) {
356 copy_row_swap_RB(dst, src, stride);
357 dst += stride;
358 src -= stride;
359 }
360}
361
362static void
363copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)
364{
365 uint8_t *end;
366
367 end = dst + height * stride;
368 while (dst < end) {
369 copy_row_swap_RB(dst, src, stride);
370 dst += stride;
371 src += stride;
372 }
373}
374
375static void
376test_screenshot_frame_notify(struct wl_listener *listener, void *data)
377{
378 struct test_screenshot_frame_listener *l =
379 container_of(listener,
380 struct test_screenshot_frame_listener, listener);
381 struct weston_output *output = data;
382 struct weston_compositor *compositor = output->compositor;
383 int32_t stride;
384 uint8_t *pixels, *d, *s;
385
386 output->disable_planes--;
387 wl_list_remove(&listener->link);
388 stride = l->buffer->width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
389 pixels = malloc(stride * l->buffer->height);
390
391 if (pixels == NULL) {
392 l->done(l->data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
393 free(l);
394 return;
395 }
396
Chris Michael2ec5f2a2015-12-03 12:23:12 -0500397 /* FIXME: Needs to handle output transformations */
Bryce Harringtonf280d112015-05-05 15:13:20 -0700398
399 compositor->renderer->read_pixels(output,
400 compositor->read_format,
401 pixels,
402 0, 0,
403 output->current_mode->width,
404 output->current_mode->height);
405
406 stride = wl_shm_buffer_get_stride(l->buffer->shm_buffer);
407
408 d = wl_shm_buffer_get_data(l->buffer->shm_buffer);
409 s = pixels + stride * (l->buffer->height - 1);
410
411 wl_shm_buffer_begin_access(l->buffer->shm_buffer);
412
413 /* XXX: It would be nice if we used Pixman to do all this rather
414 * than our own implementation
415 */
416 switch (compositor->read_format) {
417 case PIXMAN_a8r8g8b8:
418 case PIXMAN_x8r8g8b8:
419 if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
420 copy_bgra_yflip(d, s, output->current_mode->height, stride);
421 else
422 copy_bgra(d, pixels, output->current_mode->height, stride);
423 break;
424 case PIXMAN_x8b8g8r8:
425 case PIXMAN_a8b8g8r8:
426 if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
427 copy_rgba_yflip(d, s, output->current_mode->height, stride);
428 else
429 copy_rgba(d, pixels, output->current_mode->height, stride);
430 break;
431 default:
432 break;
433 }
434
435 wl_shm_buffer_end_access(l->buffer->shm_buffer);
436
437 l->done(l->data, WESTON_TEST_SCREENSHOT_SUCCESS);
438 free(pixels);
439 free(l);
440}
441
442static bool
443weston_test_screenshot_shoot(struct weston_output *output,
444 struct weston_buffer *buffer,
445 weston_test_screenshot_done_func_t done,
446 void *data)
447{
448 struct test_screenshot_frame_listener *l;
449
450 /* Get the shm buffer resource the client created */
451 if (!wl_shm_buffer_get(buffer->resource)) {
452 done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
453 return false;
454 }
455
456 buffer->shm_buffer = wl_shm_buffer_get(buffer->resource);
457 buffer->width = wl_shm_buffer_get_width(buffer->shm_buffer);
458 buffer->height = wl_shm_buffer_get_height(buffer->shm_buffer);
459
460 /* Verify buffer is big enough */
461 if (buffer->width < output->current_mode->width ||
462 buffer->height < output->current_mode->height) {
463 done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
464 return false;
465 }
466
467 /* allocate the frame listener */
468 l = malloc(sizeof *l);
469 if (l == NULL) {
470 done(data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
471 return false;
472 }
473
474 /* Set up the listener */
475 l->buffer = buffer;
476 l->done = done;
477 l->data = data;
478 l->listener.notify = test_screenshot_frame_notify;
479 wl_signal_add(&output->frame_signal, &l->listener);
480
481 /* Fire off a repaint */
482 output->disable_planes++;
483 weston_output_schedule_repaint(output);
484
485 return true;
486}
487
488static void
489capture_screenshot_done(void *data, enum weston_test_screenshot_outcome outcome)
490{
491 struct wl_resource *resource = data;
492
493 switch (outcome) {
494 case WESTON_TEST_SCREENSHOT_SUCCESS:
495 weston_test_send_capture_screenshot_done(resource);
496 break;
497 case WESTON_TEST_SCREENSHOT_NO_MEMORY:
498 wl_resource_post_no_memory(resource);
499 break;
500 default:
501 break;
502 }
503}
504
505
506/**
507 * Grabs a snapshot of the screen.
508 */
509static void
510capture_screenshot(struct wl_client *client,
511 struct wl_resource *resource,
512 struct wl_resource *output_resource,
513 struct wl_resource *buffer_resource)
514{
515 struct weston_output *output =
516 wl_resource_get_user_data(output_resource);
517 struct weston_buffer *buffer =
518 weston_buffer_from_resource(buffer_resource);
519
520 if (buffer == NULL) {
521 wl_resource_post_no_memory(resource);
522 return;
523 }
524
525 weston_test_screenshot_shoot(output, buffer,
526 capture_screenshot_done, resource);
527}
528
Derek Foremanf6a65922015-02-24 09:32:14 -0600529static const struct weston_test_interface test_implementation = {
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800530 move_surface,
531 move_pointer,
532 send_button,
533 activate_surface,
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000534 send_key,
Marek Chalupac8daf772015-03-30 06:37:55 -0400535 device_release,
536 device_add,
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000537 get_n_buffers,
Bryce Harringtonf280d112015-05-05 15:13:20 -0700538 capture_screenshot,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800539};
540
541static void
542bind_test(struct wl_client *client, void *data, uint32_t version, uint32_t id)
543{
544 struct weston_test *test = data;
545 struct wl_resource *resource;
546
Derek Foremanf6a65922015-02-24 09:32:14 -0600547 resource = wl_resource_create(client, &weston_test_interface, 1, id);
Marek Chalupa42ebdda2014-07-11 12:33:02 +0200548 if (!resource) {
549 wl_client_post_no_memory(client);
550 return;
551 }
552
Kristian Høgsberg442a5fa2013-07-03 18:13:33 -0400553 wl_resource_set_implementation(resource,
554 &test_implementation, test, NULL);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800555
556 notify_pointer_position(test, resource);
557}
558
559static void
560idle_launch_client(void *data)
561{
562 struct weston_test *test = data;
563 pid_t pid;
564 sigset_t allsigs;
565 char *path;
566
567 path = getenv("WESTON_TEST_CLIENT_PATH");
568 if (path == NULL)
Pekka Paalanenf72e4792013-11-21 16:23:57 +0200569 return;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800570 pid = fork();
571 if (pid == -1)
572 exit(EXIT_FAILURE);
573 if (pid == 0) {
574 sigfillset(&allsigs);
575 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
576 execl(path, path, NULL);
577 weston_log("compositor: executing '%s' failed: %m\n", path);
578 exit(EXIT_FAILURE);
579 }
580
581 test->process.pid = pid;
582 test->process.cleanup = test_client_sigchld;
583 weston_watch_process(&test->process);
584}
585
586WL_EXPORT int
Kristian Høgsbergcb4685b2013-02-20 15:37:49 -0500587module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -0700588 int *argc, char *argv[])
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800589{
590 struct weston_test *test;
591 struct wl_event_loop *loop;
592
Peter Huttererf3d62272013-08-08 11:57:05 +1000593 test = zalloc(sizeof *test);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800594 if (test == NULL)
595 return -1;
596
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800597 test->compositor = ec;
598 weston_layer_init(&test->layer, &ec->cursor_layer.link);
599
Derek Foremanf6a65922015-02-24 09:32:14 -0600600 if (wl_global_create(ec->wl_display, &weston_test_interface, 1,
Kristian Høgsberg919cddb2013-07-08 19:03:57 -0400601 test, bind_test) == NULL)
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800602 return -1;
603
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400604 /* create our own seat */
605 weston_seat_init(&test->seat, ec, "test-seat");
606
607 /* add devices */
608 weston_seat_init_pointer(&test->seat);
Pekka Paalanen315bf8c2016-06-16 12:04:53 +0300609 if (weston_seat_init_keyboard(&test->seat, NULL) < 0)
610 return -1;
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400611 weston_seat_init_touch(&test->seat);
612
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800613 loop = wl_display_get_event_loop(ec->wl_display);
614 wl_event_loop_add_idle(loop, idle_launch_client, test);
615
616 return 0;
617}