I am generating code coverage data files (.gdca and .gcno) on an iOS project running on Xcode 4.5 using Apple LLVM Compiler 4.1.
Files are being generated under Library/Developer/Xcode/DerivedData/viewer-evgaabclrjcouydwveuptwroeofm/Build/Intermediates/viewer.build/Coverage-iphonesimulator/viewer_generic/viewer_generic.build/Objects-normal/i386.
All the (.o, .d, .dia, .gcda, .gdno) files are under this directory. There are no sub folders.
I am able to open individual .gcda files using Cover Story. Now I want to generate a report which can be viewed using cobertura.
I am trying to use gcovr for this. On terminal I got to the above folder
Command: gcovr -r `pwd` -x -v
Output:
(Several lines of similar output as below)
Running gcov: 'gcov /Users/abc/Library/Developer/Xcode/DerivedData/viewer-evgaabclrjcouydwveuptwroeofm/Build/Intermediates/viewer.build/Coverage-iphonesimulator/viewer_generic/viewer_generic.build/Objects-normal/i386/FILE_NAME.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /Users/abc/Library/Developer/Xcode/DerivedData/viewer-evgaabclrjcouydwveuptwroeofm/Build/Intermediates/viewer.build/Coverage-iphonesimulator/viewer_generic/viewer_generic.build/Objects-normal/i386' in '/Users/abc/Library/Developer/Xcode/DerivedData/viewer-evgaabclrjcouydwveuptwroeofm/Build/Intermediates/viewer.build/Coverage-iphonesimulator/viewer_generic/viewer_generic.build/Objects-normal/i386'
Parsing coverage data for file /Users/abc/Documents/Perforce/DPS-MacBookPro/depot/sandbox/Viewer-Labatt/Blue/viewers/ipadviewer/iphone/apps/viewer/Classes/view/zooming/FILE_NAME.mm
Filtering coverage data for file /Users/abc/Documents/Perforce/DPS-MacBookPro/depot/sandbox/Viewer-Labatt/Blue/viewers/ipadviewer/iphone/apps/viewer/Classes/view/zooming/FILE_NAME.mm
Gathered coveraged data for 0 files
<?xml version="1.0" ?>
<!DOCTYPE coverage
SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
<coverage branch-rate="0.0" line-rate="0.0" timestamp="1354144430" version="gcovr 2.4 (r2774)">
<sources>
<source>
/Users/abc/Library/Developer/Xcode/DerivedData/viewer-evgaabclrjcouydwveuptwroeofm/Build/Intermediates/viewer.build/Coverage-iphonesimulator/viewer_generic/viewer_generic.build/Objects-normal/i386
</source>
</sources>
<packages/>
</coverage>
I am seeing a warning: gcno:version '404', prefer '402'
Please help me figure out why gcovr is unable to produce the report.
Tl;dr: The code coverage files that LLVM outputs are newer than the ones expected by gcovr. If you replace your version of gcovr with the linked version (version 2.4), then it should work. Maybe.
Back before LLVM, Xcode used GCC as its compiler. GCC included a tool called 'gcov', which generated all those files, .gcno, .gcda and their ilk.
Back then, Macs came preinstalled (and still do) with GCC version 4.2. So Xcode would compile your project with gcc 4.2, and then run gcov version 4.2, which would generate 4.2-versioned test coverage files. This worked fine for gcovr, because the pre-2.0 alpha version seems to have been written with gcov 4.2 in mind.
But when Apple switched to LLVM, things went squirrely. LLVM also outputs gcov-style test coverage files, if you set the 'Generate Test Coverage Files' flag in your target settings. BUT, LLVM defaults to outputting gcov 4.4 files, NOT 4.2.
This person had the idea that if we could tell LLVM to output the 4.2 version of the files (I think it may technically be able to), then it would solve the problem. That's probably true, but I don't know how to do that.
I did however, find a solution for myself. I opened up terminal, and checked my version of gcovr:
gcovr --version
It told me that my version of gcovr was actually gcovr 2.0-prerelease. This version doesn't support the gcov 4.4 versions of the test coverage files.
So I found a version that does.
Here's the page where it is hosted: https://software.sandia.gov/trac/fast/wiki/gcovr
And here is the link to the script itself: https://software.sandia.gov/trac/fast/export/2800/gcovr/trunk/scripts/gcovr
This script is gcovr 2.4, which supports up to gcc 4.8. Theoretically, it should be quite happy with the 4.4 versions of the test coverage files that LLVM outputs. That warning is now completely gone for me. Give it a shot, let me know how it goes!
Are you properly specifying the your object directory path? According to the gcovr documentation
--object-directory=OBJDIR: Specify the directory that contains the gcov data files. gcovr must be able to identify the path between the *.gcda files and the directory where gcc was originally run. Normally, gcovr can guess correctly. This option overrides gcovr's normal path detection and can specify either the path from gcc to the gcda file (i.e. what was passed to gcc's '-o' option), or the path from the gcda file to gcc's original working directory.
The following command works for me when run under the root directory of your project.
gcovr -r . --object-directory path_to_coverage_files -x > coverage.xml
Where the path_to_coverage_files is the directory where all your (.o, .d, .dia, .gcda, .gdno) files are.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With