Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding certain functions from gcov/lcov coverage results

Tags:

c++

lcov

gcov

Is it possible to exclude certain functions or lines of code from the gcov coverage analysis. My code contains certain functions that are used for debugging, and are not exercised as part of my test suite. Such functions reduce the coverage percentage reported by gcov. I would like to exclude these functions from the results. If it is not possible via gcov, perhaps it is possible via lcov, but I was not able to figure it out. Your help is appreciated.

like image 311
Buğra Gedik Avatar asked Jul 02 '10 05:07

Buğra Gedik


People also ask

What is difference between GCOV and LCOV?

Lcov is a graphical front-end for gcov. It collects gcov data for multiple source files and creates HTML pages containing the source code annotated with coverage information. It also adds overview pages for easy navigation within the file structure. Lcov supports statement, function, and branch coverage measurement.


1 Answers

I filter out certain source files by running the output of lcov --capture through a simple awk script. The output of lcov --capture has a very simple format and the awk script below filters out source files matching file_pattern. I think it is possible to adapt the script to make it filter functions instead of file names.

BEGIN {
        record=""
}

/^SF/ {
        if ( match ($0, "file_pattern" ) ) {
            doprint = 0
        } else {
            doprint = 1
        }
}

/^end_of_record$/ {
        if ( doprint ) {
            print record $0
        }
        record = ""
        next
}

{
    record=record $0 "\n"
}
like image 132
Fabian Avatar answered Nov 09 '22 07:11

Fabian