diff --git a/CMakeLists.txt b/CMakeLists.txt index cb40e26499de..b25659fd09e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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(testing "Configure unit test targets" OFF) +if(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() #============================================================================= diff --git a/Makefile b/Makefile index 6f60f7ea029e..25d074549833 100644 --- a/Makefile +++ b/Makefile @@ -337,18 +337,18 @@ format: # Testing # -------------------------------------------------------------------- -.PHONY: tests tests_coverage tests_mission tests_mission_coverage tests_offboard tests_avoidance unit_test +.PHONY: test tests_coverage tests_mission tests_mission_coverage tests_offboard tests_avoidance unit_test .PHONY: rostest python_coverage -unit_test: - $(eval CMAKE_ARGS += -Dunit_testing=ON) +test: + $(eval CMAKE_ARGS += -Dtesting=ON) $(eval ARGS += unit_test) $(call cmake-build,px4_sitl_default) 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 += -Dtesting=ON) + $(eval ARGS += test_results) + $(call cmake-build,px4_sitl_default) tests_coverage: @$(MAKE) clean diff --git a/cmake/gtest/px4_add_gtest.cmake b/cmake/gtest/px4_add_gtest.cmake index 2d50f089772e..5125104e7c4f 100644 --- a/cmake/gtest/px4_add_gtest.cmake +++ b/cmake/gtest/px4_add_gtest.cmake @@ -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