How to make xcode4 code-coverage with llvm cumulative across application executions - xcode

I have code coverage in XCode 4.2 with libprofile_rt working. I have noticed that the coverage files are reset for every execution of my program. This is different from the way gcov worked and its something I need to work (since my tests execute across multiple runs of my app). Can someone point me to the way to make libprofile_rt generate cumulative coverage?

actually looks to be an existing bug in LLVM: http://llvm.org/bugs/show_bug.cgi?id=11457

You don't need to include *libprofile_rt.dylib* and use *-profile_rt* flag when running project in xCode 4.4.1 (works with iOS Simulator like a charm) Just set these flags:
Generate Test Coverage Files: YES
Instrument Program Flow: YES
Build and run. In case you runt Test-target of your app, *.gcda files are created automatically because tested app terminates, in case of running regular target, *.gcda files are created when you explicitly kill your app (the other approach is to set UIApplicationExitsOnSuspend = YES in .plist)
Please note, it was well tested on new project created with xCode 4.4.1
Code coverage files will be output to /Build/Intermediates/.build//.build/Objects-normal/

Related

Xcode mach-o linker error when archiving project with test targets

I'm getting mach-o linker errors pointing to missing files in my test targets when I try to create an archive, I can build and run my app on both on the simulator and device without any problems though. I've tried looking at the bundle loader and test host configurations for the test targets, and both look fine. What else could cause this?
In my statution, i solve this issue to change Bit Code Enabled from Build Settings. if you use 3.party framework in your project and these framework is not supported bit code for compression in release time. You must change Bit Code Enabled flag from YES to NO.
i hope this will help someone.
Not the exact solution, but I realized that I don't want or need my unit tests to run during archived builds. If anyone else is having this problem try checking your scheme's build settings to make sure your test targets are not being built when you build for archiving.
Select your scheme -> Edit Scheme -> Build and uncheck Archive for your test targets.

How can I get Xcode to Compile my code instead of doing Build AST?

I just converted a Framework project from Xcode 3 to Xcode 4. I've been building this project for years under every version of Xcode and Project Builder.
For some reason, Xcode 4 runs Build AST on all of my classes rather than Compile, which doesn't actually build the framework executable. On digging into it I found that this passes the -fsyntax-only flag to clang which tells it to stop after producing an Abstract Syntax Tree for each class. I have another Framework that builds fine in Xcode 4, and I've compared the build settings without uncovering anything that looks like it would cause this.
Does anyone have an idea what would make Xcode want to perform the Build AST action rather than Compile? And more to the point, how to turn that behavior off?
Thanks for any ideas...
Okay, I found that in my case I had a custom Build Rule for '*.i' files in my project. The clang build process apparently produces .i files (along with several others) as an intermediate product, so this rule was interfering and stopping it from completing all stages of the build. Removing the custom Build Rule allowed everything to build normally.

What is required to generate code coverage data using XCode 4

I have been trying to generate code coverage data for my application on XCode 4.2.1 (build 4D502) using the steps outlined at http://code.google.com/p/coverstory/wiki/UsingCoverstory
I am obviously missing something as there are no .gcno or .gcda files being generated along side my object files. I've tried adding the settings to both my test target and my application target but to no avail. I've had a second set of eyes go over things and all appears to be in order. Any ideas as to what is missing. Thanks in advance.
It doesn't work with llvm-gcc; you'll need to use the "LLVM Compiler 3.0" (aka clang). (I assume by the 'llvm-gcc' tag that you're not currently using it.)
I did this just last week, so it's definitely working.

Do I have to do something to get OCunit tests to compile out of box with XCode 4?

I just installed XCode 4 today (using Apple mac app store), and I created a new Mac OS application, and tried to switch to test mode,and build the test skeleton code it generated for me. It failed here:
In mytests.h:
#import <SenTestingKit/SenTestingKit.h>
The error is:
file://..mytests.h: error: Lexical or Preprocessor Issue: 'SenTestingKit/SenTestingKit.h' file not found
Now, when I use locate from the terminal to find SenTestingKit.h, I notice it exists under the /Developer-old/Library/Frameworks folder (which is what XCode 4 installer renamed my /Developer folder to). There is no new /Developer/Library/Frameworks. And I can't seem to find SenTestingKit.framework on my disk, other than the developer-old one.
What's up? It seems SenTestingKit.framework is not shipped with XCode 4.
Update:
Furthermore, When I copy my old SenTestingKit framework from XCode 3 into /Developer/Library/Frameworks, it sort of builds, but it doesn't work the way I would expect. The dummy test is designed to just fail, but when I "run test", I just get the normal cocoa app document window opening, and no indication that my test has failed (as I intend it to do).
This is pretty bad. I can't get a Unit test to FAIL. That's not the usual situation for me, you understand.
You may find that the reason for this is because you've installed Xcode 4 into a directory such as /Xcode 4.x/ or similar. The space is causing the problem because the -I paths are "Xcode" and "4.x/Library/Frameworks".
To fix this, what you need to do is select your test target, and under its build settings go and find the Framework Search Path, and put quotes around the two arguments, so you have:
"$(SDKROOT)/Developer/Library/Frameworks" and "$(DEVELOPER_LIBRARY_DIR)/Frameworks"
Then you default tests will compile, link and fail.
You will maybe need to import the framework into your project. Otherwise, the header file won't be recognize.
If you can't see the framework you're looking for, you can adjust the framework look paths in your project's build settings.
When you're building unit tests in the same project as you main code, make sure that XCode 4 didn't automatically connect you mytests.m file into the "Compile Sources" section of your main code.
For example, if you have two targets in our project:
MyProject
MyProjectTests
Check the Build Phases for MyProject to see if XCode added mytests.m into the "Compile Sources" accordion. This will cause your builds to fail because SenTest isn't included in the main project.

Why doesn't gcov report any lines being covered by my unit tests?

I am using Xcode 3.2 on 10.6, with the shipped version of gcov and default GCC compiler (both version 4.2.1). I have created a dependent Cocoa unit test bundle which is injected into my app, and followed Apple's documentation on setting up a gcov-instrumented build configuration - based on the Debug configuration which doesn't have any compiler optimisations enabled.
When I build the test bundle with this 'Gcov-instrumented' configuration, the app launches and the tests are injected and run. Also the coverage statistics files are generated at:
build/<AppTarget>.build/Gcov-instrumented/<AppTarget>.build/Objects-normal/x86_64/<object>.gcda
build/<AppTarget>.build/Gcov-instrumented/<AppTarget>.build/Objects-normal/x86_64/<object>.gcno
So far so good. I know the tests are really being run because if I insert failures then the test suite fails as expected. Unfortunately, gcov reports that no lines of the objects have been covered by the tests! Every line is reported as 0 coverage. I've searched here and at the Apple mailing list archives, and can't find anyone with a similar problem. I expect I'm missing something - but what is it?
I have been running into this problem intermittently. I stumbled into a good length of lucky time where it was "mostly working" in my main project. By mostly working I mean I was able to get coverage to show up, but with a little more pain than on 10.5. I had to aggressively delete the coverage files and rebuild in order to get any updates, for instance. Even in my "barely working" state, the compiler/runtime doesn't seem willing to overwrite an existing coverage data file.
I think I've stumbled back on to a working scenario. Voodoo for sure, and less than ideal:
Make sure the SDK is 10.6.
Make sure the deployment is set to gcc 4.0 (!).
Do a full clean of the project.
Rebuild.
Does this get you the expected coverage data?
Granted, I would expect to be able to generate coverage files that work using gcc 4.2 or one of the LLVM compilers, but for the moment this seems to have me slightly less crippled than before.
Another clue: when I observe the coverage data (using Google's Cover Story), I get warnings like:
/BUILDRESULTS/MarsEdit.build/Code Coverage/MarsEditDataModelTests.build/Objects-normal/i386/MEDataItem.gcno:version '400A', prefer '402*'
But the coverage information is still presented. So it seems it's balking at an older coverage format version, but if I use the newer compiler (4.2) which would presumably generate the newer format .gcno files, the 0% coverage problem plagues me as it does Graham.
In Xcode 4.6, coverage reports just seem to work. Turn on "Generate Test Coverage Files" and "Instrument Program Flow" for the app target, run the tests, then point the coverage tool at the output. That's in ~/Library/Developer/Xcode/Derived Data/<Project>-<hash>/Build/Intermediates/<Target>.build/Debug-iphonesimulator/<Target>.build; opening that folder in CoverStory shows me the results I expected.
This GitHub repository contains scripts that can automatically discover the output and get lcov to visualise it; I'm happy with CoverStory for now.
You can get code coverage working with gcc 4.2.1. Details here:
SnowLeopardGCov
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.
Configuration
Xcode 3.2.5/iOS 4.1 and 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” to “Other Linker Flags”
UIApplicationExitsOnSuspend flag in Info.plist is set to true
Result
I have the .gcda files generated but the coverage always show 0%.
Settings tried
Changing GCC to 4.0 and 4.2. When I try to change the GCC to 4.0 I get 26 build errors.
Set environment variables:
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.)
GCC Optimization set to None (-O0) and unchecked the precompiled prefix header file flag.
I was getting 0 coverage when *.gcno files for static library was overwritten by those for shared library.

Resources