Testing: switch unit tests to BUILD_TESTING

This commit is contained in:
Matthias Grob 2019-04-14 20:55:35 +02:00
parent 01e9b2cde8
commit 5020dfdc3d
4 changed files with 19 additions and 14 deletions

View File

@ -299,10 +299,6 @@ if (${PX4_PLATFORM} STREQUAL "posix")
if (NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE)
endif()
# cmake testing only on posix
enable_testing()
include(CTest)
endif()
#=============================================================================
@ -417,14 +413,18 @@ endif()
# Testing - Automatic unit and integration testing with CTest
#
option(unit_testing "Configure unit test targets" OFF)
# optionally enable cmake testing (supported only on posix)
option(CMAKE_TESTING "Configure test targets" OFF)
if(CMAKE_TESTING)
include(CTest)
endif()
list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake/gtest/)
include(px4_add_gtest)
if(unit_testing)
include(gtest)
add_custom_target(unit_test COMMAND GTEST_COLOR=1 ${CMAKE_CTEST_COMMAND} -V -R UnitTest- USES_TERMINAL)
if(BUILD_TESTING)
include(gtest)
add_custom_target(unit_test COMMAND GTEST_COLOR=1 ${CMAKE_CTEST_COMMAND} -V -R UnitTest- USES_TERMINAL)
endif()
#=============================================================================

View File

@ -341,14 +341,18 @@ format:
.PHONY: rostest python_coverage
unit_test:
$(eval CMAKE_ARGS += -Dunit_testing=ON)
$(eval CMAKE_ARGS += -DCMAKE_TESTING=ON)
$(eval CMAKE_ARGS += -DCONFIG=px4_sitl_test)
$(eval ARGS += unit_test)
$(call cmake-build,px4_sitl_default)
$(call cmake-build,px4_sitl_test)
tests:
@$(MAKE) --no-print-directory px4_sitl_test test_results \
ASAN_OPTIONS="color=always:check_initialization_order=1:detect_stack_use_after_return=1" \
UBSAN_OPTIONS="color=always"
$(eval CMAKE_ARGS += -DCMAKE_TESTING=ON)
$(eval CMAKE_ARGS += -DCONFIG=px4_sitl_test)
$(eval ARGS += test_results)
$(eval ASAN_OPTIONS += color=always:check_initialization_order=1:detect_stack_use_after_return=1)
$(eval UBSAN_OPTIONS += color=always)
$(call cmake-build,px4_sitl_test)
tests_coverage:
@$(MAKE) clean

View File

@ -41,7 +41,7 @@ include(px4_base)
#
function(px4_add_gtest)
# skip if unit testing is not configured
if(unit_testing)
if(BUILD_TESTING)
# parse source file and library dependencies from arguments
px4_parse_function_args(
NAME px4_add_gtest

View File

@ -151,6 +151,7 @@ add_custom_target(test_results
px4
examples__dyn_hello
test_mixer_multirotor
unit_test
USES_TERMINAL
COMMENT "Running tests in sitl"
WORKING_DIRECTORY ${PX4_BINARY_DIR})