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

Automatic tests and zerocounter #31

Open
dlyr opened this issue Jan 9, 2021 · 3 comments
Open

Automatic tests and zerocounter #31

dlyr opened this issue Jan 9, 2021 · 3 comments

Comments

@dlyr
Copy link

dlyr commented Jan 9, 2021

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
Copy link
Author

dlyr commented Jan 9, 2021

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

@alehaa
Copy link
Contributor

alehaa commented Jan 11, 2021

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.

@dlyr
Copy link
Author

dlyr commented Jan 11, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants