Getting KUnit
If you’re working on Linux 5.5+, you have KUnit.
Otherwise, you’ll want to backport the patches, which should all begin with "kunit: "
.
An option of last resort is to use the deprecated and incompatible
kunit/alpha/master
branch.
See Deprecated below for more details.
Where are these versions?
Upstream
KUnit can be found in Linux 5.5 and newer.
Code: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
Usage - for a more detailed explanation of KUnit features
API - for the list of KUnit APIs used for testing
The KUnit code itself is primarily found in the lib/kunit directory.
Deprecated
This is where KUnit development was done prior to getting upstreamed, but all development on it has since ceased.
It has a couple of features that haven’t made their way in the upstream version of KUnit yet, namely:
Class mocking
Function mocking
Hardware/platform faking
Error recovery
Note
Tests written against the kunit/alpha/master
branch will not be
directly compatible with the upstream version, however. You can set
CONFIG_KUNIT_USE_UPSTREAM_NAMES=y
to make it act a bit more like the
upstream version, see this patch series for details.
The old, deprecated branch is stored in a Google-hosted gerrit instance.
Code: https://kunit.googlesource.com/linux/+/kunit/alpha/master.
Usage - for a more detailed explanation of KUnit features
API - for the list of KUnit APIs used for testing
kunitconfig file: https://kunit.googlesource.com/kunitconfig/+/refs/heads/kunit/alpha/master/kunitconfig