views:

432

answers:

3

Hi,

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.

+1  A: 

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

refulgentis
A: 

Can u explain how do u set these variables(GCOV_PREFIX & GCOV_PREFIX_STRIP) so that *.gcda are placed in Documents directory of testing application. I'm speaking about testing on the Device. I tried many solutions such as: - set prefix variable to let's say /tmp and GCOV_PREFIX_STRIP=1 before building application in Xcode - set prefix variable to let's say /tmp and GCOV_PREFIX_STRIP=1 while logged in to iPhone by ssh(i have jailbroken phone)

None of the above helped me. I'm getting:


profiling:/Users:Cannot create directory
profiling:/Users/krasnyk/Documents/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/Calculator.gcda:Skip

while debugging which definitely shows that the application does not see the set up variables. When I start "Terminal" appliaction on my iPhone & check the variables it seems to me that these are set:


mobile$ echo $COV_PREFIX
/tmp
mobile$ echo $COV_PREFIX_STRIP
1

So what am I doing wrong?

I also tried to create the directory tree the same as i have on my Mac(just the path to the directory when *.gcda files would be place if i could test the application on my mac) - it worked but it is to hard solution - cannot be easily automated.

Any ideas?

krasnyk
A: 

Ok I figured it out. Environment variables GCOV_PREFIX & GCOV_PREFIX_STRIP should be set by the application code using for example setenv() function.

krasnyk