Andes Workshop

It is currently Thu Mar 28, 2024 9:17 pm

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: code coverage tool使用教學
PostPosted: Thu Jan 19, 2012 4:47 pm 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
我們使用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
linker.gif [ 23.86 KiB | Viewed 9898 times ]

我在此用的toolchain nds32le-elf-newlib-v2

並且在compiler setting裡加上option -fprofile-arcs -ftest-coverage,如下圖
Attachment:
p1.gif
p1.gif [ 14.69 KiB | Viewed 9882 times ]


以上步驟完成後,build project得到.adx及tmp.gcno檔。

(2)使用vep2conf,將vep轉成conf,並且要加上-s elf的參數。
複製E:\Andestech\AndeSight200MCU\vep\tmpl\*.vep 到sid/ins裡
(如下圖)
Attachment:
a3.gif
a3.gif [ 18.62 KiB | Viewed 9896 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
a4.gif [ 3.07 KiB | Viewed 9896 times ]

以上步驟完成後,得到n903.vep.conf檔案

(3)用sid開啟conf檔案,以啟動vep target
hylai@APC002 /cygdrive/e/Andestech/AndeSight200MCU/sid
$ ./sid n903.vep.conf
Attachment:
a5.gif
a5.gif [ 3.64 KiB | Viewed 9896 times ]

然後用gdb連上執行
Attachment:
a6.gif
a6.gif [ 15.13 KiB | Viewed 9896 times ]

執行完成,得到tmp.gcda檔案。

(4)與tmp.gcda 同一個目錄下,放回tmp.c檔案。
執行以下command
$ nds32le-elf-gcov.exe tmp.c
Attachment:
a7.gif
a7.gif [ 2.68 KiB | Viewed 9896 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 860 times


Last edited by cindy on Fri Jan 20, 2012 4:20 pm, edited 4 times in total.

Top
 Profile Send private message E-mail  
 
 Post subject: Re: code coverage tool使用教學
PostPosted: Thu Jan 19, 2012 6:42 pm 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
這裡看到一篇文章也滿不錯的,可以參考。
http://blog.chinaunix.net/space.php?uid ... id=1810652

Gcov只能用在-O0沒有optimization情況下。


Top
 Profile Send private message E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group