Conceptual
Login

Writing Unit Tests Inside the Kernel with KUnit

KUnit runs small tests inside a running kernel, so code that can only work in kernel space can still be tested piece by piece. In Rust you mark a block of tests with an attribute and they are compiled into the kernel only when testing is switched on. That lets you check the logic in your driver, such as how it builds a register value, without any hardware at all. Without it, your only test is loading the whole driver and hoping.

Questions this Concept answers

  • Why can a kernel driver's logic not be tested with an ordinary user-space test run?