Skip to content

Coverage tracers

guwirth edited this page Mar 10, 2021 · 18 revisions

This description is only valid for cxx plugin version 1.x

Gcov / gcovr

  1. Make sure to compile and link with the --coverage flag. Disable optimizations and switch on debugging.
  2. Execute your application / your tests. This will generate .gcda files.
  3. Execute gcov to use the .gcda files precedently generated, it will generate .gcov files somewhere you define.
  4. Collect the coverage information and generate the report using gcovr:
gcovr -r WHERE_SONAR_SCANNER_WILL_RUN -x --object-directory=ABSOLUTE_PATH_TO_GCOV_FILES_FOLDER > report.xml

Hints:

  • cxx plugin requires gcov coverage reports with paths in the generated xml reports.

Bullseye

Create the XML coverage report with:

covxml -f UTCoverage.cov -o bullseyecoverage-result-0.xml

To merge two coverage files (e.g. to obtain the overall coverage):

covmerge -c ITCoverage.cov UTCoverage.cov -f ALLCOVERAGE.cov

Microsofts Code Coverage

Prerequisites

  • Visual Studio Premium or Visual Studio Ultimate 2010, 2012 or 2013
  • MSDN: Using Code Coverage to Determine How Much Code is being Tested
  • With Visual Studio 2012 the file CodeCoverage.exe is normally located in 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Dynamic Code Coverage Tools'.
  • With Visual Studio 2013 the file CodeCoverage.exe is normally located in 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Dynamic Code Coverage Tools'.
  • The CodeCoverage.exe runs as master of the unit test runner.

Creating the coverage report for SonarQube is a two step process:

(1) Generate a coverage file with:

CodeCoverage.exe collect /output:out.coverage [...]

where [...] is your test client. Example below is for Visual Studio:

mstest.exe /testmetadata:.\some.vsmdi /testlist:03_COMP_smoke/clientAndServer/pass /runconfig:.\localtestrun2010.testrunconfig /resultsfile:testResults.trx

(2) Convert the resulting coverage file into an XML file:

CodeCoverage.exe analyze /output:result.xml out.coverage

With this option it is also possible to merge several coverage results into one XML file.

CodeCoverage.exe analyze /output:result.xml out1.coverage out2.coverage

(3) Read coverage file with SonarQube

Define the location of your coverage file in the SonarQube configuration file (sonar.cxx.coverage.reportPath) and start the sonar runner to read it.

Hints:

Testwell CTC++

Please see Get-code-coverage-metrics for more information about execution and import of Testwell CTC++ coverage reports

Clone this wiki locally