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>
This commit is contained in:
U. Artie Eoff 2012-08-16 18:12:05 -07:00 committed by Kristian Høgsberg
parent c95c2dffb0
commit 91931bcabb
2 changed files with 13 additions and 1 deletions

View File

@ -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 */

View File

@ -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) {