SonarCFamily C branch coverage with gcov misses some branches


I have an issue with code coverage reporting in SonarQube. More specfically, I have C code that is analyzed by sonar-scanner, and I use the cmocka (v1.1.5) unit testing framework to run some unit tests. These unit tests generate note files that are then parsed by gcov (v7.5.0) to produce .gcov files, which are in turn parsed by sonar-scanner.

My issue is with branches coverage: some branches are considered by SonarQube as “Not covered by tests”, even though the .gcov file indicates otherwise; on the other hand, most branches are parsed just fine. For instance, I have the following piece of code (the red line hover text reads “Not covered by tests (2 conditions).”):

and the corresponding piece of .gcov file (rest of file removed for privacy):
source.c.gcov.txt (941 Bytes)

The branch annotations are visible in the .gcov file.
Additionally, when I generate a branch coverage report locally on my development machine using lcov, it reports 100% branches coverage.
Furthermore, from a logical standpoint, I don’t understand how the branches could not be taken whereas the lines contained in both branches are actually covered (see picture above).

Note that gcov is invoked with the -b option.
I am using SonarCFamily v6.11.0 on SonarQube Developer Edition v8.4.1 with sonar-scanner v4.4. The machine hosting the sonar-scanner is a Linux Ubuntu 18.04 (amd64).

Is there something I’m missing? Could a misconfiguration on my part lead to such a behaviour?


Ok so, long story short: it was a misconfiguration on my part :sweat_smile:

More specifically, it all started when I forgot to set the sonar property sonar.cfamily.gcov.reportsPath. It’s usually no big deal, as such a mistake can be easily detected by looking at the dashboard and seeing a 0% coverage rate.

On my instance however, I have this toolchain called VHDLTool set up, which I use to analyze some VHDL code in SonarQube. As part of the toolchain, I installed the sonar-coverage-ghdl plugin, which is supposed to import gcov-like coverage reports on VHDL source files into SonarQube.

It so happens that said plugin doesn’t need to be told where to find the gcov files, but instead scans the whole repository to find them. Since the CFamily gcov sensor hadn’t been told where to find the coverage reports, coverage processing somehow fell back to that other “clever” ghdl plugin. As a result, the coverage reports on my C code were processed by the VHDL coverage plugin since the beginning, which effectively masked the mistake for a good while…

Anyway, it’s solved now.

Hi @gvuspace,

glad you found the misconfiguration! Thank you for the update.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.