An introduction to kernel code coverage tools and testing frameworks
Code coverage is tooling that can identify which lines of code get executed during a run and which lines of code don't. Tools such as GNU coverage (gcov), and kcov and frontend tools such as lcov can be very valuable in gleaning this key information.
Why is code coverage important?
Here are a few typical reasons why you should (I'd go so far as to say must) perform code coverage:
- Debugging: To help identify code paths that are never executed (error paths are pretty typical), thereby making it clear that you need test cases for them (to then catch bugs that lurk in such regions).
- Testing/QA: Identify test cases that work and, more to the point, ones that need to be written in order to cover lines of code that never get executed, as, after all, 100% code coverage is the objective!
- They can help with (minimal) kernel configuration. Seeing that certain code paths are never taken perhaps...