testlib: Implement FatalSignalHandler inline
Change-Id: Ie6f151cb099151616f83ea8d5e11e6625bedeb8c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
89f443dfbc
commit
d005d743de
@ -1534,43 +1534,12 @@ void TestMethods::invokeTests(QObject *testObject) const
|
||||
}
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
|
||||
|
||||
class FatalSignalHandler
|
||||
{
|
||||
public:
|
||||
FatalSignalHandler();
|
||||
~FatalSignalHandler();
|
||||
|
||||
private:
|
||||
static void signal(int);
|
||||
sigset_t handledSignals;
|
||||
};
|
||||
|
||||
void FatalSignalHandler::signal(int signum)
|
||||
{
|
||||
const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime());
|
||||
const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
|
||||
if (signum != SIGINT) {
|
||||
stackTrace();
|
||||
if (qEnvironmentVariableIsSet("QTEST_PAUSE_ON_CRASH")) {
|
||||
fprintf(stderr, "Pausing process %d for debugging\n", getpid());
|
||||
raise(SIGSTOP);
|
||||
}
|
||||
}
|
||||
qFatal("Received signal %d\n"
|
||||
" Function time: %dms Total time: %dms",
|
||||
signum, msecsFunctionTime, msecsTotalTime);
|
||||
#if defined(Q_OS_INTEGRITY)
|
||||
FatalSignalHandler()
|
||||
{
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(struct sigaction));
|
||||
act.sa_handler = SIG_DFL;
|
||||
sigaction(signum, &act, NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
FatalSignalHandler::FatalSignalHandler()
|
||||
{
|
||||
sigemptyset(&handledSignals);
|
||||
|
||||
const int fatalSignals[] = {
|
||||
@ -1585,8 +1554,8 @@ FatalSignalHandler::FatalSignalHandler()
|
||||
act.sa_flags = SA_RESETHAND;
|
||||
#endif
|
||||
|
||||
// tvOS/watchOS both define SA_ONSTACK (in sys/signal.h) but mark sigaltstack() as
|
||||
// unavailable (__WATCHOS_PROHIBITED __TVOS_PROHIBITED in signal.h)
|
||||
// tvOS/watchOS both define SA_ONSTACK (in sys/signal.h) but mark sigaltstack() as
|
||||
// unavailable (__WATCHOS_PROHIBITED __TVOS_PROHIBITED in signal.h)
|
||||
#if defined(SA_ONSTACK) && !defined(Q_OS_TVOS) && !defined(Q_OS_WATCHOS)
|
||||
// Let the signal handlers use an alternate stack
|
||||
// This is necessary if SIGSEGV is to catch a stack overflow
|
||||
@ -1625,11 +1594,10 @@ FatalSignalHandler::FatalSignalHandler()
|
||||
sigaddset(&handledSignals, fatalSignals[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FatalSignalHandler::~FatalSignalHandler()
|
||||
{
|
||||
~FatalSignalHandler()
|
||||
{
|
||||
// Unregister any of our remaining signal handlers
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(act));
|
||||
@ -1646,11 +1614,38 @@ FatalSignalHandler::~FatalSignalHandler()
|
||||
if (oldact.sa_handler != FatalSignalHandler::signal)
|
||||
sigaction(i, &oldact, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static void signal(int signum)
|
||||
{
|
||||
const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime());
|
||||
const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
|
||||
if (signum != SIGINT) {
|
||||
stackTrace();
|
||||
if (qEnvironmentVariableIsSet("QTEST_PAUSE_ON_CRASH")) {
|
||||
fprintf(stderr, "Pausing process %d for debugging\n", getpid());
|
||||
raise(SIGSTOP);
|
||||
}
|
||||
}
|
||||
qFatal("Received signal %d\n"
|
||||
" Function time: %dms Total time: %dms",
|
||||
signum, msecsFunctionTime, msecsTotalTime);
|
||||
#if defined(Q_OS_INTEGRITY)
|
||||
{
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(struct sigaction));
|
||||
act.sa_handler = SIG_DFL;
|
||||
sigaction(signum, &act, NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
sigset_t handledSignals;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
|
||||
|
Loading…
x
Reference in New Issue
Block a user