Coverage report - No green lines next to covered code

sonarcfamily
coverage

(Eliezer Ramm) #1

I am doing a PoC for a internal development group showing how Sonar deals with C code coverage. I compile with the gcov flag and run gcovr to export to xml which is then picked up with the “sonar.cfamily.gcov.reportsPath=” flag.

For a test i run the executable e.g myexec --version which generates gcda files.

When I use gcovr to generate html the report shows 100% coverage for the file main.c (whose job is simply to call the another function. (in the lines column 100% and 2/2 with a green background)

However when I look at the coverage report in Sonar (based on the imported xml file from gcovr) it shows me that the line of code is not covered by tests with red next to it.

image

If I call the code shouldn’t it be a green line next to it ? Also do I need gocvr to create the xml couldn’t I just point “sonar.cfamily.gcov.reportsPath=” to where the gcda and gcno files are ?

cmd line is

sonar-scanner-3.0.3.778/bin/sonar-scanner -X -Dsonar.scm.forceReloadAll=true -Dsonar.sources=/usr/local/src/ -Dsonar.language=c -Dsonar.cxx.coverage.reportPath=/usr/local/src/ -Dsonar.cxx.coverage.overallReportPath=/usr/local/src/gcovr.xml -Dsonar.cfamily.build-wrapper-output=/usr/local/src/son_out -Dsonar.projectKey=vcc-11.3

SonarQube version - 6.7.2.37468
SonarQube Scanner 3.0.3.778
SonarCFamily 5.1.0.10083


(G Ann Campbell) #2

Hi,

Your edit to add the analysis command line reveals the problem:

-Dsonar.cfamily.build-wrapper-output=/usr/local/src/son_out  # indicates you're using SonarCFamily analyzer
-Dsonar.cxx.coverage.reportPath=/usr/local/src/ # indicates you're using community cxx analyzer

You’re passing parameters for two different analyzers. Since you can’t be using both (my guess is that you’re using SonarCFamily), then the values for the one you’re not using are guaranteed to be ignored.

The docs should help.

 
Ann


(Eliezer Ramm) #3

I had tried using the flag from the cfamily and what I tested was my latest try based on a suggestion of a colleague.

So to see the coverage reports i would need
sonar.cfamily.coverage.reportPath=
sonar.cfamily.coverage.overallReportPath=

If not could you please supply the correct cli flags ?


(G Ann Campbell) #4

Hi,

The parameter you use depends on the coverage engine you’re using. You should check the docs for specifics.

 
Ann


(Eliezer Ramm) #6

Your link helped me solve the problem. Thank You. It was my error in thinking that the cxx plugin and the c family plugin deal with coverage info the same way. so in short if you are using the cfamily you need to generate the .gcov files for Sonar and if you are using the cxx plugin you need the gcovr report.

i used this link to generate a sample project
https://embeddedinn.wordpress.com/tutorials/test-coverage-analysis-with-gcov/

case closed :sunny: