]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Provide a method to dump the stack on abort
authorMartin Schwenke <martin@meltin.net>
Wed, 5 Jan 2022 02:45:33 +0000 (13:45 +1100)
committerAmitay Isaacs <amitay@samba.org>
Tue, 3 May 2022 09:19:31 +0000 (09:19 +0000)
Some tests make generous use of assert() and it can be difficult to
guess the cause of failures without resorting to GDB.  This provides
some help.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/src/test_backtrace.c [new file with mode: 0644]
ctdb/tests/src/test_backtrace.h [new file with mode: 0644]
ctdb/wscript

diff --git a/ctdb/tests/src/test_backtrace.c b/ctdb/tests/src/test_backtrace.c
new file mode 100644 (file)
index 0000000..aa3fc0c
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+   Print a backtrace when a test aborts
+
+   Copyright (C) Martin Schwenke, DataDirect Networks  2022
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "replace.h"
+
+#include "lib/util/fault.h"
+#include "lib/util/signal.h"
+
+#include "tests/src/test_backtrace.h"
+
+static void test_abort_backtrace_handler(int sig)
+{
+       log_stack_trace();
+       CatchSignal(SIGABRT, SIG_DFL);
+       abort();
+}
+
+void test_backtrace_setup(void)
+{
+       CatchSignal(SIGABRT, test_abort_backtrace_handler);
+}
diff --git a/ctdb/tests/src/test_backtrace.h b/ctdb/tests/src/test_backtrace.h
new file mode 100644 (file)
index 0000000..a6089c9
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+   Print a backtrace when a test aborts
+
+   Copyright (C) Martin Schwenke, DataDirect Networks  2022
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __CTDB_TEST_BACKTRACE_H__
+#define __CTDB_TEST_BACKTRACE_H__
+
+void test_backtrace_setup(void);
+
+#endif /* __CTDB_TEST_BACKTRACE_H__ */
index 0445c1c447114dd405a815a728f3752352d5cdb5..8feda184d861b97c7c479d6bbf1fa8a67f936a7d 100644 (file)
@@ -1013,7 +1013,10 @@ def build(bld):
 
     bld.SAMBA_SUBSYSTEM('ctdb-tests-common',
                         source=bld.SUBDIR('tests/src',
-                                          'cluster_wait.c test_options.c'),
+                                          '''cluster_wait.c
+                                             test_options.c
+                                             test_backtrace.c
+                                          '''),
                         deps='''ctdb-client
                                 samba-util
                                 replace