]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Kill unit tests that run more than 1200 seconds
authorMark Andrews <marka@isc.org>
Tue, 24 Jan 2023 07:09:06 +0000 (18:09 +1100)
committerMark Andrews <marka@isc.org>
Mon, 3 Apr 2023 01:11:26 +0000 (11:11 +1000)
The CI doesn't provide useful forensics when a system test locks
up.  Fork the process and kill it with ABRT if it is still running
after 20 minutes.  Pass the exit status to the caller.

(cherry picked from commit 3d5c7cd46c60e0a534dce0640c4e47b699e7003e)

lib/isc/include/isc/util.h
tests/include/tests/isc.h

index 922661beaa3f6701b3522ab77063b6a9fea6a4fc..81a793d87d2d0b2c1e40722fa86bf852af49a5b1 100644 (file)
  */
 #define UNUSED(x) (void)(x)
 
+#if __has_c_attribute(maybe_unused)
+#define ISC_ATTR_UNUSED [[maybe_unused]]
+#else
+#define ISC_ATTR_UNUSED __attribute__((__unused__))
+#endif
+
 #if __GNUC__ >= 8 && !defined(__clang__)
 #define ISC_NONSTRING __attribute__((nonstring))
 #else /* if __GNUC__ >= 8 && !defined(__clang__) */
index 6131c2018529007ab03d10621c3ce60008d632f8..9165a4208ac6559b477acb9c39918fe12b244b27 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <inttypes.h>
 #include <stdbool.h>
+#include <unistd.h>
 #include <uv.h>
 
 #include <isc/buffer.h>
@@ -35,6 +36,9 @@
 #include "task_p.h"
 #include "timer_p.h"
 
+#include <sys/types.h>
+#include <sys/wait.h>
+
 #define CHECK(r)                             \
        do {                                 \
                result = (r);                \
@@ -102,18 +106,39 @@ teardown_managers(void **state);
 
 #define ISC_TEST_MAIN ISC_TEST_MAIN_CUSTOM(NULL, NULL)
 
-#define ISC_TEST_MAIN_CUSTOM(setup, teardown)                       \
-       int main(void) {                                            \
-               int r;                                              \
-                                                                    \
-               signal(SIGPIPE, SIG_IGN);                           \
-                                                                    \
-               isc_mem_debugging |= ISC_MEM_DEBUGRECORD;           \
-               isc_mem_create(&mctx);                              \
-                                                                    \
-               r = cmocka_run_group_tests(tests, setup, teardown); \
-                                                                    \
-               isc_mem_destroy(&mctx);                             \
-                                                                    \
-               return (r);                                         \
+#define ISC_TEST_MAIN_CUSTOM(setup, teardown)                                \
+       static int  __child = 0;                                             \
+       static void __alarm(int sig ISC_ATTR_UNUSED) {                       \
+               kill(__child, SIGABRT);                                      \
+       }                                                                    \
+       int main(void) {                                                     \
+               int r, status;                                               \
+                                                                             \
+               switch ((__child = fork())) {                                \
+               case 0:                                                      \
+                       break;                                               \
+               case -1:                                                     \
+                       exit(1);                                             \
+               default:                                                     \
+                       signal(SIGALRM, __alarm);                            \
+                       alarm(1200);                                         \
+                       if ((r = waitpid(__child, &status, 0)) == __child) { \
+                               /* Pass the exit status to the caller. */    \
+                               if (WIFEXITED(status)) {                     \
+                                       exit(WEXITSTATUS(status));           \
+                               }                                            \
+                       }                                                    \
+                       exit(1);                                             \
+               }                                                            \
+                                                                             \
+               signal(SIGPIPE, SIG_IGN);                                    \
+                                                                             \
+               isc_mem_debugging |= ISC_MEM_DEBUGRECORD;                    \
+               isc_mem_create(&mctx);                                       \
+                                                                             \
+               r = cmocka_run_group_tests(tests, setup, teardown);          \
+                                                                             \
+               isc_mem_destroy(&mctx);                                      \
+                                                                             \
+               return (r);                                                  \
        }