[PATCH wayland 3/8] tests: add tests for leak check in clients
Marek Chalupa
mchqwerty at gmail.com
Fri Dec 19 05:53:02 PST 2014
Sanity tests for leak checks in clients of test compositor
and also check if the test-compositor itself is not leaking
anything.
Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
---
tests/display-test.c | 14 +++++++++
tests/sanity-test.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+)
diff --git a/tests/display-test.c b/tests/display-test.c
index f9889a8..6505507 100644
--- a/tests/display-test.c
+++ b/tests/display-test.c
@@ -81,6 +81,20 @@ TEST(display_destroy_listener)
}
static void
+empty_client(void)
+{
+ TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT;
+}
+
+TEST(tc_leaks_tests)
+{
+ struct display *d = display_create();
+ client_create(d, empty_client);
+ display_run(d);
+ display_destroy(d);
+}
+
+static void
registry_handle_globals(void *data, struct wl_registry *registry,
uint32_t id, const char *intf, uint32_t ver)
{
diff --git a/tests/sanity-test.c b/tests/sanity-test.c
index bd3f70c..468b80c 100644
--- a/tests/sanity-test.c
+++ b/tests/sanity-test.c
@@ -95,8 +95,26 @@ FAIL_TEST(sanity_malloc_indirect)
/* not freeing array, must leak */
}
+FAIL_TEST(tc_client_memory_leaks)
+{
+ struct display *d = display_create();
+ client_create(d, sanity_malloc_direct);
+ display_run(d);
+ display_destroy(d);
+}
+
+FAIL_TEST(tc_client_memory_leaks2)
+{
+ struct display *d = display_create();
+ client_create(d, sanity_malloc_indirect);
+ display_run(d);
+ display_destroy(d);
+}
+
FAIL_TEST(sanity_fd_leak)
{
+ TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT;
+
int fd[2];
assert(leak_check_enabled);
@@ -108,6 +126,8 @@ FAIL_TEST(sanity_fd_leak)
FAIL_TEST(sanity_fd_leak_exec)
{
+ TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT;
+
int fd[2];
int nr_fds = count_open_fds();
@@ -129,8 +149,69 @@ TEST(sanity_fd_exec)
exec_fd_leak_check(nr_fds + 2);
}
+TEST(sanity_fd_no_leak)
+{
+ TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT;
+
+ int fd[2];
+
+ assert(leak_check_enabled);
+
+ /* leak 2 file descriptors */
+ if (pipe(fd) < 0)
+ exit(EXIT_SUCCESS); /* failed to fail */
+
+ close(fd[0]);
+ close(fd[1]);
+}
+
+static void
+sanity_client_no_leak(void)
+{
+ struct wl_display *display = wl_display_connect(NULL);
+ assert(display);
+
+ wl_display_disconnect(display);
+}
+
+TEST(tc_client_no_fd_leaks)
+{
+ struct display *d = display_create();
+
+ /* this one uses TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT */
+ client_create(d, sanity_fd_no_leak);
+ display_run(d);
+
+ /* this one uses wl_display_connect() */
+ client_create(d, sanity_client_no_leak);
+ display_run(d);
+ display_destroy(d);
+}
+
+FAIL_TEST(tc_client_fd_leaks)
+{
+ struct display *d = display_create();
+
+ client_create(d, sanity_fd_leak);
+ display_run(d);
+
+ display_destroy(d);
+}
+
+FAIL_TEST(tc_client_fd_leaks_exec)
+{
+ struct display *d = display_create();
+
+ client_create(d, sanity_fd_leak);
+ display_run(d);
+
+ display_destroy(d);
+}
+
FAIL_TEST(timeout_tst)
{
+ TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT;
+
test_set_timeout(1);
/* test should reach timeout */
test_sleep(2);
@@ -138,6 +219,8 @@ FAIL_TEST(timeout_tst)
TEST(timeout2_tst)
{
+ TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT;
+
/* the test should end before reaching timeout,
* thus it should pass */
test_set_timeout(1);
@@ -147,6 +230,8 @@ TEST(timeout2_tst)
FAIL_TEST(timeout_reset_tst)
{
+ TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT;
+
test_set_timeout(5);
test_set_timeout(10);
test_set_timeout(1);
@@ -157,6 +242,8 @@ FAIL_TEST(timeout_reset_tst)
TEST(timeout_turnoff)
{
+ TEST_CLIENT_NOT_USING_WL_DISPLAY_CONNECT;
+
test_set_timeout(1);
test_set_timeout(0);
--
2.1.0
More information about the wayland-devel
mailing list