2009年6月4日

LCOV - the LTP GCOV extension

LCOV - the LTP GCOV extension
gcov—a Test Coverage Program

// -- $ mkdir src; vim src/hello.c --
#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;
}

// -- makefile --
all: results/index.html
firefox results/index.html

results/index.html: hello.info
genhtml -o results hello.info

hello.info: hello.c.gcov
lcov --directory . --capture --output-file hello.info

hello.c.gcov: hello.gcda
gcov ./src/hello.c
cat hello.c.gcov

hello.gcda: hello
./hello

hello: src/hello.c
gcc -fprofile-arcs -ftest-coverage -o hello ./src/hello.c

clean:
rm -f hello*
rm -rf results/

//-- make --
$ make all
gcc -fprofile-arcs -ftest-coverage -o hello ./src/hello.c
./hello
Success
gcov ./src/hello.c
File './src/hello.c'
Lines executed:87.50% of 8
./src/hello.c:creating 'hello.c.gcov'

cat hello.c.gcov
-: 0:Source:./src/hello.c
-: 0:Graph:hello.gcno
-: 0:Data:hello.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include
-: 2:
-: 3:int main (void)
1: 4:{
-: 5: int i, total;
-: 6:
1: 7: total = 0;
-: 8:
11: 9: for (i = 0; i < 10; i++)
10: 10: total += i;
-: 11:
1: 12: if (total != 45)
#####: 13: printf ("Failure\n");
-: 14: else
1: 15: printf ("Success\n");
1: 16: return 0;
-: 17:}
-: 18:
lcov --directory . --capture --output-file hello.info
Capturing coverage data from .
Found gcov version: 4.3.3
Scanning . for .gcda files ...
Found 1 data files in .
Processing ./hello.gcda
Finished .info-file creation
genhtml -o results hello.info
Reading data file hello.info
Found 1 entries.
Found common filename prefix "/home/solomon"
Writing .css and .png files.
Generating output.
Processing file c2/src/hello.c
Writing directory view page.
Overall coverage rate: 7 of 8 lines (87.5%)
firefox results/index.html

沒有留言:

網誌存檔