aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-22 12:01:39 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-22 12:01:39 +0000
commit664d53715dcd7c9c266083179bae00ff19750557 (patch)
tree72fcdba0b1165fbf4e8decbeb87d671682294d7b
parentcac99b2cbe66cc254098be9eb859973a1d3b2b3c (diff)
downloadpaludis-664d53715dcd7c9c266083179bae00ff19750557.tar.gz
paludis-664d53715dcd7c9c266083179bae00ff19750557.tar.xz
Make the test errors more useful if we hit a timeout or segfault
-rw-r--r--test/test_runner.cc38
-rw-r--r--test/test_runner.hh8
2 files changed, 38 insertions, 8 deletions
diff --git a/test/test_runner.cc b/test/test_runner.cc
index 1aa74ab..523f950 100644
--- a/test/test_runner.cc
+++ b/test/test_runner.cc
@@ -19,12 +19,12 @@
*/
#include "test_runner.hh"
-
-#include "test_runner.hh"
#include "test_framework.hh"
+
#include <iostream>
#include <cstdlib>
#include <signal.h>
+#include <execinfo.h>
#include <unistd.h>
/** \file
@@ -35,13 +35,33 @@
using namespace test;
-/**
- * Called if we take too long.
- */
-void
-timeout_handler(int)
+namespace
+{
+ void do_backtrace()
+ {
+ void * bt[50];
+ size_t sz = backtrace(bt, 50);
+ char * * symbols = backtrace_symbols(bt, sz);
+
+ std::cerr << "Stack dump:" << std::endl;
+ for (unsigned n(0) ; n < sz ; ++n)
+ std::cerr << " * " << symbols[n] << std::endl;
+
+ std::free(symbols);
+ }
+}
+
+void timeout_handler(int)
{
- std::cerr << "Exiting due to timeout!" << std::endl;
+ std::cerr << std::endl << "Test aborted due to timeout!" << std::endl;
+ do_backtrace();
+ std::exit(EXIT_FAILURE);
+}
+
+void segfault_handler(int)
+{
+ std::cerr << std::endl << "Test aborted due to segmentation fault!" << std::endl;
+ do_backtrace();
std::exit(EXIT_FAILURE);
}
@@ -49,6 +69,8 @@ int
main(int, char * argv[])
{
signal(SIGALRM, &timeout_handler);
+ signal(SIGSEGV, &segfault_handler);
+
std::cout << "Test program " << argv[0] << ":" << std::endl;
return TestCaseList::run_tests() ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/test/test_runner.hh b/test/test_runner.hh
index d02787f..ba0ff01 100644
--- a/test/test_runner.hh
+++ b/test/test_runner.hh
@@ -21,6 +21,8 @@
#ifndef PALUDIS_GUARD_TEST_TEST_RUNNER_HH
#define PALUDIS_GUARD_TEST_TEST_RUNNER_HH 1
+#include <paludis/attributes.hh>
+
/** \file
* Declarations for the default test runner.
*/
@@ -28,4 +30,10 @@
/// Main program.
int main(int, char *[]);
+/// Called if we take too long.
+void timeout_handler(int) PALUDIS_ATTRIBUTE((noreturn));
+
+/// Called if we get a segfault.
+void segfault_handler(int) PALUDIS_ATTRIBUTE((noreturn));
+
#endif