Skip to content

Coverage tracers

Günter Wirth edited this page May 13, 2014 · 18 revisions

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. Collect the coverage information and generate the report using gcovr:
gcovr -x -r . > report.xml

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:mstest_coverage.xml out.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:

Clone this wiki locally