I am working on a project which uses a couple of boost libraries. When looking at our test reports, we have seen that test coverage information sometimes does fit to our source code. I was able to track it down to boost::range. I think it is because of some static initialization inside the library, although I cannot say anything more specific.
Basically, if you compile the following code with gcc --coverage
, run it and print the coverage report with gcov -b
, there will be four additional branches and an additional line, which I would like to ignore.
#include <boost/range.hpp>
int foo(int x)
{
return x+1;
}
int main(int argc, char* argv[])
{
return foo(argc);
}
The coverage report is: Lines executed:100.00% of 5 Branches executed:100.00% of 4 Taken at least once:50.00% of 4 Calls executed:100.00% of 2 Creating 'test_gcov.cpp.gcov'
I guess that the count of 5 lines comes from the two function signatures, the function bodies and one additional line in the boost::range library. I don't know where exactly, but the generated gcov-file shows that some static initialization is going on, so I guess that is where the branches are located.
I would like to know if there is a way to tell gcov to ignore any code in the boost namespace, or any other means.
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.
LCOV_EXCL_START. Marks the beginning of an excluded section. The current line is part of this section. LCOV_EXCL_STOP. Marks the end of an excluded section.
You can use the --remove
or -r
flag to ignore files from external libraries. For example:
lcov -c -d <build_dir> -o <output_trace_file>
lcov -r <output_trace_file> "/usr*" -o <output_trace_file>
You can replace "/usr*"
with whatever pattern you're trying to remove.
The blog post here gives a good example of how to use that flag (and covers the whole lcov
process, start to finish.)
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