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() {