utility of the day

Jul 10, 2009 15:31


gcov - coverage testing tool

-: 0:Source:/tmp/1.c -: 0:Graph:1.gcno -: 0:Data:1.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include -: 2: -: 3:void foo() 1: 4:{ 1: 5: printf("int:\t%ld\n", (long) sizeof(int)); 1: 6: printf("long:\t%ld\n", (long) sizeof(long)); 1: 7:} -: 8: -: 9:void bar() #####: 10:{ #####: 11: printf("size_t:\t%ld\n", (long) sizeof(size_t)); #####: 12: printf("void*:\t%ld\n", (long) sizeof(void*)); #####: 13:} -: 14: -: 15:int main() 1: 16:{ 1: 17: foo(); -: 18:/* bar(); */ 1: 19: return 0; -: 20:}
The lines marked with `#####' were never executed.
Compile with `--coverage' and run yer program:
$ vi /tmp/1.c $ cd /tmp $ gcc --coverage -g -Wall -W -o 1 1.c $ ./1 >/dev/null $ gcov /tmp/1.c File '/tmp/1.c' Lines executed:63.64% of 11 /tmp/1.c:creating '1.c.gcov'
GCC only.
Update: gcov with `-b' option measures branch coverage.
See also:

tips, otd, programming, english, tools

Previous post Next post
Up