]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add test-fd-util.c to test i_close() panic message
authorMartti Rannanjärvi <martti.rannanjarvi@open-xchange.com>
Thu, 23 May 2019 15:49:18 +0000 (18:49 +0300)
committerMartti Rannanjärvi <martti.rannanjarvi@open-xchange.com>
Thu, 23 May 2019 20:02:44 +0000 (23:02 +0300)
src/lib/Makefile.am
src/lib/test-fd-util.c [new file with mode: 0644]
src/lib/test-lib.inc

index f1fd95c5ff491dade8c14dbcb7c9e931fca7c633..2726dd80da7515eeb4c3a33c4d8c80d8798acf92 100644 (file)
@@ -349,6 +349,7 @@ test_lib_SOURCES = \
        test-event-flatten.c \
        test-event-log.c \
        test-failures.c \
+       test-fd-util.c \
        test-file-create-locked.c \
        test-guid.c \
        test-hash.c \
diff --git a/src/lib/test-fd-util.c b/src/lib/test-fd-util.c
new file mode 100644 (file)
index 0000000..1058eca
--- /dev/null
@@ -0,0 +1,24 @@
+/* Copyright (c) 2019 Dovecot authors, see the included COPYING file */
+
+#include "test-lib.h"
+#include "fd-util.h"
+
+enum fatal_test_state fatal_i_close(unsigned int stage)
+{
+       if (stage == 0) {
+               test_begin("fatal i_close");
+       } else {
+               test_end();
+               return FATAL_TEST_FINISHED;
+       }
+
+       int fd = 0;
+       const char *fatal_string = t_strdup_printf(
+               "%s: close((&fd)) @ %s:%d attempted with fd=%d",
+               __func__, __FILE__, __LINE__ + 2, fd);
+       test_expect_fatal_string(fatal_string);
+       i_close_fd(&fd);
+
+       /* This cannot be reached. */
+       return FATAL_TEST_ABORT;
+}
index 12f9305bdb795a4a9aae1aaf509e1eaa86095162..0d2895fc293e0a85825cd9473c424648396af2a5 100644 (file)
@@ -27,6 +27,7 @@ TEST(test_hash_format)
 TEST(test_hash_method)
 TEST(test_hmac)
 TEST(test_hex_binary)
+FATAL(fatal_i_close)
 TEST(test_imem)
 TEST(test_ioloop)
 TEST(test_iso8601_date)