tags:

views:

83

answers:

3

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.

A: 

Bugur, Did you got to know how to filter specific functions? Even I am facing the same problem

sarath
Nope, couldn't find a way. It seems like moving those functions to a separate file and doing the filtering in lcov might help.
bugur
A: 

Bugur, If you are using LCOV for post processing gcov files, then there is a way to filter out specific lines of code.

sarath
+2  A: 

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"
}
Fabian