Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ code coverage support #905

Merged
merged 6 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conda/environments/rmm_dev_cuda10.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ dependencies:
- cudatoolkit=10.1
- spdlog>=1.8.5,<1.9
- cython>=0.29,<0.30
- gcovr>=5.0
1 change: 1 addition & 0 deletions conda/environments/rmm_dev_cuda10.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ dependencies:
- cudatoolkit=10.2
- spdlog>=1.8.5,<1.9
- cython>=0.29,<0.30
- gcovr>=5.0
1 change: 1 addition & 0 deletions conda/environments/rmm_dev_cuda11.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ dependencies:
- cudatoolkit=11.0
- spdlog>=1.8.5,<1.9
- cython>=0.29,<0.30
- gcovr>=5.0
4 changes: 4 additions & 0 deletions gcovr.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exclude=build/.*
exclude=tests/.*
html=yes
html-details=yes
34 changes: 33 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

# Build options
option(DISABLE_DEPRECATION_WARNING "Disable warnings generated from deprecated declarations." OFF)
option(CODE_COVERAGE "Enable generating code coverage with gcov." OFF)

# compiler function
if(CODE_COVERAGE)
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
message(WARNING "Generating code coverage for optimised (non-Debug) builds not recommended")
endif()
endif()

# This function takes in a test name and test source and handles setting all of the associated
# properties and linking to build the test
Expand All @@ -41,6 +46,33 @@ function(ConfigureTestInternal TEST_NAME)
PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-declarations>)
endif()

if(CODE_COVERAGE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")

set(KEEP_DIR ${CMAKE_CURRENT_BINARY_DIR}/tmp)
harrism marked this conversation as resolved.
Show resolved Hide resolved
make_directory(${KEEP_DIR})
harrism marked this conversation as resolved.
Show resolved Hide resolved
target_compile_options(${TEST_NAME} PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:--keep
--keep-dir=${KEEP_DIR}>)
target_compile_options(
${TEST_NAME}
PUBLIC
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=--coverage,-fprofile-abs-path,-fkeep-inline-functions,-fno-elide-constructors>
)
target_compile_options(
${TEST_NAME} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:--coverage -fprofile-abs-path
-fkeep-inline-functions -fno-elide-constructors>)
target_link_options(${TEST_NAME} PRIVATE --coverage)
target_link_libraries(${TEST_NAME} gcov)
endif()

# Add coverage-generated files to clean target
list(APPEND COVERAGE_CLEAN_FILES "**/*.gcno" "**/*.gcda")
set_property(
TARGET ${TEST_NAME}
APPEND
PROPERTY ADDITIONAL_CLEAN_FILES ${COVERAGE_CLEAN_FILES})
endif()

add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
endfunction()

Expand Down