Mercurial > dovecot > core-2.2
changeset 20713:3d0aecd0b2bc
lib-test: test-exit helper to stop valgrind complaining about fork()s
fork()s that want to _exit() will cause valgrind's full memory leak
checker to complain a lot - this performs a quick cleanup first.
Before:
phil@phil:~/repos/dovecot-core$ valgrind --trace-children=yes --leak-check=full --show-leak-kinds=all src/lib/test-lib --match unix
==19576== total heap usage: 4 allocs, 0 frees, 17,858 bytes allocated
istream unix ......................................................... : ok
0 / 1 tests failed
==19575== total heap usage: 7 allocs, 7 frees, 19,327 bytes allocated
After:
phil@phil:~/repos/dovecot-core$ valgrind --trace-children=yes --leak-check=full --show-leak-kinds=all src/lib/test-lib --match unix
istream unix ......................................................... : ok
==4993== total heap usage: 4 allocs, 4 frees, 17,858 bytes allocated
0 / 1 tests failed
==4992== total heap usage: 7 allocs, 7 frees, 19,327 bytes allocated
Signed-off-by: Phil Carmody <phil@dovecot.fi>
author | Phil Carmody <phil@dovecot.fi> |
---|---|
date | Tue, 09 Aug 2016 18:29:19 +0300 |
parents | 8730e4b4ec11 |
children | 2ac556536f25 |
files | src/lib-test/test-common.c src/lib-test/test-common.h src/lib/test-istream-unix.c |
diffstat | 3 files changed, 15 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-test/test-common.c Tue Jul 12 13:28:54 2016 +0300 +++ b/src/lib-test/test-common.c Tue Aug 09 18:29:19 2016 +0300 @@ -5,7 +5,7 @@ #include "test-common.h" #include <stdio.h> - +#include <unistd.h> /* _exit() */ #include <setjmp.h> /* for fatal tests */ /* To test the firing of i_assert, we need non-local jumps, i.e. setjmp */ @@ -458,3 +458,13 @@ test_run_named_fatals(fatals, match); return test_deinit(); } + +void ATTR_NORETURN +test_exit(int status) +{ + i_free_and_null(expected_error_str); + i_free_and_null(test_prefix); + (void)t_pop(); /* as we were within a T_BEGIN { tests[i].func(); } T_END */ + lib_deinit(); + _exit(status); +}
--- a/src/lib-test/test-common.h Tue Jul 12 13:28:54 2016 +0300 +++ b/src/lib-test/test-common.h Tue Aug 09 18:29:19 2016 +0300 @@ -73,4 +73,7 @@ #define FATAL_NAMELESS(x) x, /* Were you to want to use the X trick but not name the tests */ #define FATAL_NAMED(x) { .name = #x , .func = x }, +/* If a fork() wants to exit(), then this will avoid valgrind leak errors */ +void test_exit(int status) ATTR_NORETURN; + #endif
--- a/src/lib/test-istream-unix.c Tue Jul 12 13:28:54 2016 +0300 +++ b/src/lib/test-istream-unix.c Tue Aug 09 18:29:19 2016 +0300 @@ -176,7 +176,7 @@ case 0: i_close_fd(&fd[0]); test_istream_unix_client(fd[1]); - _exit(0); + test_exit(0); default: i_close_fd(&fd[1]); test_istream_unix_server(fd[0]);