Code coverage - ligurio/openbsd-tests GitHub Wiki
Reasons to measure code coverage
Optimization
GCOV identifies the sections in the code that are heavy executed, using which we’ll be able to focus on optimizing the parts of the code which are executed often.
Identifying dead code
Any code that got compiled but never got executed on any possible scenario can be found using GCOV. Removing such code can help in reducing the memory footprint of the program. This can be vital information for programs running on embedded platforms.
Reliability of testing
The coverage report can help in identifying the gaps in testing. The coverage information can be used for writing test cases to exercise the uncovered area in the code.
Feedback-driven fuzzing
Criteria of testing completion
How-To
Results
- OpenBSD code coverage results - https://ligurio.github.io/openbsd-tests/
- LibreSSL
- OpenSSH
References
- https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
- https://alastairs-place.net/blog/2016/05/20/code-coverage-from-the-command-line-with-clang/
- http://releases.llvm.org/5.0.0/docs/CommandGuide/llvm-cov.html
- https://llvm.org/docs/CoverageMappingFormat.html
- Do not open .gcda/.gcno files in write mode unnecessarily.
- https://gcc.gnu.org/onlinedocs/gcc/Gcov-Data-Files.html
- http://www.chennainerd.in/blog/2014/06/08/gcov-c-slash-c-plus-plus-code-coverage-testing-tool/
- Add -fprofile-dir= to clang (since LLVM 6.0)
- https://twitter.com/vegard_no/status/842125693727170570 (OpenBSD code is not friendly for testing)
A more interesting analysis would be to run a series of kernel tests prior to generating the code coverage report.
To get a more accurate report, it would also be best to zero out the counters before running the tests: sudo lcov --zerocounters
. Then run the series of kernel tests.