From: "U. Artie Eoff" <ullysses.a.e...@intel.com>

This finalizes Robert Bradfords patch to allow NO_ASSERT_LEAK_CHECK
environment variable to disable leak checks in unit tests.

Signed-off-by: U. Artie Eoff <ullysses.a.e...@intel.com>
---
 tests/sanity-test.c | 8 ++++++++
 tests/test-runner.c | 6 +++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/tests/sanity-test.c b/tests/sanity-test.c
index 67ca663..46f4f85 100644
--- a/tests/sanity-test.c
+++ b/tests/sanity-test.c
@@ -29,6 +29,8 @@
 #include "test-runner.h"
 #include "wayland-util.h"
 
+extern int leak_check_enabled;
+
 TEST(empty)
 {
 }
@@ -68,6 +70,8 @@ FAIL_TEST(sanity_malloc_direct)
 {
        void *p;
 
+       assert(leak_check_enabled);
+
        p = malloc(10); /* memory leak */
        assert(p);      /* assert that we got memory, also prevents
                         * the malloc from getting optimized away. */
@@ -78,6 +82,8 @@ FAIL_TEST(sanity_malloc_indirect)
 {
        struct wl_array array;
 
+       assert(leak_check_enabled);
+
        wl_array_init(&array);
 
        /* call into library that calls malloc */
@@ -90,6 +96,8 @@ FAIL_TEST(sanity_fd_leak)
 {
        int fd[2];
 
+       assert(leak_check_enabled);
+
        /* leak 2 file descriptors */
        if (pipe(fd) < 0)
                exit(EXIT_SUCCESS); /* failed to fail */
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 6c30649..8c79dff 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -39,6 +39,8 @@ static void (*sys_free)(void*);
 static void* (*sys_realloc)(void*, size_t);
 static void* (*sys_calloc)(size_t, size_t);
 
+int leak_check_enabled;
+
 extern const struct test __start_test_section, __stop_test_section;
 
 __attribute__ ((visibility("default"))) void *
@@ -95,7 +97,7 @@ run_test(const struct test *t)
 
        cur_fds = count_open_fds();
        t->run();
-       if (!getenv("NO_ASSERT_LEAK_CHECK")) {
+       if (leak_check_enabled) {
                assert(cur_alloc == num_alloc && "memory leak detected in 
test.");
                assert(cur_fds == count_open_fds() && "fd leak detected");
        }
@@ -115,6 +117,8 @@ int main(int argc, char *argv[])
        sys_malloc = dlsym(RTLD_NEXT, "malloc");
        sys_free = dlsym(RTLD_NEXT, "free");
 
+       leak_check_enabled = !getenv("NO_ASSERT_LEAK_CHECK");
+
        if (argc == 2) {
                t = find_test(argv[1]);
                if (t == NULL) {
-- 
1.7.11.2

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to