Files
compute-runtime/shared/test/common/os_interface/linux/signal_utils.cpp
Baj, Tomasz 7daee00df4 Add alarmTime to ULTs
Signed-off-by: Baj, Tomasz <tomasz.baj@intel.com>
Related-To: NEO-6413
2022-01-31 13:51:57 +01:00

48 lines
1.3 KiB
C++

/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/libult/signal_utils.h"
#include "gtest/gtest.h"
#include <unistd.h>
std::string lastTest("");
namespace NEO {
extern const unsigned int ultIterationMaxTime;
}
void handleSIGALRM(int signal) {
std::cout << "Tests timeout on: " << lastTest << std::endl;
abort();
}
int setAlarm(bool enableAlarm) {
std::cout << "enable SIGALRM handler: " << enableAlarm << std::endl;
if (enableAlarm) {
auto currentUltIterationMaxTime = NEO::ultIterationMaxTime;
auto ultIterationMaxTimeEnv = getenv("NEO_ULT_ITERATION_MAX_TIME");
if (ultIterationMaxTimeEnv != nullptr) {
currentUltIterationMaxTime = atoi(ultIterationMaxTimeEnv);
}
unsigned int alarmTime = currentUltIterationMaxTime * ::testing::GTEST_FLAG(repeat);
struct sigaction sa;
sa.sa_handler = &handleSIGALRM;
sa.sa_flags = SA_RESTART;
sigfillset(&sa.sa_mask);
if (sigaction(SIGALRM, &sa, NULL) == -1) {
std::cout << "FATAL ERROR: cannot intercept SIGALRM" << std::endl;
return -2;
}
alarm(alarmTime);
std::cout << "set timeout to: " << alarmTime << std::endl;
}
return 0;
}