2

I've been trying to get GCov working with Xcode 4.2Build 4D199 on Lion with iOS SDK 5.0 to no avail. Has anyone had any luck with this? I'm using Google Tools For Mac for my unit tests and I've linked in libprofile_rt.dylib and added:

"OTHER_CFLAGS[arch=*]" = (
    "-ftest-coverage",
    "-fprofile-arcs",
    "-falign-loops=16",
);

as indicated on the Coverstory page here http://code.google.com/p/coverstory/wiki/UsingCoverstory But when I find . -name *.gcda" I come up empty. What am I missing?

Cliff
  • 10,586
  • 7
  • 61
  • 102

2 Answers2

4

GCov is no longer supported in XCode 4.2. You'll note that if you go their "man page" for it, XCode 4.2 is not an option in the drop down list. Furthermore, if you look at the compile, it's using "c++", which is linked to llvm-g++-4.2. They now exclusively use the Clang/LLVM tool chain (which in turn often makes use of the gcc tool chain) instead of giving you the option of directly using the gcc tool chain. A consequence of this is that doing code coverage in XCode4 with gcov is no longer directly available. This also can affect compiles using CMake that bypass XCode 4. That first link gives you instructions on how to change your project to use profile_rt instead of gcov.

Ben Hocking
  • 7,790
  • 5
  • 37
  • 52
  • I appreciate you response, however I still continue to experience trouble. See my latest post: http://stackoverflow.com/questions/8459330/code-coverage-on-ios-using-xcode-4-2-on-lion/8476639#8476639 – Cliff Dec 19 '11 at 04:28
  • Indeed. I had read the link and had thought that it would solve my problems, but had not had time to try it out at the time. I can't even get it to work on my Mac _outside_ of XCode. – Ben Hocking Dec 20 '11 at 23:23
  • Haha! I just caught your xkcd ref above! I still have no luck here. I've tried building llvm/clang from source and I get a x64 libprofile_rt.dylib binary that doesn't agree with the iOS simulator. The original crashes with a bad executable path. What do I do? – Cliff Dec 21 '11 at 16:37
  • That's a good question, Cliff. I've gone through the canonical example at http://www.network-theory.co.uk/docs/gccintro/gccintro_81.html and couldn't get it to work, even from the command line. – Ben Hocking Dec 24 '11 at 02:02
  • @Cliff: I've asked my own question here: http://stackoverflow.com/questions/8622293/no-code-coverage-with-mac-os-x-lion-and-xcode-4-llvm-g-4-2 – Ben Hocking Dec 24 '11 at 02:29
2

How to generate coverage test reports (Xcode 4.5 edition)

  1. cd to your Xcode project and type

    git clone git@github.com:j4n0/XcodeCoverage.git
    cd XcodeCoverage
    wget http://downloads.sourceforge.net/ltp/lcov-1.10.tar.gz
    tar -zxvf lcov-1.10.tar.gz
    
  2. Set the following build properties on both your main target and your SentestKit target, but only for the Debug configuration (expand the node, there are Debug and Release entries):

    Generate Profiling code       Yes
    Generate Test Coverage Files  Yes
    Instrument Program Flow       Yes
    
  3. Install Xcode command line tools: Xcode > Preferences > Downloads > Command Line Tools.

  4. In your main target, add a “Run Script” build phase to execute ./XcodeCoverage/exportenv.sh

  5. Build your application, and run the tests.

  6. Generate the coverage report from the XcodeCoverage typing: ./getcov
    Upon completion, the script will launch a browser with the html output.

If reports are not generated try this:

  • Edit the plist of your application and add the following:
    <key>UIApplicationExitsOnSuspend</key>
    <true/>
    
    Then run your application and press Home. This will quit cleanly and generate the gcda files.
  • If it still doesn't work, try using the iPad simulator instead.

For more tips and tricks check the talk Code Coverage on iOS by Richard Buckle.

Jano
  • 62,815
  • 21
  • 164
  • 192
  • Good info! I had done this already, however my question was regarding the generation of the coverage files ".gcno & .gcda" which are a pre-requisite to lcov. This probably belongs in a separate discussion but I've upvoted just the same. – Cliff Jan 27 '13 at 17:03
  • To generate gcno and gcda you only need the settings `Generate Test Coverage Files`, `Instrument Program Flow`, and to quit the application cleanly. Not sure about Generate Profiling code, I know Apple tools don't use it. With Xcode 4.5, no more flags or dlybs are needed. – Jano Jan 27 '13 at 18:49
  • Exactly, I posted my question way before XCode 4.5 back when Apple started changing the tools and disabling support for code coverage. Back then you had to resort to the dark arts of compiling a custom LLVM until they posted an update. – Cliff Jan 28 '13 at 17:38