Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7d569db9 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Hard-abort tests if LOG_ALWAYS_FATAL"

parents 6f959538 f1dafb59
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -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 */
+6 −1
Original line number Diff line number Diff line
@@ -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() {