blob: 27d045d9f56ba8ef0617d1f7f8d476c2693bf1d2 [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);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800106}
107
108static void
109move_surface(struct wl_client *client, struct wl_resource *resource,
110 struct wl_resource *surface_resource,
111 int32_t x, int32_t y)
112{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400113 struct weston_surface *surface =
114 wl_resource_get_user_data(surface_resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800115 struct weston_test_surface *test_surface;
116
Giulio Camuffo7fe01b12013-03-28 18:02:42 +0100117 test_surface = surface->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500118 if (!test_surface) {
119 test_surface = malloc(sizeof *test_surface);
120 if (!test_surface) {
121 wl_resource_post_no_memory(resource);
122 return;
123 }
124
125 test_surface->view = weston_view_create(surface);
126 if (!test_surface->view) {
127 wl_resource_post_no_memory(resource);
128 free(test_surface);
129 return;
130 }
131
132 surface->configure_private = test_surface;
133 surface->configure = test_surface_configure;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800134 }
135
136 test_surface->surface = surface;
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400137 test_surface->test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800138 test_surface->x = x;
139 test_surface->y = y;
140}
141
142static void
143move_pointer(struct wl_client *client, struct wl_resource *resource,
144 int32_t x, int32_t y)
145{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400146 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800147 struct weston_seat *seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -0500148 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
Jonas Ådahld2510102014-10-05 21:39:14 +0200149 struct weston_pointer_motion_event event = { 0 };
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800150
Jonas Ådahld2510102014-10-05 21:39:14 +0200151 event = (struct weston_pointer_motion_event) {
152 .mask = WESTON_POINTER_MOTION_REL,
153 .dx = wl_fixed_to_double(wl_fixed_from_int(x) - pointer->x),
154 .dy = wl_fixed_to_double(wl_fixed_from_int(y) - pointer->y),
155 };
156
157 notify_motion(seat, 100, &event);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800158
159 notify_pointer_position(test, resource);
160}
161
162static void
163send_button(struct wl_client *client, struct wl_resource *resource,
164 int32_t button, uint32_t state)
165{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400166 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800167 struct weston_seat *seat = get_seat(test);
168
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800169 notify_button(seat, 100, button, state);
170}
171
172static void
173activate_surface(struct wl_client *client, struct wl_resource *resource,
174 struct wl_resource *surface_resource)
175{
176 struct weston_surface *surface = surface_resource ?
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400177 wl_resource_get_user_data(surface_resource) : NULL;
178 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800179 struct weston_seat *seat;
Derek Foreman1281a362015-07-31 16:55:32 -0500180 struct weston_keyboard *keyboard;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800181
182 seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -0500183 keyboard = weston_seat_get_keyboard(seat);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800184 if (surface) {
Bryce Harrington260c2ff2016-06-29 19:04:06 -0700185 weston_seat_set_keyboard_focus(seat, surface);
Derek Foreman1281a362015-07-31 16:55:32 -0500186 notify_keyboard_focus_in(seat, &keyboard->keys,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800187 STATE_UPDATE_AUTOMATIC);
188 }
189 else {
190 notify_keyboard_focus_out(seat);
Bryce Harrington260c2ff2016-06-29 19:04:06 -0700191 weston_seat_set_keyboard_focus(seat, surface);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800192 }
193}
194
195static void
196send_key(struct wl_client *client, struct wl_resource *resource,
197 uint32_t key, enum wl_keyboard_key_state state)
198{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400199 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800200 struct weston_seat *seat = get_seat(test);
201
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800202 notify_key(seat, 100, key, state, STATE_UPDATE_AUTOMATIC);
203}
204
Marek Chalupac8daf772015-03-30 06:37:55 -0400205static void
206device_release(struct wl_client *client,
207 struct wl_resource *resource, const char *device)
208{
209 struct weston_test *test = wl_resource_get_user_data(resource);
210 struct weston_seat *seat = get_seat(test);
211
212 if (strcmp(device, "pointer") == 0) {
213 weston_seat_release_pointer(seat);
214 } else if (strcmp(device, "keyboard") == 0) {
215 weston_seat_release_keyboard(seat);
216 } else if (strcmp(device, "touch") == 0) {
217 weston_seat_release_touch(seat);
218 } else if (strcmp(device, "seat") == 0) {
219 weston_seat_release(seat);
220 } else {
221 assert(0 && "Unsupported device");
222 }
223}
224
225static void
226device_add(struct wl_client *client,
227 struct wl_resource *resource, const char *device)
228{
229 struct weston_test *test = wl_resource_get_user_data(resource);
230 struct weston_seat *seat = get_seat(test);
231
232 if (strcmp(device, "pointer") == 0) {
233 weston_seat_init_pointer(seat);
234 } else if (strcmp(device, "keyboard") == 0) {
235 weston_seat_init_keyboard(seat, NULL);
236 } else if (strcmp(device, "touch") == 0) {
237 weston_seat_init_touch(seat);
238 } else {
239 assert(0 && "Unsupported device");
240 }
241}
242
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000243#ifdef ENABLE_EGL
244static int
245is_egl_buffer(struct wl_resource *resource)
246{
247 PFNEGLQUERYWAYLANDBUFFERWL query_buffer =
248 (void *) eglGetProcAddress("eglQueryWaylandBufferWL");
249 EGLint format;
250
251 if (query_buffer(eglGetCurrentDisplay(),
252 resource,
253 EGL_TEXTURE_FORMAT,
254 &format))
255 return 1;
256
257 return 0;
258}
259#endif /* ENABLE_EGL */
260
261static void
262get_n_buffers(struct wl_client *client, struct wl_resource *resource)
263{
264 int n_buffers = 0;
265
266#ifdef ENABLE_EGL
267 struct wl_resource *buffer_resource;
268 int i;
269
270 for (i = 0; i < 1000; i++) {
271 buffer_resource = wl_client_get_object(client, i);
272
273 if (buffer_resource == NULL)
274 continue;
275
276 if (is_egl_buffer(buffer_resource))
277 n_buffers++;
278 }
279#endif /* ENABLE_EGL */
280
Derek Foremanf6a65922015-02-24 09:32:14 -0600281 weston_test_send_n_egl_buffers(resource, n_buffers);
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000282}
283
Bryce Harringtonf280d112015-05-05 15:13:20 -0700284enum weston_test_screenshot_outcome {
285 WESTON_TEST_SCREENSHOT_SUCCESS,
286 WESTON_TEST_SCREENSHOT_NO_MEMORY,
287 WESTON_TEST_SCREENSHOT_BAD_BUFFER
288 };
289
290typedef void (*weston_test_screenshot_done_func_t)(void *data,
291 enum weston_test_screenshot_outcome outcome);
292
293struct test_screenshot {
294 struct weston_compositor *compositor;
295 struct wl_global *global;
296 struct wl_client *client;
297 struct weston_process process;
298 struct wl_listener destroy_listener;
299};
300
301struct test_screenshot_frame_listener {
302 struct wl_listener listener;
303 struct weston_buffer *buffer;
304 weston_test_screenshot_done_func_t done;
305 void *data;
306};
307
308static void
309copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
310{
311 uint8_t *end;
312
313 end = dst + height * stride;
314 while (dst < end) {
315 memcpy(dst, src, stride);
316 dst += stride;
317 src -= stride;
318 }
319}
320
321
322static void
323copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)
324{
325 /* TODO: optimize this out */
326 memcpy(dst, src, height * stride);
327}
328
329static void
330copy_row_swap_RB(void *vdst, void *vsrc, int bytes)
331{
332 uint32_t *dst = vdst;
333 uint32_t *src = vsrc;
334 uint32_t *end = dst + bytes / 4;
335
336 while (dst < end) {
337 uint32_t v = *src++;
338 /* A R G B */
339 uint32_t tmp = v & 0xff00ff00;
340 tmp |= (v >> 16) & 0x000000ff;
341 tmp |= (v << 16) & 0x00ff0000;
342 *dst++ = tmp;
343 }
344}
345
346static void
347copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
348{
349 uint8_t *end;
350
351 end = dst + height * stride;
352 while (dst < end) {
353 copy_row_swap_RB(dst, src, stride);
354 dst += stride;
355 src -= stride;
356 }
357}
358
359static void
360copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)
361{
362 uint8_t *end;
363
364 end = dst + height * stride;
365 while (dst < end) {
366 copy_row_swap_RB(dst, src, stride);
367 dst += stride;
368 src += stride;
369 }
370}
371
372static void
373test_screenshot_frame_notify(struct wl_listener *listener, void *data)
374{
375 struct test_screenshot_frame_listener *l =
376 container_of(listener,
377 struct test_screenshot_frame_listener, listener);
378 struct weston_output *output = data;
379 struct weston_compositor *compositor = output->compositor;
380 int32_t stride;
381 uint8_t *pixels, *d, *s;
382
383 output->disable_planes--;
384 wl_list_remove(&listener->link);
385 stride = l->buffer->width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
386 pixels = malloc(stride * l->buffer->height);
387
388 if (pixels == NULL) {
389 l->done(l->data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
390 free(l);
391 return;
392 }
393
Chris Michael2ec5f2a2015-12-03 12:23:12 -0500394 /* FIXME: Needs to handle output transformations */
Bryce Harringtonf280d112015-05-05 15:13:20 -0700395
396 compositor->renderer->read_pixels(output,
397 compositor->read_format,
398 pixels,
399 0, 0,
400 output->current_mode->width,
401 output->current_mode->height);
402
403 stride = wl_shm_buffer_get_stride(l->buffer->shm_buffer);
404
405 d = wl_shm_buffer_get_data(l->buffer->shm_buffer);
406 s = pixels + stride * (l->buffer->height - 1);
407
408 wl_shm_buffer_begin_access(l->buffer->shm_buffer);
409
410 /* XXX: It would be nice if we used Pixman to do all this rather
411 * than our own implementation
412 */
413 switch (compositor->read_format) {
414 case PIXMAN_a8r8g8b8:
415 case PIXMAN_x8r8g8b8:
416 if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
417 copy_bgra_yflip(d, s, output->current_mode->height, stride);
418 else
419 copy_bgra(d, pixels, output->current_mode->height, stride);
420 break;
421 case PIXMAN_x8b8g8r8:
422 case PIXMAN_a8b8g8r8:
423 if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
424 copy_rgba_yflip(d, s, output->current_mode->height, stride);
425 else
426 copy_rgba(d, pixels, output->current_mode->height, stride);
427 break;
428 default:
429 break;
430 }
431
432 wl_shm_buffer_end_access(l->buffer->shm_buffer);
433
434 l->done(l->data, WESTON_TEST_SCREENSHOT_SUCCESS);
435 free(pixels);
436 free(l);
437}
438
439static bool
440weston_test_screenshot_shoot(struct weston_output *output,
441 struct weston_buffer *buffer,
442 weston_test_screenshot_done_func_t done,
443 void *data)
444{
445 struct test_screenshot_frame_listener *l;
446
447 /* Get the shm buffer resource the client created */
448 if (!wl_shm_buffer_get(buffer->resource)) {
449 done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
450 return false;
451 }
452
453 buffer->shm_buffer = wl_shm_buffer_get(buffer->resource);
454 buffer->width = wl_shm_buffer_get_width(buffer->shm_buffer);
455 buffer->height = wl_shm_buffer_get_height(buffer->shm_buffer);
456
457 /* Verify buffer is big enough */
458 if (buffer->width < output->current_mode->width ||
459 buffer->height < output->current_mode->height) {
460 done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
461 return false;
462 }
463
464 /* allocate the frame listener */
465 l = malloc(sizeof *l);
466 if (l == NULL) {
467 done(data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
468 return false;
469 }
470
471 /* Set up the listener */
472 l->buffer = buffer;
473 l->done = done;
474 l->data = data;
475 l->listener.notify = test_screenshot_frame_notify;
476 wl_signal_add(&output->frame_signal, &l->listener);
477
478 /* Fire off a repaint */
479 output->disable_planes++;
480 weston_output_schedule_repaint(output);
481
482 return true;
483}
484
485static void
486capture_screenshot_done(void *data, enum weston_test_screenshot_outcome outcome)
487{
488 struct wl_resource *resource = data;
489
490 switch (outcome) {
491 case WESTON_TEST_SCREENSHOT_SUCCESS:
492 weston_test_send_capture_screenshot_done(resource);
493 break;
494 case WESTON_TEST_SCREENSHOT_NO_MEMORY:
495 wl_resource_post_no_memory(resource);
496 break;
497 default:
498 break;
499 }
500}
501
502
503/**
504 * Grabs a snapshot of the screen.
505 */
506static void
507capture_screenshot(struct wl_client *client,
508 struct wl_resource *resource,
509 struct wl_resource *output_resource,
510 struct wl_resource *buffer_resource)
511{
512 struct weston_output *output =
513 wl_resource_get_user_data(output_resource);
514 struct weston_buffer *buffer =
515 weston_buffer_from_resource(buffer_resource);
516
517 if (buffer == NULL) {
518 wl_resource_post_no_memory(resource);
519 return;
520 }
521
522 weston_test_screenshot_shoot(output, buffer,
523 capture_screenshot_done, resource);
524}
525
Derek Foremanf6a65922015-02-24 09:32:14 -0600526static const struct weston_test_interface test_implementation = {
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800527 move_surface,
528 move_pointer,
529 send_button,
530 activate_surface,
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000531 send_key,
Marek Chalupac8daf772015-03-30 06:37:55 -0400532 device_release,
533 device_add,
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000534 get_n_buffers,
Bryce Harringtonf280d112015-05-05 15:13:20 -0700535 capture_screenshot,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800536};
537
538static void
539bind_test(struct wl_client *client, void *data, uint32_t version, uint32_t id)
540{
541 struct weston_test *test = data;
542 struct wl_resource *resource;
543
Derek Foremanf6a65922015-02-24 09:32:14 -0600544 resource = wl_resource_create(client, &weston_test_interface, 1, id);
Marek Chalupa42ebdda2014-07-11 12:33:02 +0200545 if (!resource) {
546 wl_client_post_no_memory(client);
547 return;
548 }
549
Kristian Høgsberg442a5fa2013-07-03 18:13:33 -0400550 wl_resource_set_implementation(resource,
551 &test_implementation, test, NULL);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800552
553 notify_pointer_position(test, resource);
554}
555
556static void
557idle_launch_client(void *data)
558{
559 struct weston_test *test = data;
560 pid_t pid;
561 sigset_t allsigs;
562 char *path;
563
564 path = getenv("WESTON_TEST_CLIENT_PATH");
565 if (path == NULL)
Pekka Paalanenf72e4792013-11-21 16:23:57 +0200566 return;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800567 pid = fork();
568 if (pid == -1)
569 exit(EXIT_FAILURE);
570 if (pid == 0) {
571 sigfillset(&allsigs);
572 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
573 execl(path, path, NULL);
574 weston_log("compositor: executing '%s' failed: %m\n", path);
575 exit(EXIT_FAILURE);
576 }
577
578 test->process.pid = pid;
579 test->process.cleanup = test_client_sigchld;
580 weston_watch_process(&test->process);
581}
582
583WL_EXPORT int
Kristian Høgsbergcb4685b2013-02-20 15:37:49 -0500584module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -0700585 int *argc, char *argv[])
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800586{
587 struct weston_test *test;
588 struct wl_event_loop *loop;
589
Peter Huttererf3d62272013-08-08 11:57:05 +1000590 test = zalloc(sizeof *test);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800591 if (test == NULL)
592 return -1;
593
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800594 test->compositor = ec;
595 weston_layer_init(&test->layer, &ec->cursor_layer.link);
596
Derek Foremanf6a65922015-02-24 09:32:14 -0600597 if (wl_global_create(ec->wl_display, &weston_test_interface, 1,
Kristian Høgsberg919cddb2013-07-08 19:03:57 -0400598 test, bind_test) == NULL)
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800599 return -1;
600
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400601 /* create our own seat */
602 weston_seat_init(&test->seat, ec, "test-seat");
603
604 /* add devices */
605 weston_seat_init_pointer(&test->seat);
Pekka Paalanen315bf8c2016-06-16 12:04:53 +0300606 if (weston_seat_init_keyboard(&test->seat, NULL) < 0)
607 return -1;
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400608 weston_seat_init_touch(&test->seat);
609
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800610 loop = wl_display_get_event_loop(ec->wl_display);
611 wl_event_loop_add_idle(loop, idle_launch_client, test);
612
613 return 0;
614}