CMake-codecov icon indicating copy to clipboard operation
CMake-codecov copied to clipboard

Automatic tests and zerocounter

Open dlyr opened this issue 3 years ago • 3 comments

I just try to use CMake-codecov (I'm new to lcov, just learning, so sorry if my question is out of scope)

I want to automatically call check target before calling lcov. after calling coverage_evaluate() at the end of main CMakeLists.txt, I added add_dependencies(lcov check) But I have one issue, I want to "zerocounter" lcov data before tests, to have fresh results in case of rebuild. I have done

add_custom_command(TARGET lcov-zerocounter COMMAND ${LCOV_BIN} --quiet --zerocounter --directory ${CMAKE_BINARY_DIR})
add_dependencies(check lcov-zerocounter)

But I'm asking myself should this be present directly in CMake-codecov ? or is there a better way to handle lcov data cleanup before capture. Thanks.

dlyr avatar Jan 09 '21 14:01 dlyr

Well my tentative do not work for parallel build, so I had to create a new custom target in FindLcov.cmake so that I could trigger check target before any capture:

@@ -285 +286 @@ function (lcov_capture_tgt TNAME)
-       add_custom_target(${TNAME}-geninfo DEPENDS ${OUTFILE})
+       add_custom_target(${TNAME}-geninfo DEPENDS ${OUTFILE} lcov-before-capture)

and add_dependencies(lcov-before-capture check) in my main CMakeLists.txt

dlyr avatar Jan 09 '21 15:01 dlyr

Usually, I just let the individual test runs cumulate to see, if all parts of the code have been tested. I think this is a convenient command to add into this project.

However, I would prefer to pack individual extensions as the lcov-before-capture into an extra function of the target repository, as it seems to be a customized feature.

alehaa avatar Jan 11 '21 01:01 alehaa

Hi, thanks for you answer. I actually drop CMake-codecov for the moment, the lack of Ninja support, but also some things I could not debug easily make the report not usable with codecov.io for my config. My simple version, which works with Ninja, and produce the report I expect, but do not have fine grained file dependencies:

        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall -W -fprofile-arcs -ftest-coverage")
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -Wall -W -fprofile-arcs -ftest-coverage")
        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}-fprofile-arcs -ftest-coverage")
# ...

   add_custom_target(lcov-init
        COMMAND ${LCOV_BIN} --initial --capture --directory ${CMAKE_BINARY_DIR} --output-file ${CMAKE_BINARY_DIR}/init.info
        COMMAND ${LCOV_BIN} --remove ${CMAKE_BINARY_DIR}/init.info ${LCOV_REMOVES} --output-file ${CMAKE_BINARY_DIR}/init.info
        DEPENDS ${all_targets}
        BYPRODUCTS ${CMAKE_BINARY_DIR}/init.info)
    add_custom_target(lcov-zerocounter
        COMMAND ${LCOV_BIN} --zerocounter --directory ${CMAKE_BINARY_DIR}
        DEPENDS lcov-init)
    add_custom_target(lcov-capture
        COMMAND ${LCOV_BIN} --capture --directory . --output-file  ${CMAKE_BINARY_DIR}/coverage.info
        COMMAND ${LCOV_BIN} --remove coverage.info  ${LCOV_REMOVES} --output-file  ${CMAKE_BINARY_DIR}/coverage.info
        COMMAND ${LCOV_BIN} -a ${CMAKE_BINARY_DIR}/init.info -a ${CMAKE_BINARY_DIR}/coverage.info -o ${CMAKE_BINARY_DIR}/total.info
        DEPENDS lcov-zerocounter
        BYPRODUCTS ${CMAKE_BINARY_DIR}/total.info)
    add_custom_target(lcov-list
        COMMAND ${LCOV_BIN} --list ${CMAKE_BINARY_DIR}/total.info
        SOURCES  ${CMAKE_BINARY_DIR}/total.info)

    add_dependencies(check lcov-zerocounter)
    add_dependencies(lcov-capture check)

dlyr avatar Jan 11 '21 07:01 dlyr