From f1dafb5962e798a02417b5a2075b6dcc318561ab Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 15 Jan 2016 16:57:26 -0800 Subject: [PATCH] Hard-abort tests if LOG_ALWAYS_FATAL Bug: 26591625 Also fixes it so debuggerd runs and we get stacks Change-Id: I55b376e6a4e12ddcd21fa251fbfe5bd521fc0985 --- libs/hwui/tests/common/TestUtils.cpp | 23 ++++++++----------- libs/hwui/tests/unit/CrashHandlerInjector.cpp | 7 +++++- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libs/hwui/tests/common/TestUtils.cpp b/libs/hwui/tests/common/TestUtils.cpp index d56693ce70093..5ed7aa4640262 100644 --- a/libs/hwui/tests/common/TestUtils.cpp +++ b/libs/hwui/tests/common/TestUtils.cpp @@ -21,7 +21,6 @@ #include #include -#include namespace android { namespace uirenderer { @@ -129,11 +128,14 @@ static void defaultCrashHandler() { fprintf(stderr, "RenderThread crashed!"); } -static jmp_buf gErrJmpBuff; static std::function gCrashHandler = defaultCrashHandler; +static sighandler_t gPreviousSignalHandler; static void signalHandler(int sig) { - longjmp(gErrJmpBuff, 1); + gCrashHandler(); + if (gPreviousSignalHandler) { + gPreviousSignalHandler(sig); + } } void TestUtils::setRenderThreadCrashHandler(std::function crashHandler) { @@ -141,17 +143,7 @@ void TestUtils::setRenderThreadCrashHandler(std::function 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 */ diff --git a/libs/hwui/tests/unit/CrashHandlerInjector.cpp b/libs/hwui/tests/unit/CrashHandlerInjector.cpp index 685c26490a1af..b1c678d1c6faf 100644 --- a/libs/hwui/tests/unit/CrashHandlerInjector.cpp +++ b/libs/hwui/tests/unit/CrashHandlerInjector.cpp @@ -17,11 +17,16 @@ #include "tests/common/TestUtils.h" #include +#include 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() {