[PATCH wayland 2/8] test-compositor: extend leak checks into clients

Marek Chalupa mchqwerty at gmail.com
Fri Dec 19 05:53:01 PST 2014


Run leak checks also on clients of test-compositor.

Checking leaks in memory is the same as in normal TEST.

The problem here is with fds. We pass WAYLAND_SOCKET
fd to the client and this fd is over taken by wl_display and
closed in wl_display_disonnect(). The result is that
the client closed one more fd than it opened. That would
not be a problem if every client used wl_display_connect() -
but this is not the case. E. g. sanity-tests usually do not
call wl_display_connect().

Solution is simple: when client does not call wl_display_connect(),
it states it by invoking TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT macro.
Because mostly (we can use word 'only' at the moment) sanity-test
clients do not use wl_display_connect(), this does not introduce any changes
to regular testing clients (and thus for the guys that write those clients)

Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
---
 tests/test-compositor.c | 17 +++++++++++++++++
 tests/test-compositor.h |  6 ++++++
 2 files changed, 23 insertions(+)

diff --git a/tests/test-compositor.c b/tests/test-compositor.c
index 6f86a85..6d94ae9 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 --- */
@@ -131,10 +132,15 @@ client_destroyed(struct wl_listener *listener, void *data)
 	ci->wl_client = NULL;
 }
 
+/* clients that are not using wl_display_connect() will set this to 1
+ * to fix fd leak checks */
+int not_using_wl_display_connect;
+
 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 +153,18 @@ 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();
+
+	not_using_wl_display_connect = 0;
 	client_main();
+
+	/* if client does not use wl_display_connect, then it has one more
+	 * opened filedescriptor which is WAYLAND_SOCKET.
+	 * We assume that the client uses wl_display_connect() (thus -1)
+	 * and if it does not, it declares it by setting
+	 * not_using_wl_display_connect to 1 */
+	check_leaks(cur_alloc, cur_fds - 1 + not_using_wl_display_connect);
 }
 
 static struct client_info *
diff --git a/tests/test-compositor.h b/tests/test-compositor.h
index c41b17b..f77a5db 100644
--- a/tests/test-compositor.h
+++ b/tests/test-compositor.h
@@ -95,3 +95,9 @@ struct client_info *client_create_with_name(struct display *d,
 					    void (*client_main)(void),
 					    const char *name);
 #define client_create(d, c) client_create_with_name((d), (c), (#c))
+
+#define TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT		\
+	do {							\
+		extern int not_using_wl_display_connect;	\
+		not_using_wl_display_connect = 1;		\
+	} while(0);
-- 
2.1.0



More information about the wayland-devel mailing list