11/*
2- * Copyright (C) 2018-2021 Intel Corporation
2+ * Copyright (C) 2018-2022 Intel Corporation
33 *
44 * SPDX-License-Identifier: MIT
55 *
1818#include " shared/test/common/helpers/test_files.h"
1919#include " shared/test/common/helpers/ult_hw_config.inl"
2020#include " shared/test/common/libult/global_environment.h"
21+ #include " shared/test/common/libult/signal_utils.h"
2122#include " shared/test/common/mocks/mock_gmm.h"
2223#include " shared/test/common/mocks/mock_gmm_client_context.h"
2324#include " shared/test/common/mocks/mock_sip.h"
@@ -50,7 +51,6 @@ extern const char *hardwarePrefix[];
5051extern const HardwareInfo *hardwareInfoTable[IGFX_MAX_PRODUCT];
5152extern const char *executionName;
5253
53- extern const unsigned int ultIterationMaxTime;
5454extern bool useMockGmm;
5555extern TestMode testMode;
5656extern const char *executionDirectorySuffix;
@@ -118,10 +118,6 @@ void applyWorkarounds() {
118118 }
119119}
120120#ifdef __linux__
121- void handle_SIGALRM (int signal) {
122- std::cout << " Tests timeout on: " << lastTest << std::endl;
123- abort ();
124- }
125121void handle_SIGSEGV (int signal) {
126122 std::cout << " SIGSEGV on: " << lastTest << std::endl;
127123 abort ();
@@ -193,7 +189,7 @@ std::string getRunPath(char *argv0) {
193189int main (int argc, char **argv) {
194190 int retVal = 0 ;
195191 bool useDefaultListener = false ;
196- bool enable_alarm = true ;
192+ bool enableAlarm = true ;
197193 bool enable_abrt = true ;
198194 bool setupFeatureTableAndWorkaroundTable = testMode == TestMode::AubTests ? true : false ;
199195 bool showTestStats = false ;
@@ -223,7 +219,7 @@ int main(int argc, char **argv) {
223219 std::string envVar = std::string (" NEO_" ) + executionName + " _DISABLE_TEST_ALARM" ;
224220 char *envValue = getenv (envVar.c_str ());
225221 if (envValue != nullptr ) {
226- enable_alarm = false ;
222+ enableAlarm = false ;
227223 }
228224 }
229225
@@ -242,7 +238,7 @@ int main(int argc, char **argv) {
242238 } else if (!strcmp (" --enable_default_listener" , argv[i])) {
243239 useDefaultListener = true ;
244240 } else if (!strcmp (" --disable_alarm" , argv[i])) {
245- enable_alarm = false ;
241+ enableAlarm = false ;
246242 } else if (!strcmp (" --show_test_stats" , argv[i])) {
247243 showTestStats = true ;
248244 } else if (!strcmp (" --disable_pagefaulting_tests" , argv[i])) { // disable tests which raise page fault signal during execution
@@ -433,32 +429,14 @@ int main(int argc, char **argv) {
433429 gEnvironment ->setMockFileNames (fclDebugVars.fileName , igcDebugVars.fileName );
434430 gEnvironment ->setDefaultDebugVars (fclDebugVars, igcDebugVars, hwInfoForTests);
435431
432+ int sigOut = setAlarm (enableAlarm);
433+ if (sigOut != 0 )
434+ return sigOut;
435+
436436#if defined(__linux__)
437- std::cout << " enable SIGALRM handler: " << enable_alarm << std::endl;
438437 std::cout << " enable SIGSEGV handler: " << enable_segv << std::endl;
439438 std::cout << " enable SIGABRT handler: " << enable_abrt << std::endl;
440439
441- // ULTs timeout
442- if (enable_alarm) {
443- auto currentUltIterationMaxTime = NEO::ultIterationMaxTime;
444- auto ultIterationMaxTimeEnv = getenv (" NEO_ULT_ITERATION_MAX_TIME" );
445- if (ultIterationMaxTimeEnv != nullptr ) {
446- currentUltIterationMaxTime = atoi (ultIterationMaxTimeEnv);
447- }
448- unsigned int alarmTime = currentUltIterationMaxTime * ::testing::GTEST_FLAG (repeat);
449-
450- struct sigaction sa;
451- sa.sa_handler = &handle_SIGALRM;
452- sa.sa_flags = SA_RESTART;
453- sigfillset (&sa.sa_mask );
454- if (sigaction (SIGALRM, &sa, NULL ) == -1 ) {
455- printf (" FATAL ERROR: cannot intercept SIGALRM\n " );
456- return -2 ;
457- }
458- alarm (alarmTime);
459- std::cout << " set timeout to: " << alarmTime << std::endl;
460- }
461-
462440 if (enable_segv) {
463441 struct sigaction sa;
464442 sa.sa_handler = &handle_SIGSEGV;
0 commit comments