我們使用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:
linker.gif [ 23.86 KiB | Viewed 10302 times ]
我在此用的toolchain nds32le-elf-newlib-v2
並且在compiler setting裡加上option
-fprofile-arcs -ftest-coverage,如下圖
Attachment:
p1.gif [ 14.69 KiB | Viewed 10286 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 10300 times ]
hylai@APC002 /cygdrive/e/Andestech/AndeSight200MCU/sid/ins
$
./vep2conf ADP-XC5-for-N903-S-32GPR.vep -s elf -o n903.vep.confAttachment:
a4.gif [ 3.07 KiB | Viewed 10300 times ]
以上步驟完成後,得到n903.vep.conf檔案
(3)用sid開啟conf檔案,以啟動vep target
hylai@APC002 /cygdrive/e/Andestech/AndeSight200MCU/sid
$
./sid n903.vep.confAttachment:
a5.gif [ 3.64 KiB | Viewed 10300 times ]
然後用gdb連上執行
Attachment:
a6.gif [ 15.13 KiB | Viewed 10300 times ]
執行完成,得到tmp.gcda檔案。
(4)與tmp.gcda 同一個目錄下,放回tmp.c檔案。
執行以下command
$ nds32le-elf-gcov.exe tmp.c
Attachment:
a7.gif [ 2.68 KiB | Viewed 10300 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:
cv_example.zip [70.75 KiB]
Downloaded 880 times