]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-test: Do not init/deinit library twice
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 31 Oct 2016 13:37:00 +0000 (15:37 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 31 Oct 2016 13:46:06 +0000 (15:46 +0200)
If lib is initialized, do not initialize
or deinitialize library. This is done to
allow using master_service in unit tests
which also wants to perform lib init
and deinit itself.

src/lib-test/test-common.c

index 3f7cf976e9ffcdcf44216f2c434d41ac5f2ff167..95f5be3a252778c7b0e29b4e88a9542d0ce87902 100644 (file)
@@ -7,6 +7,8 @@
 #include <unistd.h> /* _exit() */
 #include <setjmp.h> /* for fatal tests */
 
+static bool test_deinit_lib;
+
 /* To test the firing of i_assert, we need non-local jumps, i.e. setjmp */
 static volatile bool expecting_fatal = FALSE;
 static jmp_buf fatal_jmpbuf;
@@ -206,7 +208,12 @@ static void test_init(void)
        failure_count = 0;
        total_count = 0;
 
-       lib_init();
+       if (!lib_is_initialized()) {
+               lib_init();
+               test_deinit_lib = TRUE;
+       } else
+               test_deinit_lib = FALSE;
+
        i_set_error_handler(test_error_handler);
        /* Don't set fatal handler until actually needed for fatal testing */
 }
@@ -215,7 +222,8 @@ static int test_deinit(void)
 {
        i_assert(test_prefix == NULL);
        printf("%u / %u tests failed\n", failure_count, total_count);
-       lib_deinit();
+       if (test_deinit_lib)
+               lib_deinit();
        return failure_count == 0 ? 0 : 1;
 }