Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to measure function coverage with gcov?

Currently we use gcov with our testing suite for Linux C++ application and it does a good job at measuring line coverage.

Can gcov produce function/method coverage report in addition to line coverage?

Looking at the parameters gcov accepts I do not think it is possible, but I may be missing something. Or, probably, is there any other tool that can produce function/method coverage report out of statistics generated by gcc?

Update: By function/method coverage I mean percentage of functions that get executed during tests.

like image 433
Dima Malenko Avatar asked Feb 10 '09 21:02

Dima Malenko


People also ask

What is the output of gcov?

gcov produces files called mangledname . gcov in the current directory. These contain the coverage information of the source file they correspond to. One .

What is the best updated code coverage tool?

#1) Parasoft JTest Its report provides a good picture of code covered and thereby minimizes risks. Key Features: It is used for Java-based applications. It is a multi-tasking tool which includes Data flow analysis, Unit testing, Static analysis, runtime error detection, code coverage testing etc.

What is gcov and LCOV?

LCOV is a graphical tool for GCC's coverage testing with gcov. It creates HTML pages containing the source code annotated with coverage information by collecting gcov data from multiple source files.


1 Answers

I guess what you mean is the -f option, which will give you the percentage of lines covered per function. There is an interesting article about gcov at Dr. Dobb's which might be helpful. If "man gcov" doesn't show the -f flag, check if you have a reasobably recent version of the gcc suite.

Edit: to get the percentage of functions not executed you can simply parse through the function coverage output, as 0.00% coverage should be pretty much equivalent to not called. This small script prints the percentage of functions not executed:

#!/bin/bash

if test -z "$1"
then
    echo "First argument must be function coverage file"
else
    notExecuted=`cat $1 | grep "^0.00%" | wc -l`
    executed=`cat $1 | grep -v "^0.00%" | wc -l`

    percentage=$(echo "scale=2; $notExecuted / ($notExecuted + $executed) * 100" |bc)

    echo $percentage
fi
like image 70
VolkA Avatar answered Nov 11 '22 18:11

VolkA