add tests code coverage

-closes #5862
This commit is contained in:
Daniel Agar 2016-12-04 19:10:24 -05:00 committed by Lorenz Meier
parent c2b6381759
commit 1941dfca87
4 changed files with 33 additions and 1 deletions

4
.gitignore vendored
View File

@ -77,3 +77,7 @@ vectorcontrol/
# CLion ignores
.idea
# gcov code coverage
coverage-html/
coverage.info

View File

@ -257,6 +257,13 @@ run_tests_posix: posix_sitl_default
tests: check_unittest run_tests_posix
tests_coverage:
@(PX4_CODE_COVERAGE=1 CCACHE_DISABLE=1 ${MAKE} tests)
@(lcov --directory . --capture --quiet --output-file coverage.info)
@(lcov --remove coverage.info '/usr/*' --quiet --output-file coverage.info)
#@(lcov --list coverage.info)
@(genhtml coverage.info --quiet --output-directory coverage-html)
# QGroundControl flashable firmware (currently built by travis-ci)
qgc_firmware: \
check_px4fmu-v1_default \

View File

@ -827,6 +827,7 @@ function(px4_add_common_flags)
)
set(added_link_dirs) # none used currently
set(added_exe_linker_flags)
string(TOUPPER ${BOARD} board_upper)
string(REPLACE "-" "_" board_config ${board_upper})
@ -848,6 +849,20 @@ function(px4_add_common_flags)
)
endif()
# code coverage
if ($ENV{PX4_CODE_COVERAGE} MATCHES "1")
message(STATUS "Code coverage build flags enabled")
list(APPEND added_cxx_flags
-fprofile-arcs -ftest-coverage --coverage -g3 -O0 -fno-elide-constructors -Wno-invalid-offsetof -fno-default-inline -fno-inline
)
list(APPEND added_c_flags
-fprofile-arcs -ftest-coverage --coverage -g3 -O0 -fno-default-inline -fno-inline
)
list(APPEND added_exe_linker_flags
-ftest-coverage --coverage -lgcov
)
endif()
# output
foreach(var ${inout_vars})
string(TOLOWER ${var} lower_var)

View File

@ -13,11 +13,17 @@ enable_testing()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -std=gnu99 -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=gnu++0x -g -fno-exceptions -fno-rtti -fno-threadsafe-statics -DCONFIG_WCHAR_BUILTIN -D__CUSTOM_FILE_IO__")
# code coverage
if ($ENV{PX4_CODE_COVERAGE} MATCHES "1")
message(STATUS "Code coverage build flags enabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage")
endif()
if (NOT PX4_SOURCE_DIR)
set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
endif()
set(GTEST_DIR ${PX4_SOURCE_DIR}/unittests/googletest)
add_subdirectory(${GTEST_DIR})
include_directories(${GTEST_DIR}/include)