|
Monday, 11 July 2011 20:39 |
|
Below are some notes on how to use the 'gcov' and 'lcov' test coverage programs.
gcov
'gcov' is easy to use, however it produces lots of files even for a simple program.
- Add the following options to your compile and linker commands '-fprofile-arcs -ftest-coverage'
- g++ -O0 -g3 -Wall -c -fprofile-arcs -ftest-coverage -o main.o ./main.cpp
- g++ -fprofile-arcs -ftest-coverage -o avltree ./main.o
- After building main.cpp you will see the below file created:
- After running your recompiled executable files like below will be created:
- Now produce your coverage results
- Now view the coverage report
lcov
'lcov' is a graphical front end for 'gcov' that produces a great html summary of your test coverage.
Along with the summary a report of exercised lines of code (blue), and untested code (orange) is produced.
An example run of 'lcov' is below.
- Initialize the directory where you wish to store the 'html' result in:
- mkdir lcovdir
- cd lcovdir
- lcov --directory ../ --zerocounters
- Run the test application:
- Process the results into a single file:
- lcov --directory ../ --capture --output-file app.info
- Generate the html results and view them
- genhtml -o . app.info
- firefox ./index.html
|