-
Notifications
You must be signed in to change notification settings - Fork 213
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
Code coverage aggregation #8
Comments
Yes, the coverage analysis is done per-target. What I do is to create a custom target which runs add_custom_target(ctest COMMAND ${CMAKE_CTEST_COMMAND}) Then I set this up as a coverage target: SETUP_TARGET_FOR_COVERAGE_COBERTURA(ctest_coverage_cobertura ctest "ctest_coverage_cobertura_results" "-j;${PROCESSOR_COUNT}") This will produce an aggregated coverage report of everything which is part of the Additionally I setup more coverage targets (e.g. GoogleTest runner) which produce each their own coverage report and at the end I aggregate them in Jenkins with the Cobertura Code Coverage Publisher. |
Thanks, I'll try this today. I guess I'm surprised that the coverage analyzer is able to gather the output of multiple executables just because they are launched by the same executable. Did I understand correctly that you use both CTest and GTest in the same project? How do you decide what to do in each testing system? |
We use GTest for unit tests and CTest for end-to-end (executable) testing. |
Hm, I must be doing something wrong. Here is my CMakeLists.txt: Project(CoverageExampleProject)
include(CTest)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH})
INCLUDE(CodeCoverage)
SET(CMAKE_CXX_FLAGS="-g -O0 --coverage")
SET(CMAKE_C_FLAGS="-g -O0 --coverage")
SET(CMAKE_EXE_LINKER_FLAGS="--coverage")
add_executable(CoverageExample CoverageExample.cpp)
target_link_libraries(CoverageExample gcov)
add_test(CoverageExampleTest CoverageExample)
add_custom_target(ctestTarget COMMAND ${CMAKE_CTEST_COMMAND})
SETUP_TARGET_FOR_COVERAGE(coverageTarget ctestTarget "testResults") and the output: ~/build/Examples/c++/CoverageExample2 $ make coverageTarget
-- Configuring done
-- Generating done
-- Build files have been written to: /home/doria/build/Examples/c++/CoverageExample2
[100%] Resetting code coverage counters to zero.
Processing code coverage counters and generating report.
Deleting all .da files in . and subdirectories
Done.
make[3]: ctestTarget: Command not found
make[3]: *** [CMakeFiles/coverageTarget] Error 127
make[2]: *** [CMakeFiles/coverageTarget.dir/all] Error 2
make[1]: *** [CMakeFiles/coverageTarget.dir/rule] Error 2
make: *** [coverageTarget] Error 2 Note that 'make ctestTarget' seems to work fine (it runs ctest). Any suggestions? |
Ah thanks, this is a bug: The script assumes that the second parameter is a valid target as well as a binary located in SETUP_TARGET_FOR_COVERAGE(coverageTarget ctestTarget "testResults") Obviously |
Makes sense. Let me know if you'd like me to test a patch. For the time being, I changed to : add_custom_target(ctest COMMAND ${CMAKE_CTEST_COMMAND})
SETUP_TARGET_FOR_COVERAGE(coverageTarget ctest "testResults") but I get:
Any thoughts? |
Maybe you are missing |
I have updated the coverage scripts in another project. I will test it there first. |
I tried it and noticed two things (I know you haven't tested yet, but I thought it may help):
Coverage_NAME seems to be empty This seems to be fixed by calling |
(Sorry we have parallel threads going) which I thought was the same thing, but apparently it is not? haha Also, FYI I learned that David |
I'd like to have aggregate code coverage reporting as well, but I'm unable to use ctest. I'm using catkin to build code in a ROS ecosystem and switching to a different build system is prohibitive. Simply creating a custom target that depends on the multiple Have you made any progress on this aggregation idea? If I get it to work, would you like a PR from me? Edit: I've got something working based on your work. Here's the relevant parts: Usage:
The Goods:
Command:
|
Is there a complete example somewhere of how to do this using |
Hi, I've written a small tutorial in #88 with a basic template to get started with Aggregation with |
Is there a way to aggregate the results of the coverage analysis? That is, it looks like CodeCoverage.cmake is a per-target (one per add_test()?) function. Say I have 10 subdirectories each with their own set of add_test() calls - how do I see the result as a coverage percentage for the whole project?
The text was updated successfully, but these errors were encountered: