2010-06-16 60 views
1
gcov的環境變量

我已經克服了所有的問題,在我的iPhone項目設置gcov,但現在我得到如下:如何設置適用於iPhone

profiling:/Users:Cannot create directory 

有沒有人有任何建議,我可能做錯了嗎?

我原先設置的gcov以下谷歌的指令可以通過谷歌搜索「UsingCoverStory」

更新中找到: 好了,讓我澄清什麼,我試圖做的。我有一個iPhone應用程序,我試圖自動測試。我正在使用UISpec框架來驅動GUI。我真正需要知道的是我的測試實際覆蓋了多少代碼。我認爲我非常接近,但我只需要了解如何正確設置環境/編譯器變量以適合我的項目。

這裏是我迄今爲止所做的一個總結。我首先複製了我的構建目標,指定了鏈接器標誌和一些其他選項。 (這可以使用由Google創建的AppleScript自動完成,說明和下載可以通過谷歌搜索「UsingCoverStory」找到)無論如何,我已經驗證了這些設置正確分配。我將我的配置設置爲Debug,並在3.1.3設備上運行。當我運行應用程序時,直到退出應用程序時纔在調試器中顯示任何特別的東西。在這一點上,我得到一個錯誤:

profiling:/Users:Cannot create directory 
profiling:/Users/forbushbl/Documents/TestApp/build/TestApp.build/Debug-iphoneos/TestApp copy.build/Objects-normal/armv6/ApplicationController.gcda:Skip 

我認爲GCOV試圖寫出來的.gcda文件,但我不太知道如何告訴它,他們應該被寫入。我在某處讀到GCOV試圖重現目錄結構,其中.gcno文件存儲在我的項目文件夾中,因爲上面的目錄是我的機器上的.gcno文件所在的位置,所以這很有意義。然而,這是一個問題,因爲iPhone上不存在該結構,設備也不能創建該結構。

我發現另一個人有同樣的問題,他們說他們必須設置一個環境變量。 How to set up gcov for code coverage analysis in iPhone SDK?

GCOV文檔說以下內容:

For example, if the object file /user/build/foo.o was built with -fprofile-arcs , the final executable will try to create the data file /user/build/foo.gcda when running on the target system. This will fail if the corresponding directory does not exist and it is unable to create it. This can be overcome by, for example, setting the environment as `GCOV_PREFIX=/target/run' and `GCOV_PREFIX_STRIP=1'. Such a setting will name the data file /target/run/build/foo.gcda .

我的問題是,我該如何設置iPhone上的這些環境變量?我應該在構建配置中還是在實際代碼中執行此操作?

+0

更多細節上的環境變量以及如何在通用(而不是iPhone)上下文中使用它們:[數據文件重定位以支持跨分析](http://gcc.gnu.org/onlinedocs/gcc/Cross_002dprofiling.html#Cross_002dprofiling) – 2011-07-15 15:58:23

回答

0

您應該可以在可執行文件設置中設置這些環境變量。打開項目的「可執行文件」分支(在樹/公開視圖中),然後雙擊可執行文件。在參數窗格下,您可以設置環境變量。

0

你應該在你的項目的main.m文件使用SETENV設置這些變量:

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. 

注意:確保上面的代碼之前:

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
int retVal = UIApplicationMain(argc, argv, nil, nil); 
[pool release];  
return retVal;