Skip to content

Commit

Permalink
Updates gtest usage and structure in CMakeLists and package.xml.
Browse files Browse the repository at this point in the history
  • Loading branch information
agalbachicar committed Nov 17, 2020
1 parent 9a4a650 commit 5adbc2c
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 413 deletions.
142 changes: 12 additions & 130 deletions delphyne-gui/cmake/TestUtils.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
##################################################
# Hack: to just build the files but not add them into the testsuite
# (like auxiliary apps using gtest files called from other tests)
# set the delphyne_SKIP_IN_TESTSUITE variable to true. The variable will
# be set to false at the end of the function.
macro (delphyne_build_tests)
find_package(ament_cmake_gtest REQUIRED)

macro (delphyne_build_tests)
# Find the Python interpreter for running the
# check_test_ran.py script
find_package(PythonInterp QUIET)
Expand All @@ -13,141 +10,26 @@ macro (delphyne_build_tests)
foreach(GTEST_SOURCE_file ${ARGN})
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)

add_executable(${BINARY_NAME}
${GTEST_SOURCE_file}
)

add_dependencies(${BINARY_NAME}
gtest gtest_main
)
ament_add_gtest(${BINARY_NAME} ${GTEST_SOURCE_file} TIMEOUT 240)

target_link_libraries(${BINARY_NAME}
${IGNITION-COMMON_LIBRARIES}
${global_attributes}
libgtest.a
pthread
)

if (UNIX)
target_link_libraries(${BINARY_NAME}
libgtest.a
libgtest_main.a
# Kind of an ugly catch-all bucket
target_link_libraries(
${BINARY_NAME}
${IGNITION-COMMON_LIBRARIES}
${global_attributes}
pthread
)
elseif(WIN32)
target_link_libraries(${BINARY_NAME}
gtest
gtest_main
)
endif()

if (NOT DEFINED delphyne_SKIP_IN_TESTSUITE)
set(delphyne_SKIP_IN_TESTSUITE False)
endif()

if (NOT delphyne_SKIP_IN_TESTSUITE)
add_test(${BINARY_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}
--gtest_output=xml:${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml)

set_tests_properties(${BINARY_NAME} PROPERTIES TIMEOUT 240)

if (PYTHONINTERP_FOUND)
# 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} python
${PROJECT_SOURCE_DIR}/test/utils/check_test_ran.py
${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml)
endif()
endif()
endforeach()

# If delphyne_SKIP_IN_TESTSUITE was set to True, back to default. This way
# we request for explicit definition before calling the macro
if (delphyne_SKIP_IN_TESTSUITE)
set(delphyne_SKIP_IN_TESTSUITE False)
endif()
endmacro()

##################################################
# Hack: to just build the files but not add them into the testsuite
# (like auxiliary apps using gtest files called from other tests)
# set the delphyne_SKIP_IN_TESTSUITE variable to true. The variable will
# be set to false at the end of the function.
macro (delphyne_build_test)

# Find the Python interpreter for running the
# check_test_ran.py script
find_package(PythonInterp QUIET)

# Build the test
set(GTEST_SOURCE_file ${ARGV0})
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)

add_executable(${BINARY_NAME}
${GTEST_SOURCE_file}
${ARGN}
)

add_dependencies(${BINARY_NAME}
gtest gtest_main
)

target_link_libraries(${BINARY_NAME}
${IGNITION-COMMON_LIBRARIES}
${IGNITION-GUI_LIBRARIES}
${IGNITION-MATH_LIBRARIES}
${IGNITION-MSGS_LIBRARIES}
${IGNITION-RENDERING_LIBRARIES}
${IGNITION-TRANSPORT_LIBRARIES}
${Qt5Core_LIBRARIES}
${Qt5Widgets_LIBRARIES}
${lcm_LIBRARIES}
${global_attributes}
)

if (UNIX)
target_link_libraries(${BINARY_NAME}
libgtest.a
libgtest_main.a
pthread
)
elseif(WIN32)
target_link_libraries(${BINARY_NAME}
gtest
gtest_main
)
endif()

if (NOT DEFINED delphyne_SKIP_IN_TESTSUITE)
set(delphyne_SKIP_IN_TESTSUITE False)
endif()

if (NOT delphyne_SKIP_IN_TESTSUITE)
add_test(${BINARY_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}
--gtest_output=xml:${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml)

set_tests_properties(${BINARY_NAME} PROPERTIES TIMEOUT 240)
# Remove a warning in GTest.
target_compile_options(${BINARY_NAME} PRIVATE "-Wno-sign-compare")

if (PYTHONINTERP_FOUND)
# 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} python
${PROJECT_SOURCE_DIR}/tools/check_test_ran.py
${PROJECT_SOURCE_DIR}/test/utils/check_test_ran.py
${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml)
endif()
endif()

# If delphyne_SKIP_IN_TESTSUITE was set to True, back to default. This way
# we request for explicit definition before calling the macro
if (delphyne_SKIP_IN_TESTSUITE)
set(delphyne_SKIP_IN_TESTSUITE False)
endif()
endforeach()
endmacro()
1 change: 0 additions & 1 deletion delphyne-gui/cmake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ endmacro()
# This should be migrated to more fine control solution based on set_property APPEND
# directories. It's present on cmake 2.8.8 while precise version is 2.8.7
link_directories(${PROJECT_BINARY_DIR}/test)
include_directories("${PROJECT_SOURCE_DIR}/test/gtest/include")

#################################################
# Enable tests compilation by default
Expand Down
1 change: 1 addition & 0 deletions delphyne-gui/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<exec_depend>ament_cmake</exec_depend>

<test_depend>ament_cmake_clang_format</test_depend>
<test_depend>ament_cmake_gtest</test_depend>

<export>
<build_type>ament_cmake</build_type>
Expand Down
23 changes: 0 additions & 23 deletions delphyne-gui/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +0,0 @@
include_directories (
${PROJECT_SOURCE_DIR}/test/gtest/include
${PROJECT_SOURCE_DIR}/test/gtest
${PROJECT_SOURCE_DIR}/test
${PROJECT_BINARY_DIR}
)

configure_file (test_config.h.in ${PROJECT_BINARY_DIR}/include/delphyne/test_config.h)

# Build gtest
add_library(gtest STATIC gtest/src/gtest-all.cc)
add_library(gtest_main STATIC gtest/src/gtest_main.cc)
target_link_libraries(gtest_main gtest)
set(GTEST_LIBRARY "${PROJECT_BINARY_DIR}/test/libgtest.a")
set(GTEST_MAIN_LIBRARY "${PROJECT_BINARY_DIR}/test/libgtest_main.a")

execute_process(COMMAND cmake -E remove_directory ${CMAKE_BINARY_DIR}/test_results)
execute_process(COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test_results)
include_directories(${GTEST_INCLUDE_DIRS})

add_subdirectory(integration)
add_subdirectory(performance)
add_subdirectory(regression)
10 changes: 0 additions & 10 deletions delphyne-gui/test/integration/CMakeLists.txt

This file was deleted.

8 changes: 0 additions & 8 deletions delphyne-gui/test/performance/CMakeLists.txt

This file was deleted.

8 changes: 0 additions & 8 deletions delphyne-gui/test/regression/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 5adbc2c

Please sign in to comment.