Question

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.

Was it helpful?

Solution

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"
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top