Andes Workshop http://forum.andestech.com/ |
|
code coverage tool使用教學 http://forum.andestech.com/viewtopic.php?f=23&t=523 |
Page 1 of 1 |
Author: | cindy [ Thu Jan 19, 2012 4:47 pm ] |
Post subject: | code coverage tool使用教學 |
我們使用gcov這個code coverage tool, 參考網頁: http://gcc.gnu.org/onlinedocs/gcc/Invok ... oking-Gcov 以下是Andes環境裡的使用方法。 (1)製作執行檔 example原始碼 Code: #include <stdio.h> int main (void) { int i, total; total = 0; for (i = 0; i < 10; i++) total += i; if (total != 45) printf ("Failure\n"); else printf ("Success\n"); return 0; } 用newlib編譯的程式,請務必勾選下面這3項 Attachment: 我在此用的toolchain nds32le-elf-newlib-v2 並且在compiler setting裡加上option -fprofile-arcs -ftest-coverage,如下圖 Attachment: p1.gif [ 14.69 KiB | Viewed 10204 times ] 以上步驟完成後,build project得到.adx及tmp.gcno檔。 (2)使用vep2conf,將vep轉成conf,並且要加上-s elf的參數。 複製E:\Andestech\AndeSight200MCU\vep\tmpl\*.vep 到sid/ins裡 (如下圖) Attachment: a3.gif [ 18.62 KiB | Viewed 10218 times ] hylai@APC002 /cygdrive/e/Andestech/AndeSight200MCU/sid/ins $ ./vep2conf ADP-XC5-for-N903-S-32GPR.vep -s elf -o n903.vep.conf Attachment: a4.gif [ 3.07 KiB | Viewed 10218 times ] 以上步驟完成後,得到n903.vep.conf檔案 (3)用sid開啟conf檔案,以啟動vep target hylai@APC002 /cygdrive/e/Andestech/AndeSight200MCU/sid $ ./sid n903.vep.conf Attachment: a5.gif [ 3.64 KiB | Viewed 10218 times ] 然後用gdb連上執行 Attachment: a6.gif [ 15.13 KiB | Viewed 10218 times ] 執行完成,得到tmp.gcda檔案。 (4)與tmp.gcda 同一個目錄下,放回tmp.c檔案。 執行以下command $ nds32le-elf-gcov.exe tmp.c Attachment: a7.gif [ 2.68 KiB | Viewed 10218 times ] 得到tmp.c.gcov檔案和結果。 (5)最後,打開tmp.c.gcov有逐行的結果。 Code: -: 0:Source:../tmp.c -: 0:Graph:tmp.gcno -: 0:Data:tmp.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include <stdio.h> -: 2: 1: 3:int main (void) -: 4:{ -: 5: int i, total; 1: 6: total = 0; -: 7: 11: 8: for (i = 0; i < 10; i++) 10: 9: total += i; -: 10: 1: 11: if (total != 45) #####: 12: printf ("Failure\n"); -: 13: else 1: 14: printf ("Success\n"); 1: 15: return 0; -: 16:} 在此附上測試程式及測試conf檔。 Attachment:
|
Author: | cindy [ Thu Jan 19, 2012 6:42 pm ] |
Post subject: | Re: code coverage tool使用教學 |
這裡看到一篇文章也滿不錯的,可以參考。 http://blog.chinaunix.net/space.php?uid ... id=1810652 Gcov只能用在-O0沒有optimization情況下。 |
Page 1 of 1 | All times are UTC + 8 hours [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |