diff options
author | Marek Chalupa <mchqwerty@gmail.com> | 2014-12-19 14:53:01 +0100 |
---|---|---|
committer | Daniel Stone <daniels@collabora.com> | 2015-01-28 17:17:06 +0000 |
commit | 9ef027757110684f659e2698dc3382c96b9ab9e7 (patch) | |
tree | 7bdd917f583fd900be3ed02d53301f94bfe371c7 | |
parent | d8e72f98f21b70ac8ae6bcf6e7594c7e656773f4 (diff) | |
download | wayland-9ef027757110684f659e2698dc3382c96b9ab9e7.tar.gz |
test-compositor: extend leak checks into clients
Run leak checks also on clients of test-compositor.
Checking leaks in memory is the same as in normal TEST.
Checking file descriptor leaks is slightly more complex, as we pass an
open file descriptor in the WAYLAND_SOCKET environment variable, which
will be consumed by a client calling wl_display_connect(), but otherwise
remain unused. We manage this accounting by checking if the environment
variable has been unset by wl_display_connect() as it consumes the
socket.
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
[daniels: squashed counter-proposal patch to simplify fd leak checking,
plus Bill's counter-counter-proposal, and reworded log.]
-rw-r--r-- | tests/test-compositor.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test-compositor.c b/tests/test-compositor.c index 6f86a85..da2a55f 100644 --- a/tests/test-compositor.c +++ b/tests/test-compositor.c @@ -33,6 +33,7 @@ #define WL_HIDE_DEPRECATED +#include "test-runner.h" #include "test-compositor.h" /* --- Protocol --- */ @@ -135,6 +136,7 @@ static void run_client(void (*client_main)(void), int wayland_sock, int client_pipe) { char s[8]; + int cur_alloc, cur_fds; int can_continue = 0; /* Wait until display signals that client can continue */ @@ -147,7 +149,20 @@ run_client(void (*client_main)(void), int wayland_sock, int client_pipe) snprintf(s, sizeof s, "%d", wayland_sock); setenv("WAYLAND_SOCKET", s, 0); + cur_alloc = get_current_alloc_num(); + cur_fds = count_open_fds(); + client_main(); + + /* Clients using wl_display_connect() will end up closing the socket + * passed in through the WAYLAND_SOCKET environment variable. When + * doing this, it clears the environment variable, so if it's been + * unset, then we assume the client consumed the file descriptor and + * do not count it towards leak checking. */ + if (!getenv("WAYLAND_SOCKET")) + cur_fds--; + + check_leaks(cur_alloc, cur_fds); } static struct client_info * |