-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathO2AddTestWrapper.cmake
More file actions
145 lines (128 loc) · 4.39 KB
/
O2AddTestWrapper.cmake
File metadata and controls
145 lines (128 loc) · 4.39 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright CERN and copyright holders of ALICE O2. This software is distributed
# under the terms of the GNU General Public License v3 (GPL Version 3), copied
# verbatim in the file "COPYING".
#
# See http://alice-o2.web.cern.ch/license for full licensing information.
#
# In applying this license CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization or
# submit itself to any jurisdiction.
include_guard()
#
# o2_add_test_wrapper
#
# Same as o2_add_test() but optionally retry up to MAX_ATTEMPTS times upon
# failure. This is achieved by using a shell script wrapper.
#
# * TARGET or COMMAND (required) is either a target name or the full path to the
# executable to be wrapped
#
# * NAME (optional): the test name. If not present it is derived from the
# target name (if TARGET was used) or from the executable name (if COMMAND was
# given)
#
# * WORKING_DIRECTORY (optional) the wrapper will cd into this directory before
# running the executable
# * DONT_FAIL_ON_TIMEOUT (optional) indicate the test will not fail on timeouts
# * MAX_ATTEMPTS (optional) the maximum number of attempts
# * TIMEOUT (optional) the test timeout (for each attempt)
# * COMMAND_LINE_ARGS (optional) extra arguments to the test executable, if
# needed
# * ENVIRONMENT: extra environment needed by the test to run properly
#
function(o2_add_test_wrapper)
if(NOT BUILD_TESTING)
return()
endif()
cmake_parse_arguments(
PARSE_ARGV
0
"A"
"DONT_FAIL_ON_TIMEOUT"
"TARGET;COMMAND;WORKING_DIRECTORY;MAX_ATTEMPTS;TIMEOUT;NAME"
"COMMAND_LINE_ARGS;LABELS;CONFIGURATIONS;ENVIRONMENT")
if(A_UNPARSED_ARGUMENTS)
message(
FATAL_ERROR "Unexpected unparsed arguments: ${A_UNPARSED_ARGUMENTS}")
endif()
if(A_TARGET AND A_COMMAND)
message(FATAL_ERROR "Should only use one of COMMAND or TARGET")
endif()
if(NOT A_TARGET AND NOT A_COMMAND)
message(FATAL_ERROR "Must give at least one of COMMAND or TARGET")
endif()
if(A_TARGET)
if(NOT TARGET ${A_TARGET})
message(FATAL_ERROR "${A_TARGET} is not a target")
endif()
set(testExe $<TARGET_FILE:${A_TARGET}>)
endif()
if(A_COMMAND)
set(testExe ${A_COMMAND})
endif()
if(A_NAME)
set(testName "${A_NAME}")
else()
if(A_COMMAND)
get_filename_component(testName ${testExe} NAME_WE)
else()
set(testName ${A_TARGET})
endif()
endif()
# if("${A_MAX_ATTEMPTS}" GREATER 1)
# # Warn only for tests where retry has been requested
# message(
# WARNING "Test ${testName} will be retried max ${A_MAX_ATTEMPTS} times")
# endif()
if(NOT A_TIMEOUT)
set(A_TIMEOUT 100) # default timeout (seconds)
endif()
if(NOT A_MAX_ATTEMPTS)
set(A_MAX_ATTEMPTS 1) # default number of attempts
endif()
if(A_DONT_FAIL_ON_TIMEOUT)
set(A_DONT_FAIL_ON_TIMEOUT "--dont-fail-on-timeout")
else()
set(A_DONT_FAIL_ON_TIMEOUT "")
endif()
# For now, we enforce 3 max attempts for all tests.
# No need to ignore time out, since we have 3 attempts
set(A_MAX_ATTEMPTS 3)
set(A_DONT_FAIL_ON_TIMEOUT "")
math(EXPR ctestTimeout "(20 + ${A_TIMEOUT}) * ${A_MAX_ATTEMPTS}")
if(NOT A_WORKING_DIRECTORY)
if(DEFINED DEFAULT_TEST_OUTPUT_DIRECTORY)
string(REPLACE "${CMAKE_BINARY_DIR}" "" reldir "${CMAKE_CURRENT_BINARY_DIR}")
get_filename_component(wdir ${DEFAULT_TEST_OUTPUT_DIRECTORY}/${reldir} REALPATH)
file(MAKE_DIRECTORY ${wdir})
message(
STATUS
"test ${testName} will output in ${wdir}"
)
set(A_WORKING_DIRECTORY ${wdir})
endif()
endif()
add_test(NAME "${testName}"
COMMAND "${CMAKE_BINARY_DIR}/tests-wrapper.sh"
"--name"
"${testName}"
"--max-attempts"
"${A_MAX_ATTEMPTS}"
"--timeout"
"${A_TIMEOUT}"
${A_DONT_FAIA_ON_TIMEOUT}
"--"
${testExe}
${A_COMMAND_LINE_ARGS}
WORKING_DIRECTORY "${A_WORKING_DIRECTORY}"
CONFIGURATIONS ${A_CONFIGURATIONS})
set_tests_properties(${testName} PROPERTIES TIMEOUT ${ctestTimeout})
if(A_LABELS)
foreach(A IN LISTS A_LABELS)
set_property(TEST ${testName} APPEND PROPERTY LABELS ${A})
endforeach()
endif()
if(A_ENVIRONMENT)
set_tests_properties(${testName} PROPERTIES ENVIRONMENT ${A_ENVIRONMENT})
endif()
endfunction()