diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f73ce7..bf85e9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,7 @@ option(BUILD_CODE_COVERAGE "Build with code coverage enabled" OFF) option(BUILD_ADDRESS_SANITIZER "Build with address sanitizer enabled" OFF) option(BUILD_DOCS "Build documentation" OFF) option(USE_CUDA "Build hipGRAPH using CUDA backend" OFF) +option(BUILD_CODE_COVERAGE "Build with code coverage flags (clang only)" OFF) # If CUGRAPH_BUILD_DIR is not set, look at CUGRAPH_SOURCE_DIR/cpp/build. cmake_dependent_option(CUGRAPH_SOURCE_DIR "Point at a cugraph source directory" "" USE_CUDA "") cmake_dependent_option(CUGRAPH_BUILD_DIR "Point at a cugraph build directory (often cpp/build)" "" USE_CUDA "") diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index e3ae5b9..387bef5 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -57,6 +57,44 @@ if(USE_CUDA) target_link_libraries(hipgraph-test PRIVATE ${CUDA_LIBRARIES}) endif() +if(BUILD_CODE_COVERAGE) + add_custom_target( + code_cov_tests + DEPENDS hipgraph-test + COMMAND ${CMAKE_COMMAND} -E rm -rf ./coverage-report + COMMAND ${CMAKE_COMMAND} -E make_directory ./coverage-report/profraw + COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE="./coverage-report/profraw/hipgraph-coverage_%p.profraw" $ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + + find_program( + LLVM_PROFDATA + llvm-profdata + REQUIRED + HINTS ${ROCM_PATH}/llvm/bin + PATHS /opt/rocm/llvm/bin + ) + + find_program( + LLVM_COV + llvm-cov + REQUIRED + HINTS ${ROCM_PATH}/llvm/bin + PATHS /opt/rocm/llvm/bin + ) + + add_custom_target( + coverage + DEPENDS code_cov_tests + COMMAND ${LLVM_PROFDATA} merge -sparse ./coverage-report/profraw/hipgraph-coverage_*.profraw -o ./coverage-report/hipgraph.profdata + COMMAND ${LLVM_COV} report -object ./library/src/libhipgraph.so -instr-profile=./coverage-report/hipgraph.profdata + COMMAND ${LLVM_COV} show -object ./library/src/libhipgraph.so -instr-profile=./coverage-report/hipgraph.profdata -format=html -output-dir=coverage-report + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + +endif() + + set_target_properties(hipgraph-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging") rocm_install(TARGETS hipgraph-test COMPONENT tests) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 725f4e2..6587ce7 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -154,6 +154,11 @@ if(NOT BUILD_SHARED_LIBS) set_target_properties(hipgraph PROPERTIES PREFIX "lib") endif() +if(BUILD_CODE_COVERAGE) + target_compile_options( hipgraph PRIVATE -g -O0 -fprofile-instr-generate -fcoverage-mapping ) + target_link_options( hipgraph PUBLIC -fprofile-instr-generate ) +endif() + # Include sources add_subdirectory(src)