forked from ros2/system_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
395 lines (351 loc) · 13.9 KB
/
CMakeLists.txt
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
cmake_minimum_required(VERSION 3.5)
project(test_rclcpp)
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
find_package(ament_cmake REQUIRED)
if(BUILD_TESTING)
find_package(rclcpp REQUIRED)
set(ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS ${rclcpp_INCLUDE_DIRS})
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
find_package(launch_testing_ament_cmake REQUIRED)
set(message_files
"msg/UInt32.msg"
)
set(service_files
"srv/AddTwoInts.srv"
)
rosidl_generate_interfaces(${PROJECT_NAME}
${message_files}
${service_files}
SKIP_INSTALL
)
# get the rmw implementations ahead of time
find_package(rmw_implementation_cmake REQUIRED)
get_available_rmw_implementations(rmw_implementations)
foreach(rmw_implementation ${rmw_implementations})
find_package("${rmw_implementation}" REQUIRED)
endforeach()
macro(custom_gtest target)
ament_add_gtest(${target}${target_suffix} ${ARGN}
APPEND_LIBRARY_DIRS "${append_library_dirs}"
ENV
RCL_ASSERT_RMW_ID_MATCHES=${rmw_implementation}
RMW_IMPLEMENTATION=${rmw_implementation})
if(TARGET ${target}${target_suffix})
target_compile_definitions(${target}${target_suffix}
PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}")
rosidl_target_interfaces(${target}${target_suffix}
${PROJECT_NAME} "rosidl_typesupport_cpp")
ament_target_dependencies(${target}${target_suffix}
"rclcpp")
target_include_directories(${target}${target_suffix} PUBLIC include)
endif()
endmacro()
function(custom_executable target)
add_executable(${target} ${ARGN})
target_compile_definitions(${target}
PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}")
rosidl_target_interfaces(${target}
${PROJECT_NAME} "rosidl_typesupport_cpp")
ament_target_dependencies(${target}
"rclcpp")
endfunction()
function(custom_gtest_executable target)
ament_add_gtest_executable(${target} ${ARGN})
target_compile_definitions(${target}
PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}")
rosidl_target_interfaces(${target}
${PROJECT_NAME} "rosidl_typesupport_cpp")
ament_target_dependencies(${target}
"rclcpp")
endfunction()
macro(custom_launch_test_two_executables test_name executable1 executable2)
cmake_parse_arguments(_ARG "" "ARGS1;ARGS2;RMW1;RMW2" "" ${ARGN})
set(TEST_NAME "${test_name}")
set(TEST_EXECUTABLE1 "$<TARGET_FILE:${executable1}>")
set(TEST_EXECUTABLE1_ARGS "${_ARG_ARGS1}")
set(TEST_EXECUTABLE1_NAME "${executable1}")
set(TEST_RMW_IMPLEMENTATION1 "${_ARG_RMW1}")
set(TEST_EXECUTABLE2 "$<TARGET_FILE:${executable2}>")
set(TEST_EXECUTABLE2_ARGS "${_ARG_ARGS2}")
set(TEST_EXECUTABLE2_NAME "${executable2}")
set(TEST_RMW_IMPLEMENTATION2 "${_ARG_RMW2}")
configure_file(
test/test_two_executables.py.in
${test_name}${target_suffix}.py.configure
@ONLY
)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${test_name}${target_suffix}_$<CONFIG>.py"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/${test_name}${target_suffix}.py.configure"
)
add_launch_test(
"${CMAKE_CURRENT_BINARY_DIR}/${test_name}${target_suffix}_$<CONFIG>.py"
TARGET "${test_name}${target_suffix}"
APPEND_LIBRARY_DIRS "${append_library_dirs}"
${_ARG_UNPARSED_ARGUMENTS}
)
if(TEST ${test_name}${target_suffix})
set_tests_properties(${test_name}${target_suffix}
PROPERTIES DEPENDS "${executable1}${target_suffix} ${executable2}${target_suffix}"
)
endif()
endmacro()
macro(custom_launch_n_nodes num_nodes)
set(TEST_EXECUTABLE1 "$<TARGET_FILE:node_with_name>")
set(TEST_EXECUTABLE2 "$<TARGET_FILE:node_check_names>")
set(TEST_RMW_IMPLEMENTATION "${rmw_implementation}")
set(TEST_NUM_NODES "${num_nodes}")
configure_file(
test/test_n_nodes.py.in
test_n_nodes${target_suffix}.py.configure
@ONLY
)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_n_nodes${target_suffix}_$<CONFIG>.py"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/test_n_nodes${target_suffix}.py.configure"
)
add_launch_test(
"${CMAKE_CURRENT_BINARY_DIR}/test_n_nodes${target_suffix}_$<CONFIG>.py"
TARGET test_n_nodes${target_suffix}
APPEND_LIBRARY_DIRS "${append_library_dirs}"
${_ARG_UNPARSED_ARGUMENTS}
)
if(TEST test_n_nodes${target_suffix})
set_tests_properties(test_n_nodes${target_suffix}
PROPERTIES DEPENDS "node_with_name${target_suffix} node_check_names${target_suffix}"
)
endif()
endmacro()
# Macro for tests that trigger the shutdown of an executable based on particular console output,
# then check the output of the executable against different console output.
macro(custom_launch_test_executable_output test_name executable)
set(TEST_NAME "${test_name}")
set(TEST_EXECUTABLE "$<TARGET_FILE:${executable}>")
set(TEST_EXECUTABLE_NAME "${executable}")
set(TEST_EXECUTABLE_TRIGGER_SHUTDOWN_OUTPUT
"${CMAKE_CURRENT_SOURCE_DIR}/test/${test_name}__trigger_shutdown")
set(TEST_EXECUTABLE_EXPECTED_OUTPUT
"${CMAKE_CURRENT_SOURCE_DIR}/test/${test_name}__expected_output")
configure_file(
test/test_executable_output.py.in
${test_name}${target_suffix}.py.configure
@ONLY
)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${test_name}${target_suffix}_$<CONFIG>.py"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/${test_name}${target_suffix}.py.configure"
)
add_launch_test(
"${CMAKE_CURRENT_BINARY_DIR}/${test_name}${target_suffix}_$<CONFIG>.py"
TARGET ${test_name}${target_suffix}
${ARGN}
APPEND_LIBRARY_DIRS "${append_library_dirs}"
ENV
RCL_ASSERT_RMW_ID_MATCHES=${rmw_implementation}
RMW_IMPLEMENTATION=${rmw_implementation}
)
if(TEST ${test_name}${target_suffix})
set_tests_properties(${test_name}${target_suffix}
PROPERTIES DEPENDS "${executable}${target_suffix}"
)
endif()
endmacro()
macro(cross_rmw_tests)
# test node names cross rmw
if(rmw_implementation1 STREQUAL rmw_implementation2)
set(target_suffix "__${rmw_implementation1}")
else()
set(target_suffix "__${rmw_implementation1}__${rmw_implementation2}")
endif()
set(rmw_implementation1_is_fastrtps FALSE)
set(rmw_implementation2_is_fastrtps FALSE)
if(rmw_implementation1 MATCHES "(.*)fastrtps(.*)")
set(rmw_implementation1_is_fastrtps TRUE)
endif()
if(rmw_implementation2 MATCHES "(.*)fastrtps(.*)")
set(rmw_implementation2_is_fastrtps TRUE)
endif()
set(rmw_implementation1_is_connext FALSE)
set(rmw_implementation2_is_connext FALSE)
if(rmw_implementation1 MATCHES "(.*)connext(.*)")
set(rmw_implementation1_is_connext TRUE)
endif()
if(rmw_implementation2 MATCHES "(.*)connext(.*)")
set(rmw_implementation2_is_connext TRUE)
endif()
set(rmw_implementation1_is_cyclonedds FALSE)
set(rmw_implementation2_is_cyclonedds FALSE)
if(rmw_implementation1 MATCHES "(.*)cyclonedds(.*)")
set(rmw_implementation1_is_cyclonedds TRUE)
endif()
if(rmw_implementation2 MATCHES "(.*)cyclonedds(.*)")
set(rmw_implementation2_is_cyclonedds TRUE)
endif()
# Whitelist cross-vendor tests
if(NOT (rmw_implementation1 STREQUAL rmw_implementation2))
# TODO(sloretz) enable connext/cyclone/fastrtps when all three use 1 participant per context
if(
(rmw_implementation1_is_fastrtps AND rmw_implementation2_is_cyclonedds) OR
(rmw_implementation1_is_cyclonedds AND rmw_implementation2_is_fastrtps) OR
(rmw_implementation1_is_fastrtps AND rmw_implementation2_is_fastrtps)
)
# Whitelisted cross-vendor tests
set(_crt_SKIP_TEST ${SKIP_TEST})
else()
# Default skip cross-vendor tests
set(_crt_SKIP_TEST "SKIP_TEST")
endif()
else()
# Same vendor tests always allowed
set(_crt_SKIP_TEST ${SKIP_TEST})
endif()
custom_launch_test_two_executables(test_node_name
node_with_name node_name_list
ARGS1 "${rmw_implementation1}" ARGS2 "node_with_name_${rmw_implementation1}"
RMW1 ${rmw_implementation1} RMW2 ${rmw_implementation2}
TIMEOUT 15
${_crt_SKIP_TEST})
endmacro()
macro(targets)
custom_gtest(gtest_publisher
"test/test_publisher.cpp"
TIMEOUT 15)
custom_gtest(gtest_avoid_ros_namespace_conventions_qos
"test/test_avoid_ros_namespace_conventions_qos.cpp"
TIMEOUT 15)
custom_gtest(gtest_client_wait_for_service_shutdown
"test/test_client_wait_for_service_shutdown.cpp"
TIMEOUT 15)
custom_gtest(gtest_executor
"test/test_executor.cpp"
TIMEOUT 60)
custom_gtest(gtest_repeated_publisher_subscriber
"test/test_repeated_publisher_subscriber.cpp"
TIMEOUT 15)
custom_gtest(gtest_spin
"test/test_spin.cpp"
TIMEOUT 30)
custom_gtest(gtest_subscription
"test/test_subscription.cpp"
TIMEOUT 60)
custom_gtest(gtest_multiple_service_calls
"test/test_multiple_service_calls.cpp"
TIMEOUT 60)
custom_gtest(gtest_timer
"test/test_timer.cpp"
TIMEOUT 30)
custom_gtest(gtest_timeout_subscriber
"test/test_timeout_subscriber.cpp"
TIMEOUT 30)
custom_gtest(gtest_intra_process
"test/test_intra_process.cpp"
TIMEOUT 15)
custom_gtest(gtest_multithreaded
"test/test_multithreaded.cpp"
TIMEOUT 90)
custom_gtest(gtest_local_parameters
"test/test_local_parameters.cpp"
TIMEOUT 300)
custom_gtest(gtest_services_in_constructor
"test/test_services_in_constructor.cpp"
TIMEOUT 30)
custom_gtest(gtest_waitable
"test/test_waitable.cpp"
TIMEOUT 30)
# Parameter tests single implementation
custom_launch_test_two_executables(test_parameter_server_cpp
test_parameters_server_cpp test_remote_parameters_cpp
ENV
RCL_ASSERT_RMW_ID_MATCHES=${rmw_implementation}
RMW_IMPLEMENTATION=${rmw_implementation}
TIMEOUT 60)
if(rmw_implementation STREQUAL "rmw_cyclonedds_cpp")
# TODO(tfoote) Disable this tests on CI as it's being flakey
# This should be removed when https://github.com/ros2/rmw_cyclonedds/issues/183 is resolved.
ament_add_test_label(test_parameter_server_cpp${target_suffix} xfail)
endif()
# Service tests single implementation
custom_launch_test_two_executables(test_services_cpp
test_services_server_cpp test_services_client_cpp
ENV
RCL_ASSERT_RMW_ID_MATCHES=${rmw_implementation}
RMW_IMPLEMENTATION=${rmw_implementation}
TIMEOUT 60)
custom_launch_test_two_executables(test_client_scope_cpp
test_client_scope_server_cpp test_client_scope_client_cpp
ENV
RCL_ASSERT_RMW_ID_MATCHES=${rmw_implementation}
RMW_IMPLEMENTATION=${rmw_implementation}
TIMEOUT 60)
custom_launch_test_two_executables(test_client_scope_consistency_cpp
test_client_scope_consistency_server_cpp test_client_scope_consistency_client_cpp
ENV
RCL_ASSERT_RMW_ID_MATCHES=${rmw_implementation}
RMW_IMPLEMENTATION=${rmw_implementation}
TIMEOUT 60)
custom_launch_n_nodes(10
TIMEOUT 15)
# Note (dhood): signal handler tests will be skipped on Windows because there is no opportunity
# for signal handling once shutdown is triggered by launch_testing.
set(SKIP_TEST "")
if(WIN32)
set(SKIP_TEST "SKIP_TEST")
endif()
# Test that a user-defined signal handler is called on interrupt:
# after rclcpp::init has been called, but before rclcpp::shutdown has been called.
custom_launch_test_executable_output(test_signal_handler_before_shutdown
test_signal_handler
TIMEOUT 30
${SKIP_TEST})
# Test that a user-defined signal handler is restored after rclcpp::init and rclcpp::shutdown
# have been called.
custom_launch_test_executable_output(test_signal_handler_after_shutdown
test_signal_handler
TIMEOUT 30
${SKIP_TEST})
# Test node names
set(rmw_implementation1 "${rmw_implementation}")
foreach(rmw_implementation2 ${rmw_implementations})
cross_rmw_tests()
endforeach()
endmacro()
set(append_library_dirs "${CMAKE_CURRENT_BINARY_DIR}")
if(WIN32)
set(append_library_dirs "${append_library_dirs}/$<CONFIG>")
endif()
# Test node names
add_executable(node_with_name "test/node_with_name.cpp")
ament_target_dependencies(node_with_name
"rclcpp")
add_executable(node_name_list "test/node_name_list.cpp")
ament_target_dependencies(node_name_list
"rclcpp")
add_executable(node_check_names "test/node_check_names.cpp")
ament_target_dependencies(node_check_names
"rclcpp")
call_for_each_rmw_implementation(targets)
custom_executable(test_signal_handler "test/test_signal_handler.cpp")
# Parameter tests single implementation
custom_executable(test_parameters_server_cpp "test/test_parameters_server.cpp")
custom_gtest_executable(test_remote_parameters_cpp "test/test_remote_parameters.cpp")
# Service tests single implementation
custom_executable(test_services_server_cpp "test/test_services_server.cpp")
custom_gtest_executable(test_services_client_cpp "test/test_services_client.cpp")
custom_executable(test_client_scope_server_cpp "test/test_client_scope_server.cpp")
custom_gtest_executable(test_client_scope_client_cpp "test/test_client_scope_client.cpp")
custom_executable(test_client_scope_consistency_server_cpp "test/test_client_scope_consistency_server.cpp")
custom_gtest_executable(test_client_scope_consistency_client_cpp "test/test_client_scope_consistency_client.cpp")
endif() # BUILD_TESTING
# TODO should not install anything
ament_package()
if(TEST cppcheck)
# cppcheck test is created in hook in ament_package()
set_tests_properties(cppcheck PROPERTIES TIMEOUT 400)
endif()