atf-c for kernel function unit testing

Julio Merino jmmv at
Mon Mar 3 17:33:02 UTC 2014

On Mon, Mar 3, 2014 at 11:52 AM, R. Tyler Croy <tyler at> wrote:
> I'm wondering if anybody's explored using atf-c for adding unit tests to kernel
> level functions or driver code.

We do this extensively in NetBSD: we have a mechanism (rump) to build
unmodified kernel-level code as user-space binaries and we later use
atf to unit-test the code in controlled tiny environments. (You'd
think about this as super-lightweight virtualization of the kernel.)

Achieving this for any non-trivial kernel-level code is hard however,
but I believe that this approach has huge benefits. For example: we
are able to unit-test all file system and networking code in
user-space without any chances of crashing the system; there is also
the benefit of being able to control the test environment fully
without relying on any state of the running kernel.

For more details see:

If the code you are interested in testing can easily be built without
ties to the kernel, you can relatively easily do the above. (In fact,
we used to do this in NetBSD for some tiny areas of the code before we
got rump.)

At some point I also pondered the idea to write an interface and a
kernel module to allow writing unit tests within the kernel. This
might be interesting for some special cases (like testing live
hardware maybe) but it's a very fragile setup that should not be
pursued if other safer solutions suffice.

More information about the freebsd-testing mailing list