Reputation: 2881
I need to switch a cmake based project from g++ to clang for some reasons. I've made the switch to llvm-11 on Ubuntu 20.04. I got the project itself compile, unit tests work as well. Though, getting coverage reporting working again seems tough.
I need to create a cobertura xml file in order to integrate it into the existing CI/CD infrastructure (Jenkins and Gitlab). I've been using an older version of [1] for cmake cobertura reporting.
I thought 'llvm-cov gcov' should do the trick for me already to do the switch, but I just end up with an empty xml file with no error reported.
Next to the empty xml there is a new default.profraw file generated by llvm-cov that ends up in the build directory. I got so far as to figure out that the .profdata file format which llvm-profdata can convert to seems to be more promising as intermediate format for conversion than the raw data format. So I've generated a .profdata file for testing from that using:
llvm-profdata-11 merge -sparse default.profraw -o default.profdata
And I can generate an HTML file from this as well which actually contains expected coverage:
llvm-cov show my-unit-tests -instr-profile=default.profdata ../src/*.cpp -path-equivalence -use-color --format html > coverage.html
Here is also the related snippet from the CMake file:
append_coverage_compiler_flags()
setup_target_for_coverage_gcovr_xml(
NAME coveragereports
EXECUTABLE my-unit-tests
DEPENDENCIES my-unit-tests my-app-lib-testing
#BASE_DIRECTORY "coverage"
#BASE_DIRECTORY "../"
EXCLUDE "${CMAKE_SOURCE_DIR}/libraries/*" "${CMAKE_SOURCE_DIR}/test/*" "/Library/*"
)
What tools / options do I have to convert the coverage data generated by clang(11) to cobertura xml?
[1] https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
Upvotes: 8
Views: 1915
Reputation: 69
llvm-cov
could produce a report in lcov
format that could be easily converted to Cobertura. Use something like lcov-cobertura Python module or anythong else.
Upvotes: 1