Merge "Hard-abort tests if LOG_ALWAYS_FATAL"

This commit is contained in:
John Reck
2016-01-19 15:38:16 +00:00
committed by Android (Google) Code Review
2 changed files with 15 additions and 15 deletions

View File

@@ -21,7 +21,6 @@
#include <unistd.h>
#include <signal.h>
#include <setjmp.h>
namespace android {
namespace uirenderer {
@@ -129,11 +128,14 @@ static void defaultCrashHandler() {
fprintf(stderr, "RenderThread crashed!");
}
static jmp_buf gErrJmpBuff;
static std::function<void()> gCrashHandler = defaultCrashHandler;
static sighandler_t gPreviousSignalHandler;
static void signalHandler(int sig) {
longjmp(gErrJmpBuff, 1);
gCrashHandler();
if (gPreviousSignalHandler) {
gPreviousSignalHandler(sig);
}
}
void TestUtils::setRenderThreadCrashHandler(std::function<void()> crashHandler) {
@@ -141,17 +143,7 @@ void TestUtils::setRenderThreadCrashHandler(std::function<void()> crashHandler)
}
void TestUtils::TestTask::run() {
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = signalHandler;
if (setjmp(gErrJmpBuff)) {
gCrashHandler();
return;
}
sigaction(SIGABRT, &act, nullptr);
gPreviousSignalHandler = signal(SIGABRT, signalHandler);
// RenderState only valid once RenderThread is running, so queried here
RenderState& renderState = renderthread::RenderThread::getInstance().renderState();
@@ -159,6 +151,9 @@ void TestUtils::TestTask::run() {
renderState.onGLContextCreated();
rtCallback(renderthread::RenderThread::getInstance());
renderState.onGLContextDestroyed();
// Restore the previous signal handler
signal(SIGABRT, gPreviousSignalHandler);
}
} /* namespace uirenderer */

View File

@@ -17,11 +17,16 @@
#include "tests/common/TestUtils.h"
#include <gtest/gtest.h>
#include <cstdio>
using namespace android::uirenderer;
static void gunitCrashHandler() {
FAIL() << "RenderThread fatal exception!";
auto testinfo = ::testing::UnitTest::GetInstance()->current_test_info();
printf("[ FAILED ] %s.%s\n", testinfo->test_case_name(),
testinfo->name());
printf("[ FATAL! ] RenderThread crashed, aborting tests!\n");
fflush(stdout);
}
static void hookError() {