For my header-only C++ library (lots of templates etc) I use GCov to check test coverage. However, it reports 100% coverage for all headers because the unused functions aren't generated by the compiler in the first place. Manually spotting uncovered functions is easy but defeats the purpose of continuous integration…
How does one solve this automatically? Should I just use "lines hit / LOC" as my coverage metric and just never reach 100% again?
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.
gcov is a test coverage program. Use it in concert with GCC to analyze your programs to help create more efficient, faster running code and to discover untested parts of your program. You can use gcov as a profiling tool to help discover where your optimization efforts will best affect your code.
Apart from the usual flags to GCC controlling inlining;
--coverage -fno-inline -fno-inline-small-functions -fno-default-inline
You can instantiate your template classes at the top of your unit test files;
template class std::map<std::string, std::string>;
This will generate code for every method in that template class making the coverage tools work perfectly.
Also, make sure that you initialise your *.gcno files (so for lcov)
lcov -c -i -b ${ROOT} -d . -o Coverage.baseline <run your tests here> lcov -c -d . -b ${ROOT} -o Coverage.out lcov -a Coverage.baseline -a Coverage.out -o Coverage.combined genhtml Coverage.combined -o HTML
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