Browse Source

Testing: switch unit tests to BUILD_TESTING

sbg
Matthias Grob 6 years ago
parent
commit
5020dfdc3d
  1. 16
      CMakeLists.txt
  2. 14
      Makefile
  3. 2
      cmake/gtest/px4_add_gtest.cmake
  4. 1
      platforms/posix/cmake/sitl_tests.cmake

16
CMakeLists.txt

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

14
Makefile

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

2
cmake/gtest/px4_add_gtest.cmake

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

1
platforms/posix/cmake/sitl_tests.cmake

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

Loading…
Cancel
Save