Question

I would like to know how I can generate gcda files when an iOS application is running unit tests on an Xcode bot.

I used this blog to configure Xcode to generate test coverage files and generate a report using a script that utilizes lcov. I can consistently create the coverage files and the report on my development computer but when the bot attempts the same process, no .gcda files appear. When calling __gcov_flush() on the bot, I can see the following error in the log:

profiling:/Library/Server/Xcode/Data/BotRuns/Cache/c0jhd288-c473-c473-2432-f8219hdh98dh89/DerivedData/Build/Intermediates/AppName.build/Debug-iphonesimulator/appName.build/Objects-normal/i386/ClassName.gcda: cannot open

I know this is occurring during the application's gcov flush because I placed a log directly before and after the call"

NSLog(@"[application performSelector:@selector(gtm_gcov_flush)]; will be CALLED");
[application performSelector:@selector(gtm_gcov_flush)];
NSLog(@"[application performSelector:@selector(gtm_gcov_flush)]; was CALLED");

NOTE: gtm_gcov_flush only calls __gcov_flush() and nothing else.

Searching for "profile gcda: cannot open" lead me here, but I am already following the suggested requirements by following the above blog link. It is possible there are some permission issues but that seems unlikely since Xcode is the one generating the gcda files.

I have checked the /Library/Server/Xcode/Data/BotRuns/, /Users/username/Library/Developer/Xcode/DerivedData/, and /var/_xcstest directories and their subdirectories for gcda files and there are none in sight. However, there are gcno, o, d, and dia files in /Library/Server/Xcode/Data/BotRuns/Cache/c0jhd288-c473-c473-2432-f8219hdh98dh89/DerivedData/Build/Intermediates/AppName.build/Debug-iphonesimulator/appName.build/Objects-normal/i386/ (where there should be gcda files).

Like I said, I have had zero issues with the while running locally. The script XcodeCoverage/getcov is being called in the post-action phase of Archive in my scheme. I am using Xcode 5.0.2 on my development mac as well as via Xcode service on the CI server. Unit tests are being ran with the XCTest framework.

Thanks for your help in advance!

Was it helpful?

Solution

Well, looks like it really was a permission issue as suspected. I found a great reference for generating code coverage reports using Xcode 5+:

http://www.bubblefoundry.com/blog/2013/11/code-coverage-revisited/

As described in the above article, there are two users that manage Xcode bots, _teamserver and _xcstest. _xctest does not have the same permissions as _teamserver, so the permissions of the .gcda files' destination folder must be set to allow access by _xctest (i.e. group access to the folder). I implemented the script as suggested by the article but my CI server crashed during while archiving. Apparently at the time of archiving, the folder reference does not exist. So I updated it to:

# Setting these permissions is required to successfully flush
# test coverage data with __gcov_flush();

if [ -d ${OBJECT_FILE_DIR_normal}/i386 ]; then
    chmod 775 ${OBJECT_FILE_DIR_normal}/i386
fi

Other than just successfully generating the coverage files, I also copied them to another folder. My test coverage report is generated in the post-action phase of Archive and I could not find a way to access those files during that stage. The reason is they are generated in

/Library/Server/Xcode/Data/BotRuns/Cache/c0jhd288-c473-c473-2432-f8219hdh98dh89/DerivedData/Build/Intermediates/AppName.build/Debug-iphonesimulator/appName.build/Objects-normal/i386/

But the archive is run in:

/Library/Server/Xcode/Data/BotRuns/Cache/c5f4462c-c473-c473-2432-5ac4d0b46nal/DerivedData/Build/Intermediates/ArchiveIntermediates/AppName/BuildProductsPath/Release-iphoneos/

There may be a clever way to export the directory of coverage files at reference later but I am not sure. Finally, I'm not a super user of the terminal by any means, so please feel free to provide suggestions!

Just to note, I also referenced these blogs to help through configuration:

http://matt.vlasach.com/xcode-bots-hosted-git-repositories-and-automated-testflight-builds/

http://qualitycoding.org/xcode-code-coverage/

http://ikennd.ac/blog/2013/10/xcode-bots-common-problems-and-workarounds/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top