3

I'm trying to get the code coverage for my unit tests (Xcode 4.2.1 (4D502) on Mac OS X Lion 10.7 (11A2061)), but somehow the .gcda files don't get created. I can see .d and .o files in .../Objects-normal/i386 folder of the unit test target, but the gcno/gcda files are missing for the files being unit tested, and hence I can't generate the coverage statistics for whats being tested.

On the main target, I do see .d, .o and .gcno files for every file.

So, I believe I have the project settings set up correctly, but there's a "small" something really missing for OS X Lion. I've tried the steps mentioned in http://code.google.com/p/coverstory/wiki/UsingCoverstory, but doesn't seem to have solved my problem.

Note: I was able to get this to work on Snow Leopard and view coverage statistics using CoverStory!!

Any solution/ direction in this regard would be highly helpful. Thanks!!

Ram
  • 31
  • 4

2 Answers2

4

I was missing gcda files but found solution on some website. You need to add these flags:

-fprofile-arcs -ftest-coverage

to "Other C flags". After running tests gcda files are present.

gcno files are generated after setting both "Generate Test Coverage Files" and "Instrument Program Flow" to YES.

I'm using Xcode 4.3.2 and llvm compiler.

Alternatively, I have found that setting Generate Profiling Code to YES also causes gcda files to be generated.

Mateusz
  • 314
  • 1
  • 5
1

Make sure the following build settings are in place for your code and your tests:

GCC_PREPROCESSOR_DEFINITIONS = GCOV_ENABLED=1

GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES

GCC_GENERATE_TEST_COVERAGE_FILES = YES

Building/running the tests should create the missing gcda files. I run into this enough that I have an xcconfig file template that includes the above. You do not have to link against the gcov library with recent versions of Xcode.

quellish
  • 21,123
  • 4
  • 76
  • 83