Introduction to the front-end tool LCOV of the Linux platform code coverage testing tool GCOV

Content

1. What is Lcov ?

2. How to install Lcov on Linux platform ?

3. How to use Lcov ?

(1) Use lcov to collect coverage data and write to file

(2) Use genhtml to generate HTML- based output

(3) Graphical display of the example

4. Compile lcov's own example

5 . Other tools

(1) gcov-dump

(2) ggcov

 

 

1. What is Lcov ?

  • It is a graphical front-end tool for GCOV
  • It is an open source tool maintained by the Linux Test Project , originally designed to support the measurement of Linux kernel coverage
  • Based on Html output, and generate a complete HTML tree
  • Output includes overview, coverage percentage, graphs, and can quickly browse coverage data
  • Support for large projects, providing three levels of views: directory view, file view, source code view

Use lcov to collect coverage data and genhtml to create HTML pages. Coverage data can either be collectedfrom the currently running Linux kernel or from a user space application. To do this, you  have  to  complete the following preparation steps:

 

For Linux kernel coverage:

  Follow  the setup instructions for the gcov-kernel infrastructure:

http://ltp.sourceforge.net/coverage/gcov.php

 

For user space application coverage:

  Compile the application with GCC using the options "-fprofile-arcs" and "-ftest-coverage".

 

2. How to install Lcov on Linux platform ?

# wget http://downloads.sourceforge.net/ltp/lcov-1.9.tar.gz

# tar -zxvf lcov-1.9.tar.gz

# cd lcov-1.9

# ls

bin      contrib  descriptions.tests  lcovrc    man     rpm

CHANGES  COPYING  example             Makefile  README

# make install

No need to compile, just install directly, lcov, gendesc, genhtml, geninfo, genpng will be installed to the /usr/bin directory.

 

3. How to use Lcov ?

 

Take the example of the article Introduction to the Linux Platform Code Coverage Test Tool GCOV .

 

(1) Use lcov to collect coverage data and write to file 

# lcov --capture --directory . --output-file test.info --test-name test

Capturing coverage data from .

Found gcov version: 4.1.2

Scanning . for .gcda files ...

Found 1 data files in .

Processing test.gcda

Finished .info-file creation

. Represents the current directory, collect coverages the Data , namely .gcda information in the file, and writes test.info file, and named the Test . Please refer to the manual page of lcov for other options .

 

The contents of the test.info file are as follows.

TN:test

SF:/home/zubo/gcc/2011-04-10.sample/test.c

FN:4,main

FNDA:1,main

FNF: 1

FNH: 1

HILLS: 9,2,0,10

HILLS: 9,2,1,1

HILLS: 12,0,0,0

HILLS: 12,0,1,1

BRF: 4

BRH: 3

DA: 4.1

DA: 7.1

DA: 9.11

DA: 10.10

DA: 12.1

DA: 13.0

DA: 15.1

DA: 16.1

LF:8

LH: 7

end_of_record

(2) Use genhtml to generate HTML- based output

# genhtml test.info --output-directory output --title "a simple test" --show-details --legend

Reading data file test.info

Found 1 entries.

Found common filename prefix "/home/zubo"

Writing .css and .png files.

Generating output.

Processing file gcc/2011-04-10.sample/test.c

Writing directory view page.

Overall coverage rate:

  lines......: 87.5% (7 of 8 lines)

  functions..: 100.0% (1 of 1 function)

  branches...: 75.0% (3 of 4 branches)

Please refer to the manual page of genhtml for option explanation . Cd to the output directory, you can see that a lot of related files are generated, as follows.

# cd output

# ls

amber.png    gcov.css    index-sort-b.html  ruby.png

emerald.png  glass.png   index-sort-f.html  snow.png

gcc          index.html  index-sort-l.html  updown.png

(3) Graphical display of the example

 

(3.1) Top level view




(3.2) View of file or function


4. Compile lcov's own example

 

# cd /usr/src/lcov-1.9/example

# make

 

Compiling, running, and viewing the results is the best way to learn a tool quickly. From the example of makefile files and the compiled output, you can learn the concepts and use commands. Html output can be viewed in /usr/src/lcov-1.9/example/output/index.html . Readers can experiment by themselves.

 

5. Other related tools

 

(1) gcov-dump

 

Perhaps, we can also use the gcov-dump command to output gcov related data, but gcc does not compile gcov-dump by default , so to use it, you may need to recompile gcc .

 

(2) ggcov

 

Ggcov is a Graphical tool for displaying gcov test coverage data . For more information, please refer to http://ggcov.sourceforge.net .

 

 

Reference

lcov 's manual page

genhtml 's manual page

geninfo 's manual page

lcov the readme file paper / usr / the src / lcov-1.9 / the README

lcov the makefile document herein is / usr / the src / lcov-1.9 / the Makefile

 

Guess you like

Origin blog.csdn.net/panpanloveruth/article/details/7622704