-
Notifications
You must be signed in to change notification settings - Fork 485
/
GazeboTestUtils.cmake
178 lines (157 loc) · 6.19 KB
/
GazeboTestUtils.cmake
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
#################################################
# VAR: GZ_BUILD_TESTS_EXTRA_EXE_SRCS
# Hack: extra sources to build binaries can be supplied to gz_build_tests in
# the variable GZ_BUILD_TESTS_EXTRA_EXE_SRCS. This variable will be clean up
# at the end of the function
#
# ARG: EXTRA_LIBS
# List extra libraries that the sources should be linked against after the
# EXTRA_LIBS tag. Example:
# gz_build_tests(${test_sources} EXTRA_LIBS ${test_libraries})
#
macro (gz_build_tests)
set(_append_sources TRUE)
set(_sources)
set(_extra_libs)
foreach(arg ${ARGN})
if ("${arg}" STREQUAL "EXTRA_LIBS")
set(_append_sources FALSE)
else()
if (_append_sources)
list(APPEND _sources ${arg})
else()
list(APPEND _extra_libs ${arg})
endif()
endif()
endforeach()
# Build all the tests
foreach(GTEST_SOURCE_file ${_sources})
string(REGEX REPLACE "\\.cc" "" BINARY_NAME ${GTEST_SOURCE_file})
set(BINARY_NAME ${TEST_TYPE}_${BINARY_NAME})
if(USE_LOW_MEMORY_TESTS)
add_definitions(-DUSE_LOW_MEMORY_TESTS=1)
endif(USE_LOW_MEMORY_TESTS)
if (BUILD_TESTING)
add_executable(${BINARY_NAME}
${GTEST_SOURCE_file}
${GZ_BUILD_TESTS_EXTRA_EXE_SRCS})
else()
add_executable(${BINARY_NAME} EXCLUDE_FROM_ALL
${GTEST_SOURCE_file}
${GZ_BUILD_TESTS_EXTRA_EXE_SRCS})
endif()
link_directories(${PROJECT_BINARY_DIR}/test)
target_link_libraries(${BINARY_NAME}
gtest
gtest_main
${_extra_libs}
)
if (UNIX)
# gtest uses pthread on UNIX
target_link_libraries(${BINARY_NAME} pthread)
endif()
# Visual Studio enables c++11 support by default
if (NOT MSVC)
if(CMAKE_VERSION VERSION_LESS 3.8.2)
target_compile_options(${BINARY_NAME} PRIVATE -std=c++11)
else()
target_compile_features(${BINARY_NAME} PRIVATE cxx_std_11)
endif()
endif()
add_test(${BINARY_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}
--gtest_output=xml:${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml)
set(_env_vars)
list(APPEND _env_vars "CMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}:$ENV{CMAKE_PREFIX_PATH}")
list(APPEND _env_vars "GAZEBO_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins:${CMAKE_BINARY_DIR}/plugins/events:${CMAKE_BINARY_DIR}/plugins/rest_web")
list(APPEND _env_vars "GAZEBO_RESOURCE_PATH=${CMAKE_SOURCE_DIR}")
list(APPEND _env_vars "PATH=${CMAKE_BINARY_DIR}/gazebo:${CMAKE_BINARY_DIR}/tools:$ENV{PATH}")
list(APPEND _env_vars "PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/cmake/pkgconfig:$ENV{PKG_CONFIG_PATH}")
set_tests_properties(${BINARY_NAME} PROPERTIES
TIMEOUT 240
ENVIRONMENT "${_env_vars}")
# Check that the test produced a result and create a failure if it didn't.
# Guards against crashed and timed out tests.
add_test(check_${BINARY_NAME} ${PROJECT_SOURCE_DIR}/tools/check_test_ran.py
${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml)
if(GAZEBO_RUN_VALGRIND_TESTS AND VALGRIND_PROGRAM)
add_test(memcheck_${BINARY_NAME} ${VALGRIND_PROGRAM} --leak-check=full
--error-exitcode=1 --show-leak-kinds=all ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME})
endif()
add_dependencies(tests ${BINARY_NAME})
endforeach()
set(GZ_BUILD_TESTS_EXTRA_EXE_SRCS "")
endmacro()
if (VALID_DISPLAY)
# Redefine build display tests
macro (gz_build_display_tests)
gz_build_tests(${ARGV})
endmacro()
# Redefine build qt tests
macro (gz_build_qt_tests)
# Build all the tests
foreach(QTEST_SOURCE_file ${ARGN})
string(REGEX REPLACE ".cc" "" BINARY_NAME ${QTEST_SOURCE_file})
string(REGEX REPLACE ".cc" ".hh" QTEST_HEADER_file ${QTEST_SOURCE_file})
set(BINARY_NAME ${TEST_TYPE}_${BINARY_NAME})
if (BUILD_TESTING)
add_executable(${BINARY_NAME}
${${BINARY_NAME}_MOC} ${QTEST_SOURCE_file} ${CMAKE_SOURCE_DIR}/gazebo/gui/QTestFixture.cc)
else()
add_executable(${BINARY_NAME} EXCLUDE_FROM_ALL
${${BINARY_NAME}_MOC} ${QTEST_SOURCE_file} ${CMAKE_SOURCE_DIR}/gazebo/gui/QTestFixture.cc)
endif()
add_dependencies(${BINARY_NAME}
gazebo_gui
gazebo_common
gazebo_physics
gazebo_sensors
gazebo_rendering
gazebo_msgs
gazebo_transport
)
target_link_libraries(${BINARY_NAME}
# gazebo_gui and libgazebo will bring all most of gazebo
# libraries as dependencies
libgazebo
gazebo_gui
${Qt5Test_LIBRARIES}
)
# QTest need and extra -o parameter to write logging information to a file
add_test(${BINARY_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}
-xml -o ${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml)
set(_env_vars)
list(APPEND _env_vars "CMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}:${CMAKE_PREFIX_PATH}")
list(APPEND _env_vars "GAZEBO_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins:${CMAKE_BINARY_DIR}/plugins/events:${CMAKE_BINARY_DIR}/plugins/rest_web")
list(APPEND _env_vars "GAZEBO_RESOURCE_PATH=${CMAKE_SOURCE_DIR}")
list(APPEND _env_vars "PATH=${CMAKE_BINARY_DIR}/gazebo:${CMAKE_BINARY_DIR}/tools:$ENV{PATH}")
list(APPEND _env_vars "PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/cmake/pkgconfig:$PKG_CONFIG_PATH")
set_tests_properties(${BINARY_NAME} PROPERTIES
TIMEOUT 240
ENVIRONMENT "${_env_vars}")
# Check that the test produced a result and create a failure if it didn't.
# Guards against crashed and timed out tests.
add_test(check_${BINARY_NAME} ${PROJECT_SOURCE_DIR}/tools/check_test_ran.py
${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml)
if(GAZEBO_RUN_VALGRIND_TESTS AND VALGRIND_PROGRAM)
add_test(memcheck_${BINARY_NAME} ${VALGRIND_PROGRAM} --leak-check=full
--error-exitcode=1 --show-leak-kinds=all ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME})
endif()
add_dependencies(tests ${BINARY_NAME})
endforeach()
endmacro()
else()
# Fake macros when no valid display is found
macro (gz_build_display_tests)
endmacro()
macro (gz_build_qt_tests)
endmacro()
endif()
if (VALID_DRI_DISPLAY)
macro (gz_build_dri_tests)
gz_build_tests(${ARGV})
endmacro()
else()
# Fake macro when no valid DRI display is found
macro (gz_build_dri_tests)
endmacro()
endif()