diff options
author | U. Artie Eoff <ullysses.a.eoff@intel.com> | 2012-08-16 18:12:05 -0700 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2012-08-29 14:10:24 -0400 |
commit | 91931bcabb0fba1a8b76f92cefa33fdeb1b74a8b (patch) | |
tree | c84f078a6adf3cae843073d8f47aa18dc8e22d35 /tests | |
parent | c95c2dffb0a37ae50350319c52b30629c32f6660 (diff) |
tests: ensure sanity leak check tests pass when leak checks are disabled.
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.eoff@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sanity-test.c | 8 | ||||
-rw-r--r-- | tests/test-runner.c | 6 |
2 files changed, 13 insertions, 1 deletions
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) { |