2012-01-04 65 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