diff options
author | Marek Chalupa <mchqwerty@gmail.com> | 2014-12-19 14:53:00 +0100 |
---|---|---|
committer | Daniel Stone <daniels@collabora.com> | 2015-01-28 17:15:57 +0000 |
commit | d8e72f98f21b70ac8ae6bcf6e7594c7e656773f4 (patch) | |
tree | 70553a66accf0a9359db5b57954f7232c32da9a3 | |
parent | 6197f32cadc82d62a3641385098fe5ffebc147d6 (diff) | |
download | wayland-d8e72f98f21b70ac8ae6bcf6e7594c7e656773f4.tar.gz |
test-runner: move leak checking into function
1) now we can use it in the test-compositor
2) it looks better
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
-rw-r--r-- | tests/test-runner.c | 54 | ||||
-rw-r--r-- | tests/test-runner.h | 6 |
2 files changed, 41 insertions, 19 deletions
diff --git a/tests/test-runner.c b/tests/test-runner.c index 48e9a22..2e6ad33 100644 --- a/tests/test-runner.c +++ b/tests/test-runner.c @@ -149,15 +149,41 @@ sigalrm_handler(int signum) abort(); } +int +get_current_alloc_num(void) +{ + return num_alloc; +} + +void +check_leaks(int supposed_alloc, int supposed_fds) +{ + int num_fds; + + if (leak_check_enabled) { + if (supposed_alloc != num_alloc) { + fprintf(stderr, "Memory leak detected in test. " + "Allocated %d blocks, unfreed %d\n", num_alloc, + num_alloc - supposed_alloc); + abort(); + } + + num_fds = count_open_fds(); + if (supposed_fds != num_fds) { + fprintf(stderr, "fd leak detected in test. " + "Opened %d files, unclosed %d\n", num_fds, + num_fds - supposed_fds); + abort(); + } + } +} + static void run_test(const struct test *t) { - int cur_alloc = num_alloc; - int cur_fds, num_fds; + int cur_alloc, cur_fds; struct sigaction sa; - cur_fds = count_open_fds(); - if (timeouts_enabled) { sa.sa_handler = sigalrm_handler; sa.sa_flags = 0; @@ -165,27 +191,17 @@ run_test(const struct test *t) assert(sigaction(SIGALRM, &sa, NULL) == 0); } + cur_alloc = get_current_alloc_num(); + cur_fds = count_open_fds(); + t->run(); /* turn off timeout (if any) after test completition */ if (timeouts_enabled) alarm(0); - if (leak_check_enabled) { - if (cur_alloc != num_alloc) { - fprintf(stderr, "Memory leak detected in test. " - "Allocated %d blocks, unfreed %d\n", num_alloc, - num_alloc - cur_alloc); - abort(); - } - num_fds = count_open_fds(); - if (cur_fds != num_fds) { - fprintf(stderr, "fd leak detected in test. " - "Opened %d files, unclosed %d\n", num_fds, - num_fds - cur_fds); - abort(); - } - } + check_leaks(cur_alloc, cur_fds); + exit(EXIT_SUCCESS); } diff --git a/tests/test-runner.h b/tests/test-runner.h index 0e03530..5963ab6 100644 --- a/tests/test-runner.h +++ b/tests/test-runner.h @@ -39,6 +39,12 @@ count_open_fds(void); void exec_fd_leak_check(int nr_expected_fds); /* never returns */ +int +get_current_alloc_num(void); + +void +check_leaks(int supposed_allocs, int supposed_fds); + /* * set/reset the timeout in seconds. The timeout starts * at the point of invoking this function |