Skip to content

Commit 8e3caef

Browse files
test: add support for alarm in Windows ULT
Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent c7daa7a commit 8e3caef

File tree

7 files changed

+58
-3
lines changed

7 files changed

+58
-3
lines changed

opencl/test/unit_test/mock_gl/windows/mock_opengl32.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ BOOL WINAPI wglMakeCurrent(HDC arg1, HGLRC arg2) {
215215
}
216216
return (GLboolean)1;
217217
};
218-
PROC mockLoader(const char *name) {
218+
PROC __stdcall mockLoader(const char *name) {
219219
if (strcmp(name, "realFunction") == 0) {
220220
return reinterpret_cast<PROC>(*realFunction);
221221
}

opencl/test/unit_test/offline_compiler/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ int main(int argc, char **argv) {
217217
}
218218

219219
retVal = RUN_ALL_TESTS();
220+
cleanupSignals();
220221

221222
if (showTestStats) {
222223
std::cout << getTestStats() << std::endl;

opencl/test/unit_test/offline_compiler/segfault_test/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int main(int argc, char **argv) {
3131
return sigOut;
3232

3333
retVal = RUN_ALL_TESTS();
34+
cleanupSignals();
3435

3536
return retVal;
3637
}

shared/test/common/common_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ int main(int argc, char **argv) {
421421
Device::createPerformanceCountersFunc = [](Device *) -> std::unique_ptr<NEO::PerformanceCounters> { return {}; };
422422

423423
retVal = RUN_ALL_TESTS();
424+
cleanupSignals();
424425

425426
if (showTestStats) {
426427
std::cout << getTestStats() << std::endl;

shared/test/common/libult/signal_utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022 Intel Corporation
2+
* Copyright (C) 2022-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -12,3 +12,5 @@ int setAlarm(bool enableAlarm);
1212
int setSegv(bool enableSegv);
1313

1414
int setAbrt(bool enableAbrt);
15+
16+
void cleanupSignals();

shared/test/common/os_interface/linux/signal_utils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022 Intel Corporation
2+
* Copyright (C) 2022-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -131,3 +131,5 @@ int setSegv(bool enableSegv) {
131131
}
132132
return 0;
133133
}
134+
135+
void cleanupSignals() {}

shared/test/common/os_interface/windows/signal_utils.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@
1111

1212
#include "gtest/gtest.h"
1313

14+
#include <condition_variable>
1415
#include <io.h>
1516
#include <signal.h>
17+
#include <thread>
1618

1719
std::string lastTest("");
1820
static int newStdOut = -1;
1921

22+
namespace NEO {
23+
extern const char *executionName;
24+
extern unsigned int ultIterationMaxTime;
25+
} // namespace NEO
26+
27+
std::unique_ptr<std::thread> alarmThread;
28+
2029
LONG WINAPI ultExceptionFilter(
2130
_In_ struct _EXCEPTION_POINTERS *exceptionInfo) {
2231
std::cout << "UnhandledException: 0x" << std::hex << exceptionInfo->ExceptionRecord->ExceptionCode << std::dec
@@ -49,9 +58,48 @@ int setAbrt(bool enableAbrt) {
4958
}
5059

5160
int setAlarm(bool enableAlarm) {
61+
std::cout << "enable SIGALRM handler: " << enableAlarm << std::endl;
62+
63+
if (enableAlarm) {
64+
std::string envVar = std::string("NEO_") + NEO::executionName + "_DISABLE_TEST_ALARM";
65+
char *envValue = getenv(envVar.c_str());
66+
if (envValue != nullptr) {
67+
enableAlarm = false;
68+
std::cout << "WARNING: SIGALRM handler disabled by environment variable: " << envVar << std::endl;
69+
}
70+
}
71+
72+
if (enableAlarm) {
73+
std::condition_variable threadStarted;
74+
alarmThread = std::make_unique<std::thread>([&]() {
75+
auto currentUltIterationMaxTime = NEO::ultIterationMaxTime;
76+
auto ultIterationMaxTimeEnv = getenv("NEO_ULT_ITERATION_MAX_TIME");
77+
if (ultIterationMaxTimeEnv != nullptr) {
78+
currentUltIterationMaxTime = atoi(ultIterationMaxTimeEnv);
79+
}
80+
unsigned int alarmTime = currentUltIterationMaxTime * ::testing::GTEST_FLAG(repeat);
81+
std::cout << "set timeout to: " << alarmTime << std::endl;
82+
threadStarted.notify_all();
83+
std::this_thread::sleep_for(std::chrono::seconds(alarmTime));
84+
printf("timeout on %s\n", lastTest.c_str());
85+
abort();
86+
});
87+
88+
std::mutex mtx;
89+
std::unique_lock<std::mutex> lock(mtx);
90+
threadStarted.wait(lock);
91+
}
92+
5293
return 0;
5394
}
5495

5596
int setSegv(bool enableSegv) {
5697
return 0;
5798
}
99+
100+
void cleanupSignals() {
101+
if (alarmThread) {
102+
alarmThread->detach();
103+
alarmThread.reset();
104+
}
105+
}

0 commit comments

Comments
 (0)