Install stack trace handlers in unit tests
Summary: Sometimes, our tests fail because of normal `assert` call. It would be helpful to see stack trace in that case, too. Test Plan: Added `assert(false)` and verified it prints out stack trace Reviewers: haobo, dhruba, sdong, ljin, yhchiang Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D18291
This commit is contained in:
parent
a40970aa31
commit
fc3127e8de
@ -23,6 +23,7 @@ void PrintStack(int first_frames_to_skip) {}
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <cxxabi.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -69,9 +70,17 @@ void PrintStackTraceLine(const char* symbol, void* frame) {
|
|||||||
#elif OS_MACOSX
|
#elif OS_MACOSX
|
||||||
|
|
||||||
void PrintStackTraceLine(const char* symbol, void* frame) {
|
void PrintStackTraceLine(const char* symbol, void* frame) {
|
||||||
// TODO(icanadi) demangle
|
|
||||||
if (symbol) {
|
if (symbol) {
|
||||||
fprintf(stderr, "%s ", symbol);
|
char filename[64], function[512], plus[2], line[10];
|
||||||
|
sscanf(symbol, "%*s %64s %*s %512s %2s %10s", filename, function, plus,
|
||||||
|
line);
|
||||||
|
int status;
|
||||||
|
char* demangled = abi::__cxa_demangle(function, 0, 0, &status);
|
||||||
|
fprintf(stderr, "%s %s %s %s", filename,
|
||||||
|
(status == 0) ? demangled : function, plus, line);
|
||||||
|
if (demangled) {
|
||||||
|
free(demangled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, " %p", frame);
|
fprintf(stderr, " %p", frame);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
@ -111,8 +120,6 @@ void InstallStackTraceHandler() {
|
|||||||
signal(SIGSEGV, StackTraceHandler);
|
signal(SIGSEGV, StackTraceHandler);
|
||||||
signal(SIGBUS, StackTraceHandler);
|
signal(SIGBUS, StackTraceHandler);
|
||||||
signal(SIGABRT, StackTraceHandler);
|
signal(SIGABRT, StackTraceHandler);
|
||||||
|
|
||||||
printf("Installed stack trace handler for SIGILL SIGSEGV SIGBUS SIGABRT\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||||
|
|
||||||
#include "util/testharness.h"
|
#include "util/testharness.h"
|
||||||
|
#include "port/stack_trace.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -39,6 +40,8 @@ bool RegisterTest(const char* base, const char* name, void (*func)()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int RunAllTests() {
|
int RunAllTests() {
|
||||||
|
port::InstallStackTraceHandler();
|
||||||
|
|
||||||
const char* matcher = getenv("ROCKSDB_TESTS");
|
const char* matcher = getenv("ROCKSDB_TESTS");
|
||||||
|
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user