Code coverage not showing results using Xcode + gcov

前端 未结 4 1397
一生所求
一生所求 2020-12-03 01:52

I have been trying to get the Code coverage working for iPhone simulator and always get a 0% coverage. Below are the configuration details and the steps that I have tried.

相关标签:
4条回答
  • 2020-12-03 02:25

    Thanks Sangavi since your answer helped me.

    Now the but: I followed your descripition step by step and than I had the problem that no gcda-files were created (only gcdo-files).

    After that I removed your (above) prefix-code which I copied in the main.m and everything worked suddenly. Bet the gcov-path was not created correctly or something.

    Just posting this if anyone runs into the same issue.

    0 讨论(0)
  • 2020-12-03 02:27

    Thanks for all the info on stackoverfow and CubicleMuses

    I have code coverage working for both simulator and device! Here are the steps and configuration that worked for me:

    Configuration : Xcode 4 !

    XCode project settings

    Build Settings

    • Other Linker Flags: add "-lgcov"

    • GCC_GENERATE_TEST_COVERAGE_FILES: Set to YES

    • GCC_INSTRUMENT_PROGRAM_FLOW_ARCS: Set to YES

    • C/C++ Compiler Version: GCC 4.2 (if you are on XCode 4) iOS deployment target: 4.2
    • Precompile prefix header: NO

    Info.plist

    • Set UIApplicationExitsOnSuspend flag in your Info.plist to YES

    Above steps are same for Simulator and Device however, we have some extra work to make it work on Device.

    Main.m: Copy paste the below code to main.m

    const char *prefix = "GCOV_PREFIX";
    const char *prefixValue = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] cStringUsingEncoding:NSASCIIStringEncoding]; // This gets the filepath to the app's Documents directory
    const char *prefixStrip = "GCOV_PREFIX_STRIP";
    const char *prefixStripValue = "1";
    setenv(prefix, prefixValue, 1); // This sets an environment variable which tells gcov where to put the .gcda files.
    setenv(prefixStrip, prefixStripValue, 1); // This tells gcov to strip the default prefix, and use the filepath that we just declared.
    

    Note: Make sure the above code is before:

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];    
    return retVal;
    

    Why we set the above coverage variables?

    http://gcc.gnu.org/onlinedocs/gcc/Cross_002dprofiling.html

    How to get the .gcda files?

    Use the Organizer in Xcode to download app's package from the device to get the .gcda files out of the Documents directory.

    Note: I could not get the code coverage using Xcode 3.2.5 with the same settings. But Xcode 4 was a cake-walk :-)

    0 讨论(0)
  • 2020-12-03 02:32

    I just figured out after hours of frustration that enabling distributed builds in Xcode 3.2.6 will work around the need to disable your prefix header.

    0 讨论(0)
  • 2020-12-03 02:33

    I had the problem that no files were created at all. This was in Xcode 4.1 on Lion.

    I changed the compiler from System Default (GCC 4.2) to GCC 4.2. So NOT use the system default.

    Seems like a bug in Xcode, but it solved the problem for me.
    When i changed back the preference the problem returned.

    0 讨论(0)
提交回复
热议问题