KUnit is a unit testing framework decided for the Linux kernel. On April 4, 2019 the first series (after 4 RFC series were submitted) was published to the Linux kernel mailing list.

The framework is documented in Documentation/kunit. It includes a framwork written in C and a Python wrapper that reads a defconfig file named kunitconfig. The wrapper somehow parses that file to build a .config, which is used to build a user-mode kernel, which is then run as ./linux. The wrapper parses the relevant output and prints the results.

Unfortunately, I ran into several issues related to the wrapper. The first was that it did not handle the exit status of ./linux. When running the wrapper with --raw_output or simply running ./linux several stack traces were printed including a kernel panic. Also, I could not get it to select the dependencies defined in the Kconfig file I created for my tests. It failed while trying to write a config, update it based on the current kernel and then validate that process.

Testing out-of-tree kernel modules

The only somewhat reasonable solution I could come up with to use kunit to test out-of-tree kernel modules was to setup the kernel module project with the same hierarchy as the kernel and use overlayfs to build it in-tree (see The Overlay Filesystem).

References