SonarQube not showing code coverage for OpenCppCoverage with export_type=cobertura

  • using, sonarqube-9.4.0.54424 developer edition and sonar-scanner-4.7.0.2747-windows
  • My project is having C, C++ languages. I am able to run sonar-scanner and results are shown on dashboard using build-wrapper-win-x86.
    But the coverage is showing zero.
    I am using googletest for unit test cover and creating code coverage report in cobertura (xml) formal using OpenCppCoverage.
sonar.coverageReportPaths=./ctestCoverage.xml
sonar.cobertura.reportPath=./ctestCoverage.xml
sonar.flex.cobertura.reportPaths=./ctestCoverage.xml

  • I tried above things but for 1st line throwing parsing error and remaining lines are not reflecting in logs.
ERROR: Error during SonarScanner execution
ERROR: Error during parsing of the generic coverage report 'C:\REPO\ctestCoverage.xml'. Look at SonarQube documentation to know the expected XML format.
ERROR: Caused by: Unknown report version: 0. This parser only handles version 1.

Is there any way to support cobertura xml for c++ project or any option to generate sonar supported report using OpenCppCoverage?

Thank you

Welcome to the community, @pratikmhatre!

Thank you for the report, I have checked OpenCppCoverage, and the tool support exporting in Cobertura and internal binary format. We currently do not support importing either of them.

One possibility would be to convert them into the generic coverage format and provide a path to the report as sonar.coverageReportPaths. Note that this property accepts reports in this format. Providing a report in another format will cause an error that you are encountering, so you should remove this line unless the report format is transformed.

Regarding other options:

  • sonar.cobertura.reportPath is not recognized by our analyzer and seems to be used by following thirdParty plugin.
  • sonar.flex.cobertura.reportPaths applies only to code in the Flex language and it does not apply for C++ code

Hi,

FYI, we’ve just added support for Cobertura reports for C and C++:

 
HTH,
Ann

1 Like

Hello Ann,
When will the version of SonarQube that supports this feature be released?
Thx.
S.-P.

Hi @Simon-Pierre_Cadieux

Welcome to the community!

It’ll be included in 10.2, E.T.A. Wednesday the 6th.

 
:smiley:
Ann

1 Like

You can see it in action on this example project.

2 Likes

Hello,

I am passing a code coverage report generated by OpenCppCoverage [0.9.9.0] to SonarQube 10.2. The report contains references to Windows external 3rd party libraries as I didn’t make use of the --excluded_sources command line parameter.

E.g. 12:02:05.860 WARN: Cannot resolve the file path ‘j\c3ipr\pr_1860_3_12_9.short\6625a0\1\source_subfolder\libs\filesystem\src\codecvt_error_category.cpp’ from the Cobertura coverage report

In order to prevent these kinds of warnings and avoid third party source code to be taken into consideration into the code coverage percentage I defined in sonar-project.properties the following property following the syntax as per the ignore-code-coverage page:

Exclude external references:

sonar.coverage.exclusions=**\commandtypeslib**, **\configurationtypeslib**, **\distributedloggingtypes**., **\source_subfolder**., **\vctools**., **\externalapis**., **\connextdds**.

I confirmed that the settings are in effect by looking at the log file

12:01:59.137 INFO:   Excluded sources for coverage: **\commandtypeslib\**\*, **\configurationtypeslib\**\*, **\distributedloggingtypes\**\*, **\source_subfolder\**\*, **\vctools\**\*, **\externalapis\**\*, **\connextdds\**\*

however I am still getting the above warnings. Any suggestion on how to resolve this from the SonarQube configuration side will be appreciated.

Thx,

Simon-Pierre

Hi Simon-Pierre,

Please create a new thread.

 
Ann