diff options
| author | Alexandros Frantzis <alexandros.frantzis@collabora.com> | 2022-12-01 20:02:43 +0200 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2023-02-28 11:22:04 +0000 |
| commit | d4d322885349c73f8753cca0c6d7754d2b0b411e (patch) | |
| tree | ce6991bb2016f2d9af0c840a1c179a45098ce32d /tests/test-compositor.c | |
| parent | client: Track the proxies attached to a queue (diff) | |
| download | wayland-d4d322885349c73f8753cca0c6d7754d2b0b411e.tar wayland-d4d322885349c73f8753cca0c6d7754d2b0b411e.tar.gz wayland-d4d322885349c73f8753cca0c6d7754d2b0b411e.tar.bz2 wayland-d4d322885349c73f8753cca0c6d7754d2b0b411e.tar.lz wayland-d4d322885349c73f8753cca0c6d7754d2b0b411e.tar.xz wayland-d4d322885349c73f8753cca0c6d7754d2b0b411e.tar.zst wayland-d4d322885349c73f8753cca0c6d7754d2b0b411e.zip | |
tests: Capture the test client log
Capture the test client log to a temporary fd, so that is accessible by both
the test server process and the test client process.
Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Diffstat (limited to 'tests/test-compositor.c')
| -rw-r--r-- | tests/test-compositor.c | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/tests/test-compositor.c b/tests/test-compositor.c index 103ddc8..587bc2b 100644 --- a/tests/test-compositor.c +++ b/tests/test-compositor.c @@ -40,6 +40,8 @@ #include "test-runner.h" #include "test-compositor.h" +int client_log_fd = -1; + /* --- Protocol --- */ struct test_compositor; @@ -156,8 +158,20 @@ client_destroyed(struct wl_listener *listener, void *data) } static void +client_log_handler(const char *fmt, va_list arg) +{ + va_list arg_copy; + + va_copy(arg_copy, arg); + vdprintf(client_log_fd, fmt, arg_copy); + va_end(arg_copy); + + vfprintf(stderr, fmt, arg); +} + +static void run_client(void (*client_main)(void *data), void *data, - int wayland_sock, int client_pipe) + int wayland_sock, int client_pipe, int log_fd) { char s[8]; int cur_fds; @@ -173,6 +187,10 @@ run_client(void (*client_main)(void *data), void *data, snprintf(s, sizeof s, "%d", wayland_sock); setenv("WAYLAND_SOCKET", s, 0); + /* Capture the log to the specified file descriptor. */ + client_log_fd = log_fd; + wl_log_set_handler_client(client_log_handler); + cur_fds = count_open_fds(); client_main(data); @@ -188,6 +206,18 @@ run_client(void (*client_main)(void *data), void *data, check_fd_leaks(cur_fds); } +static int +create_log_fd(void) +{ + char logname[] = "/tmp/wayland-tests-log-XXXXXX"; + int log_fd = mkstemp(logname); + + if (log_fd >= 0) + unlink(logname); + + return log_fd; +} + static struct client_info * display_create_client(struct display *d, void (*client_main)(void *data), @@ -199,11 +229,15 @@ display_create_client(struct display *d, pid_t pid; int can_continue = 0; struct client_info *cl; + int log_fd; assert(pipe(pipe_cli) == 0 && "Failed creating pipe"); assert(socketpair(AF_UNIX, SOCK_STREAM, 0, sock_wayl) == 0 && "Failed creating socket pair"); + log_fd = create_log_fd(); + assert(log_fd >= 0 && "Failed to create log fd"); + pid = fork(); assert(pid != -1 && "Fork failed"); @@ -211,10 +245,11 @@ display_create_client(struct display *d, close(sock_wayl[1]); close(pipe_cli[1]); - run_client(client_main, data, sock_wayl[0], pipe_cli[0]); + run_client(client_main, data, sock_wayl[0], pipe_cli[0], log_fd); close(sock_wayl[0]); close(pipe_cli[0]); + close(log_fd); exit(0); } @@ -231,6 +266,7 @@ display_create_client(struct display *d, cl->name = name; cl->pid = pid; cl->pipe = pipe_cli[1]; + cl->log_fd = log_fd; cl->destroy_listener.notify = &client_destroyed; cl->wl_client = wl_client_create(d->wl_display, sock_wayl[1]); @@ -407,6 +443,7 @@ display_destroy(struct display *d) } close(cl->pipe); + close(cl->log_fd); free(cl); } |
