2012-01-04 66 views
14

我跟随Claus's post在Xcode 4.2上用LLVM 3.0设置代码覆盖率。我能够看到测试覆盖率文件,但它们仅用于我的单元测试类,而不是我的实际项目类。我试过设置生成测试覆盖文件仪器程序流程是我的主要目标,但这并没有帮助,因为它与下面的错误失败:Xcode 4.2的代码覆盖率 - 丢失的文件

的fopen $ UNIX2003从所谓函数llvm_gcda_start_file

为了澄清,我不认为这是正确的方法 - 我只是试图看看它是否会生成我的项目类的代码覆盖率。

在这一点上,我很乐意尝试任何能够在我的应用上使用代码覆盖的东西。有什么建议么?

回答

24

你期待连接问题,profile_rt库使用fopen$UNIX2003fwrite$UNIX2003功能,而不是fopenfwrite

所有你需要的是以下.c文件添加到您的项目:

#include <stdio.h> 

FILE *fopen$UNIX2003(const char *filename, const char *mode) 
{ 
    return fopen(filename, mode); 
} 

size_t fwrite$UNIX2003(const void *a, size_t b, size_t c, FILE *d) 
{ 
    return fwrite(a, b, c, d); 
} 

此代码只是重新映射缺少的功能,以标准的。在$UNIX2003后缀

注:

我发现一个Apple document说:

The UNIX™ conformance variants use the $UNIX2003 suffix.

Important: The work for UNIX™ conformance started in Mac OS 10.4, but was not completed until 10.5. Thus, in the 10.4 versions of libSystem.dylib, many of the conforming variant symbols (with the $UNIX2003 suffix) exist. The list is not complete, and the conforming behavior of the variant symbols may not be complete, so they should be avoided.

Because the 64-bit environment has no legacy to maintain, it was created to be UNIX™ conforming from the start, without the use of the $UNIX2003 suffix. So, for example, _fputs$UNIX2003 in 32-bit and _fputs in 64-bit will have the same conforming behavior.

因此,我希望libprofile_rt对抗10.4 SDK链接。

+1

将此.c文件添加到我在XCode 4.3.2中的项目中,并打开我的主目标(仅限调试)的覆盖范围和检测工作!这是我第一次在iOS开发中使用全功能的代码覆盖。我甚至使用gcovr和Coburtura插件将它与Jenkins集成在一起。 – 2012-05-15 16:54:18

+0

99%的时间对我有用,但我仍然随机发生崩溃。有什么想法吗?我们的测试框架将重新启动应用程序100多次。在过夜运行,它总是发生,但非常间歇性 – 2012-05-31 21:20:43

+0

@BrianKing你应该提交一个单独的问题与您的崩溃细节。 – iHunter 2012-06-02 08:09:11