Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

cocoa - 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 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...