2022-01-14 13:51:20 +00:00
|
|
|
/*
|
2023-10-20 14:34:45 +00:00
|
|
|
* Copyright (C) 2022-2023 Intel Corporation
|
2022-01-14 13:51:20 +00:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "shared/test/common/libult/signal_utils.h"
|
|
|
|
|
|
2023-10-20 14:34:45 +00:00
|
|
|
#include "shared/source/os_interface/windows/windows_wrapper.h"
|
|
|
|
|
|
2022-01-14 13:51:20 +00:00
|
|
|
#include "gtest/gtest.h"
|
2022-02-01 09:20:45 +00:00
|
|
|
|
2022-08-18 15:56:59 +00:00
|
|
|
#include <io.h>
|
2022-02-01 09:20:45 +00:00
|
|
|
#include <signal.h>
|
2022-01-14 13:51:20 +00:00
|
|
|
|
|
|
|
|
std::string lastTest("");
|
2022-08-18 15:56:59 +00:00
|
|
|
static int newStdOut = -1;
|
2022-01-14 13:51:20 +00:00
|
|
|
|
2022-02-01 09:20:45 +00:00
|
|
|
LONG WINAPI UltExceptionFilter(
|
|
|
|
|
_In_ struct _EXCEPTION_POINTERS *exceptionInfo) {
|
|
|
|
|
std::cout << "UnhandledException: 0x" << std::hex << exceptionInfo->ExceptionRecord->ExceptionCode << std::dec
|
|
|
|
|
<< " on test: " << lastTest << std::endl;
|
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void (*oldSigAbrt)(int) = nullptr;
|
|
|
|
|
void handleSIGABRT(int sigNo) {
|
2022-08-18 15:56:59 +00:00
|
|
|
if (newStdOut != -1) {
|
|
|
|
|
_dup2(newStdOut, 1);
|
|
|
|
|
}
|
2022-02-01 09:20:45 +00:00
|
|
|
std::cout << "SIGABRT on: " << lastTest << std::endl;
|
|
|
|
|
signal(SIGABRT, oldSigAbrt);
|
|
|
|
|
raise(sigNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int setAbrt(bool enableAbrt) {
|
|
|
|
|
std::cout << "enable SIGABRT handler: " << enableAbrt << std::endl;
|
|
|
|
|
|
2022-08-18 15:56:59 +00:00
|
|
|
if (newStdOut == -1) {
|
|
|
|
|
newStdOut = _dup(1);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 09:20:45 +00:00
|
|
|
SetUnhandledExceptionFilter(&UltExceptionFilter);
|
|
|
|
|
if (enableAbrt) {
|
|
|
|
|
oldSigAbrt = signal(SIGABRT, handleSIGABRT);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-14 13:51:20 +00:00
|
|
|
int setAlarm(bool enableAlarm) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2022-02-01 09:20:45 +00:00
|
|
|
|
|
|
|
|
int setSegv(bool enableSegv) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|