Conceptual
Login

Testing a Kernel Driver with Unit Tests and the Lints

Parts of a driver are pure reasoning — decoding a register value, rejecting an input too large to compute — and those parts can be tested without any hardware, by unit tests that run inside the kernel at boot. The rest is guarded by tools: a linter that flags suspicious patterns, a formatter that settles layout arguments before anyone has them, and examples inside your documentation that are compiled and run so they cannot go stale. After this stage your driver has a way to prove it still works after you change it, which is the thing that makes a project outlive your memory of writing it.

Questions this Concept answers

  • Why are the examples inside a driver's documentation compiled and executed rather than merely displayed?