From: Stephan Bosch Date: Fri, 10 Apr 2020 15:32:16 +0000 (+0200) Subject: lib-test: test-common - Add test_forked_end(). X-Git-Tag: 2.3.13~723 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7d2a1568004b0f221b40c28a65787291500bc8f4;p=thirdparty%2Fdovecot%2Fcore.git lib-test: test-common - Add test_forked_end(). --- diff --git a/src/lib-test/test-common.c b/src/lib-test/test-common.c index 59bd55937b..1c3ce53193 100644 --- a/src/lib-test/test-common.c +++ b/src/lib-test/test-common.c @@ -381,6 +381,17 @@ int test_run_named_with_fatals(const char *match, const struct named_test tests[ return test_deinit(); } +void test_forked_end(void) +{ + i_set_error_handler(default_error_handler); + i_set_fatal_handler(default_fatal_handler); + + i_free_and_null(expected_error_str); + i_free_and_null(expected_fatal_str); + i_free_and_null(test_prefix); + t_pop_last_unsafe(); /* as we were within a T_BEGIN { tests[i].func(); } T_END */ +} + void ATTR_NORETURN test_exit(int status) { diff --git a/src/lib-test/test-common.h b/src/lib-test/test-common.h index 1f1318fe6c..0ac5e6d1d4 100644 --- a/src/lib-test/test-common.h +++ b/src/lib-test/test-common.h @@ -99,6 +99,9 @@ void test_expect_fatal_string(const char *substr); #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 child is forked within test context, but wants to operate outside it, + then this will avoid valgrind leak errors */ +void test_forked_end(void); /* If a fork() wants to exit(), then this will avoid valgrind leak errors */ void test_exit(int status) ATTR_NORETURN;