-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathExecuteTestTimeout.cmake
More file actions
50 lines (41 loc) · 1.86 KB
/
ExecuteTestTimeout.cmake
File metadata and controls
50 lines (41 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
cmake_minimum_required(VERSION 3.2)
# Parse out arguments
foreach(_arg RANGE ${CMAKE_ARGC})
if(append)
list(APPEND arguments "${CMAKE_ARGV${_arg}}")
endif()
if("${CMAKE_ARGV${_arg}}" STREQUAL "-P")
set(append true)
message(status "found -P")
endif()
endforeach()
list(REMOVE_AT arguments 0)
message(STATUS "arguments: ${arguments}")
# Check if ENV variable TEST_TIMEOUT is set and use that rather than TIMEOUT_SECONDS
if(DEFINED ENV{TEST_TIMEOUT} AND NOT DEFINED FORCE_TIMEOUT_SECONDS)
message(STATUS "Overriding timeout: ${TIMEOUT_SECONDS} with $ENV{TEST_TIMEOUT}")
set(TIMEOUT_SECONDS $ENV{TEST_TIMEOUT})
endif()
# Check if FORCE_TIMEOUT_SECONDS is set, in that case respect that option
if(FORCE_TIMEOUT_SECONDS)
message(STATUS "Forcing timeout of ${FORCE_TIMEOUT_SECONDS} seconds")
set(TIMEOUT_SECONDS ${FORCE_TIMEOUT_SECONDS})
endif()
# Execute the example (SIGTERM for now, could be improved with SIGINT -> SIGKILL)
if(TIMEOUT_SECONDS GREATER 0)
execute_process(COMMAND ${arguments} TIMEOUT ${TIMEOUT_SECONDS} RESULT_VARIABLE error_variable)
else()
execute_process(COMMAND ${arguments} RESULT_VARIABLE error_variable)
endif()
message(STATUS "After process executed, ${PATH_TO_TEST_EXECUTABLE} produced the following exit code: ${error_variable}")
if(error_variable MATCHES "timeout" OR error_variable EQUAL 128 OR error_variable EQUAL 124)
# Okay
elseif(NOT error_variable)
# return code == 0, also okay
elseif(error_variable EQUAL 133 OR error_variable MATCHES "Child killed")
# sigkill, return fatal error but mark the issue
message(FATAL_ERROR "${PATH_TO_TEST_EXECUTABLE} had to be forcefully killed after 5 additional seconds after SIGINT")
else()
# not timeout and error code != 0, not okay
message(FATAL_ERROR "${PATH_TO_TEST_EXECUTABLE} produced an error (${error_variable}) while running")
endif()