objective c - Code coverage not showing results using Xcode + gcov -


i have been trying code coverage working iphone simulator , 0% coverage. below configuration details , steps have tried.

configuration

xcode 3.2.5/ios 4.1 , ios 4.2/mac 10.6/gcc 4.2 application uicatalog

references

http://www.cubiclemuses.com/cm/articles/2009/05/14/coverstory-on-the-iphone/

http://developer.apple.com/library/mac/#qa/qa2007/qa1514.html

steps

  • enable “generate test coverage files”
  • enable “instrument program flow”
  • add “-lgcov” “other linker flags”
  • uiapplicationexitsonsuspend flag in info.plist set true

result

i have .gcda files generated coverage show 0%.

settings tried

  1. changing gcc 4.0 , 4.2. when try change gcc 4.0 26 build errors.

  2. set environment variables

    (const char *prefix = "gcov_prefix"; const char *prefixvalue = [[nshomedirectory() stringbyappendingpathcomponent:@"documents"] cstringusingencoding:nsasciistringencoding]; // gets filepath app's documents directory const char *prefixstrip = "gcov_prefix_strip"; const char *prefixstripvalue = "1"; setenv(prefix, prefixvalue, 1); // sets environment variable tells gcov put .gcda files. setenv(prefixstrip, prefixstripvalue, 1); // tells gcov strip default prefix, , use filepath declared.) 
  3. gcc optimization set none (-o0) , unchecked precompiled prefix header file flag.

thanks info on stackoverfow , cubiclemuses

i have code coverage working both simulator , device! here steps , configuration worked me:

configuration : xcode 4 !

xcode project settings

build settings

  • other linker flags: add "-lgcov"

  • gcc_generate_test_coverage_files: set yes

  • gcc_instrument_program_flow_arcs: set yes

  • c/c++ compiler version: gcc 4.2 (if on xcode 4) ios deployment target: 4.2
  • precompile prefix header: no

info.plist

  • set uiapplicationexitsonsuspend flag in info.plist yes

above steps same simulator , device however, have work make work on device.

main.m: copy paste below code main.m

const char *prefix = "gcov_prefix"; const char *prefixvalue = [[nshomedirectory() stringbyappendingpathcomponent:@"documents"] cstringusingencoding:nsasciistringencoding]; // gets filepath app's documents directory const char *prefixstrip = "gcov_prefix_strip"; const char *prefixstripvalue = "1"; setenv(prefix, prefixvalue, 1); // sets environment variable tells gcov put .gcda files. setenv(prefixstrip, prefixstripvalue, 1); // tells gcov strip default prefix, , use filepath declared. 

note: make sure above code before:

nsautoreleasepool * pool = [[nsautoreleasepool alloc] init]; int retval = uiapplicationmain(argc, argv, nil, nil); [pool release];     return retval; 

why set above coverage variables?

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

how .gcda files?

use organizer in xcode download app's package device .gcda files out of documents directory.

note: not code coverage using xcode 3.2.5 same settings. xcode 4 cake-walk :-)


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -