From: Mathias Preiner Date: Thu, 24 Jun 2021 21:04:13 +0000 (-0700) Subject: cmake: Add new code coverage targets. (#6796) X-Git-Tag: cvc5-1.0.0~1557 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a0ed9d5b519b636ed0351db13bb1c3f7469d4e94;p=cvc5.git cmake: Add new code coverage targets. (#6796) This commit adds the following new code coverage targets: - coverage-reset: Resets the code coverage counters - coverage: Generates code coverage report for all cvc5 executions since the last coverage-reset - coverage-test: This was previously the coverage target that runs the tests and generates the coverage report (as used for nightlies). By using `make coverage-reset` and `make coverage` it is now possible to generate coverage reports for arbitrary executions of cvc5. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3780b0b5b..f5f571046 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -365,12 +365,22 @@ if(ENABLE_COVERAGE) # prevent this we always return with exit code 0 after the ctest command has # finished. setup_target_for_coverage_gcovr_html( - NAME coverage + NAME coverage-test EXECUTABLE ctest -j${CTEST_NTHREADS} -LE "example" --output-on-failure $$ARGS || exit 0 DEPENDS build-tests) + + # Adds targets `coverage` and `coverage-reset` for manually generating + # coverage reports for specific executions. + # + # Target coverage-reset resets all the coverage counters to zero, while + # target coverage will generate a coverage report for all executions since + # the last coverage-reset. + setup_target_for_coverage_lcov_no_executable( + NAME coverage + DEPENDENCIES cvc5-bin) endif() if(ENABLE_DEBUG_CONTEXT_MM) diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake index 932c3d066..035c2aa24 100644 --- a/cmake/CodeCoverage.cmake +++ b/cmake/CodeCoverage.cmake @@ -185,6 +185,63 @@ function(SETUP_TARGET_FOR_COVERAGE_LCOV) endfunction() # SETUP_TARGET_FOR_COVERAGE_LCOV +function(SETUP_TARGET_FOR_COVERAGE_LCOV_NO_EXECUTABLE) + + set(options NONE) + set(oneValueArgs NAME) + cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT LCOV_PATH) + message(FATAL_ERROR "lcov not found! Aborting...") + endif() # NOT LCOV_PATH + + if(NOT GENHTML_PATH) + message(FATAL_ERROR "genhtml not found! Aborting...") + endif() # NOT GENHTML_PATH + + set(DIRECTORIES -d .) + foreach(LPATH ${COVERAGE_LCOV_PATHS}) + list(APPEND DIRECTORIES "-d") + list(APPEND DIRECTORIES "${LPATH}") + endforeach() + + + add_custom_target(${Coverage_NAME}-reset + # Cleanup lcov + COMMAND ${LCOV_PATH} ${DIRECTORIES} --zerocounters + # Create baseline to make sure untouched files show up in the report + COMMAND ${LCOV_PATH} -c -i ${DIRECTORIES} -o ${Coverage_NAME}.base + COMMENT "Resetting code coverage counters to zero." + ) + + # Setup target + add_custom_target(${Coverage_NAME} + # Capturing lcov counters and generating report + COMMAND ${LCOV_PATH} ${DIRECTORIES} --capture --output-file ${Coverage_NAME}.info + # add baseline counters + COMMAND ${LCOV_PATH} -a ${Coverage_NAME}.base -a ${Coverage_NAME}.info --output-file ${Coverage_NAME}.total + COMMAND ${LCOV_PATH} --remove ${Coverage_NAME}.total ${COVERAGE_LCOV_EXCLUDES} --output-file ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned + COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned + + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${Coverage_DEPENDENCIES} + COMMENT "Processing code coverage counters and generating report." + ) + + # Show where to find the lcov info report + add_custom_command(TARGET ${Coverage_NAME} POST_BUILD + COMMAND ; + COMMENT "Lcov code coverage info report saved in ${Coverage_NAME}.info." + ) + + # Show info where to find the report + add_custom_command(TARGET ${Coverage_NAME} POST_BUILD + COMMAND ; + COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report." + ) + +endfunction() # SETUP_TARGET_FOR_COVERAGE_LCOV_NO_EXECUTABLE + # Defines a target for running and collection code coverage information # Builds dependencies, runs the given executable and outputs reports. # NOTE! The executable should always have a ZERO as exit code otherwise