Uploading C++ lcov coverage report (trace file)

Our builds happen on a different Jenkins slave and our tests are run on a different slave. So we generate a lcov trace file for each test suite we run on an individual slave and finally merge all the lcov trace file. Can we use merged lcov trace file to upload code coverage results to SonarQube? Should we be using sonar.cfamily.gcov.reportsPath to specify the path to lcov trace file? Is build wrapper required to upload code coverage for C++ code?

Hi @arjunurs,

it seems like you have an atypical setup. Coverage reports should be generated on the same machine of the analysis in order to make sure that file paths are identical. If you try to imports reports from a different workspace with different paths it wouldn’t work.

Hi @mpaladin,

We download the build and update the path. I’m able to generate code coverage reports using the genhtml tool that is include in the lcov package. My issue is specifically related to uploading results to SonarQube. I would like to confirm if SonarQube supports lcov tracefiles for C++ code coverage and if build wrapper is required during the build step to be able to upload code coverage results.

Hi @arjunurs,

our analyzer supports gcov format, to get to lcov I believe you probably need to generate gcov first.

No, if you only want to import coverage without analysing the project you don’t need build-wrapper, but you can only import coverage in such case.

@mpaladin We generate the lcov file from .gcno and .gcda files generated by the code coverage build. This is is what our code coverage build currently looks like. The final code coverage is aggregated and merged as lcov trace files. Can you recommend how we can either use this format or another compatible format with SonarQube?

Hi @arjunurs,

from lcov page:

LCOV is a graphical front-end for GCC’s coverage testing tool gcov. It collects gcov data for multiple source files and creates HTML pages containing the source code annotated with coverage information. It also adds overview pages for easy navigation within the file structure. LCOV supports statement, function and branch coverage measurement.

You can generate gcov files from .gcno and .gcda files using gcov tool, however I have no idea how you can merge them together.

Hi @arjunurs,

from http://gcc.gnu.org/onlinedocs/gcc/Gcov-tool-Intro.html :

Current gcov-tool supports the following functionalities:

  • merge two sets of profiles

Thanks @mpaladin. I will try it out. Hope it resolves the issue we have.