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.
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.
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"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With