From 3d5c7cd46c60e0a534dce0640c4e47b699e7003e Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 24 Jan 2023 18:09:06 +1100 Subject: [PATCH] Kill unit tests that run more than 1200 seconds 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. --- tests/include/tests/isc.h | 52 ++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/tests/include/tests/isc.h b/tests/include/tests/isc.h index 391a64454b..b58695e3a4 100644 --- a/tests/include/tests/isc.h +++ b/tests/include/tests/isc.h @@ -17,6 +17,9 @@ #include #include +#include +#include +#include #include #include @@ -166,18 +169,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); \ }