2 * Copyright © 2012 Intel Corporation
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
29 #include <sys/types.h>
33 #include <sys/socket.h>
35 #include "test-runner.h"
38 test_client_cleanup(struct weston_process *proc, int status)
40 struct test_client *client =
41 container_of(proc, struct test_client, proc);
43 fprintf(stderr, "server: test client exited, status %d\n", status);
45 client->status = status;
48 assert(client->status == 0);
50 if (client->terminate)
51 wl_display_terminate(client->compositor->wl_display);
55 test_client_data(int fd, uint32_t mask, void *data)
57 struct test_client *client = data;
58 struct wl_event_loop *loop;
61 len = read(client->fd, client->buf, sizeof client->buf);
63 fprintf(stderr, "server: got %.*s from client\n", len - 1, client->buf);
64 assert(client->buf[len - 1] == '\n');
65 client->buf[len - 1] = '\0';
67 loop = wl_display_get_event_loop(client->compositor->wl_display);
68 wl_event_loop_add_idle(loop, (void *) client->handle, client);
74 test_client_launch(struct weston_compositor *compositor, const char *file_name)
76 struct test_client *client;
77 struct wl_event_loop *loop;
78 int ret, sv[2], client_fd;
81 client = malloc(sizeof *client);
83 ret = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv);
86 client_fd = dup(sv[0]);
87 assert(client_fd >= 0);
88 snprintf(buf, sizeof buf, "%d", client_fd);
89 setenv("TEST_SOCKET", buf, 1);
90 snprintf(buf, sizeof buf, "%s/%s", getenv("abs_builddir"), file_name);
91 fprintf(stderr, "server: launching %s\n", buf);
93 client->terminate = 0;
94 client->compositor = compositor;
95 client->client = weston_client_launch(compositor,
98 assert(client->client);
102 loop = wl_display_get_event_loop(compositor->wl_display);
103 wl_event_loop_add_fd(loop, client->fd, WL_EVENT_READABLE,
104 test_client_data, client);
110 test_client_send(struct test_client *client, const char *fmt, ...)
117 len = vsnprintf(buf, sizeof buf, fmt, ap);
120 fprintf(stderr, "server: sending %s", buf);
122 assert(write(client->fd, buf, len) == len);
125 extern const struct test __start_test_section, __stop_test_section;
130 struct weston_compositor *compositor = data;
131 const struct test *t;
133 for (t = &__start_test_section; t < &__stop_test_section; t++)
138 module_init(struct weston_compositor *compositor);
141 module_init(struct weston_compositor *compositor)
143 struct wl_event_loop *loop;
145 loop = wl_display_get_event_loop(compositor->wl_display);
147 wl_event_loop_add_idle(loop, run_test, compositor);