How to set up gcov for code coverage analysis in iPhone SDK?
I've recently begun unit testing an app I write for the iPhone. I have the basics of creating my own tests down, even if it seems a little sub-optimal. I am, however, having real trouble setting up code coverage analysis using gcov.
I followed the instructions here: http://www.cubiclemuses.com/cm/articles/2009/05/14/coverstory-on-the-iphone/, which are repeated开发者_Go百科 very similarly in other places. I've tried using Google's AppleScript from their toolbox for Mac to do it just in case I was entering something wrong in Xcode.
I've used Apple's iPhoneUnitTests sample as a base project, and simply running Google's AppleScript to enable code-coverage testing against the CalcTests target to get a well-sourced, automated example of it not working. No matter what scenario I use, my own code, Apple's, manually setting the proper variables or letting Google's AppleScript do it for me, all I get are these errors in the debug console once the tests are finished running:
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/CalcViewController.gcda:Skip
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/Calculator.gcda:Skip
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/CalcAppDelegate.gcda:Skip
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/main.gcda:Skip
The gcda files are not created, and thus I have nothing to analyze. Any help with this would be greatly appreciated.
The solution is that these guides refer to running code in the iPhone simulator. Because I'm running application level tests, I'm cross-profiling and need to follow this information.
I then set the environment variable GCOV_PREFIX to dump it in my application's Documents directory, and then I use the Organizer in Xcode to download my app's package from the device to get the .gcda files out of the Documents directory. This is rather cumbersome and hardly lends itself to automatic coverage testing, but it is the only solution I can see given the constraints of running in a sandbox and using classes that are only available for testing on the device (namely MediaPlayer.framework).
精彩评论