Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dozens of "profiling:invalid arc tag" when running code coverage in Xcode 5

When running my Test target with code coverage enabled in Xcode 5, I get dozens of the following message in the build output:

profiling:invalid arc tag (0x...)

It doesn't seem to affect the tests, as they complete successfully, and also the GCDA coverage files are generated as expected.

Any idea what the message means, or how to suppress the messages/fix the issue, because they clutter up the build output and make it hard to find the test case results.

like image 941
jasonjwwilliams Avatar asked Mar 19 '14 22:03

jasonjwwilliams


4 Answers

Most likely this is a result of the build tools failing to merge current results into the existing .gcda coverage files. As Dave Meehan points out here, there is a brute force way of dealing with this by cleaning the product build folder, but a less hard core approach is to delete the .gcda files from targets generating them (for me, just the test target) as part of the build process. Dave includes a sample script to be included as a build phase -- or, at the project root by hand:

find . -name "*.gcda" -print0 | xargs -0 rm
like image 80
jstevenco Avatar answered Oct 20 '22 06:10

jstevenco


For the Xcode 7 users out there, you might have been wondering why your Unit Tests crash after receiving messages like this. The solution I found was that you need to make sure that all possible targets involved in your build flow (including all libraries) should have these two build settings set to NO:

GCC_GENERATE_TEST_COVERAGE_FILES = NO;
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO;

If you search for the "Code Generation" section in the build settings you will find these as "Generate Test Coverage Files" and "Instrument Program Flow".

For further reference see https://developer.apple.com/library/ios/qa/qa1514/_index.html

like image 30
skensell Avatar answered Oct 20 '22 05:10

skensell


Old question, but now Xcode 7 GM is out, and this behavior hasn't changed, I took a deeper look. The issue, I believe is that code coverage of the test app target is conflicting with code coverage of the main target.

Assuming you don't actually care about code coverage of your test target these settings stop the errors for me, with no need for extra scripts or deleting files:

In your main target (be it a framework, or an app) set:

 Enable Code Coverage Support to YES
 Generage Legacy Test Coverage Files to YES
 Instrument Program Flow to YES

For my purposes I only did this for Debug builds, but your needs may vary.

Then in your Tests target set:

 Enable Code Coverage Support to NO
 Generage Legacy Test Coverage Files to NO
 Instrument Program Flow to NO

This has resolved the error messages, and still allowed the code coverage files to be created appropriately.

Again, the question is old, but as the error still is issued in XCode 7, I found this solution works better than deleting files with special scripts.

like image 27
A. Johns Avatar answered Oct 20 '22 04:10

A. Johns


I'm having the same issue. In my appDelegate under applicationWillTerminate: I have the __gcov_flush();. Commenting this out removes the invalid arc tag messages in my build output.

I'm doing further research to figure out why this happens. I know that if I completely clean my project and delete the DerivedData directory these messages will stop for a few runs of my tests.

EDIT: I seemed to have fixed this for me. In my appDelegate I had the following:

#ifdef DEBUG
+ (void)initialize {
    [[NSUserDefaults standardUserDefaults] setValue:@"XCTestLog,GcovTestObserver"
                                         forKey:@"XCTestObserverClass"];
    [super initialize];
}
#endif

I spelled GcovTestObserver wrong, and after fixing this the messages stopped. Make sure you also have a subclass of XCTestObserver in your Test target overriding stopObserving with the following:

- (void) stopObserving
{
    [super stopObserving];
    UIApplication* application = [UIApplication sharedApplication];
    [application.delegate applicationWillTerminate:application];
}
like image 31
xthule Avatar answered Oct 20 '22 04:10

xthule