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?
Unit Testing the Linux Kernel with KUnit
Unit testing is a category of software testing that isolates and verifies a single logical unit of code independent of hardware or other non-deterministic dependencies, contrasted with integration te…