Valery V. Vorotyntsev ([info]vorotylo) wrote,
@ 2009-07-10 15:31:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Entry tags:english, otd, programming, tips, tools

utility of the day

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 <stdio.h>
        -:    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:




(4 comments) - (Post a new comment)


[info]alexott
2009-07-10 01:28 pm UTC (link)
у нас оно привязано к dashboard'у от kitware (cmake/ctest) - очень красиво получается, графики и пофайловая статистика

(Reply to this) (Thread)


[info]vorotylo
2009-07-10 01:36 pm UTC (link)
Здорово! А скриншот можешь показать? Не нарушая NDA...

(Reply to this) (Parent)(Thread)


[info]alexott
2009-07-10 01:41 pm UTC (link)
не, показать не могу, но посмотри на http://www.cdash.org - там хватает примеров реальных проектов

(Reply to this) (Parent)


[info]some41
2009-07-10 05:37 pm UTC (link)
боян

(Reply to this)


(4 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…