make tests catch fatal signals and present a nice stack for the error

This commit is contained in:
Arvid Norberg 2012-04-21 05:54:49 +00:00
parent ecb9b2b725
commit 3cf7d0a7a2
1 changed files with 30 additions and 0 deletions

View File

@ -39,6 +39,29 @@ int test_main();
extern bool tests_failure;
#include "libtorrent/assert.hpp"
#include <signal.h>
void sig_handler(int sig)
{
char stack_text[10000];
print_backtrace(stack_text, sizeof(stack_text), 30);
char const* sig_name = 0;
switch (sig)
{
#define SIG(x) case x: sig_name = #x; break
SIG(SIGSEGV);
SIG(SIGBUS);
SIG(SIGILL);
SIG(SIGABRT);
SIG(SIGFPE);
SIG(SIGSYS);
#undef SIG
};
fprintf(stderr, "signal: %s caught:\n%s\n", sig_name, stack_text);
exit(138);
}
int main()
{
#ifdef O_NONBLOCK
@ -51,6 +74,13 @@ int main()
fcntl(fileno(stderr), F_SETFL, flags & ~O_NONBLOCK);
#endif
signal(SIGSEGV, &sig_handler);
signal(SIGBUS, &sig_handler);
signal(SIGILL, &sig_handler);
signal(SIGABRT, &sig_handler);
signal(SIGFPE, &sig_handler);
signal(SIGSYS, &sig_handler);
#ifndef BOOST_NO_EXCEPTIONS
try
{