CodeVetter · Repo Unpack · Testing signals
torvalds/linux
Testing is built into the tree: KUnit (lib/kunit/) is the in-kernel unit-test framework, run at boot via kunit_run_all_tests() or via the tools/testing/kunit/kunit.py harness under UML/QEMU. kselftest (tools/testing/selftests/, ~135 target dirs) provides userspace-driven syscall/feature tests emitting KTAP. Numerous ad-hoc selftest .c files live next to core code (initramfs_test.c, kallsyms_selftest.c, sysctl-test.c, dmapool_test.c, gup_test.c). There is no in-tree CI config — validation is maintainer/review driven, with checkpatch.pl/get_maintainer.pl as local gates; external systems (syzbot, kernelci, 0-day) do continuous testing.
- KUnit is the kernel unit-test framework: lib/kunit/ contains test.c, executor.c, try-catch.c, string-stream.c, debugfs.c and assertion helpers, with public headers in include/kunit/test.h.
- KUnit tests execute during boot inside kernel_init_freeable via kunit_run_all_tests(), after do_basic_setup() and before prepare_namespace(), so late-init tests run with the full kernel initialized.
- tools/testing/kunit/ provides the Python runner: kunit.py orchestrates builds (kunit_config.py) and runs kernels under QEMU (qemu_config.py, qemu_configs/), parsing KTAP output via kunit_parser.py.
- Per-subsystem .kunitconfig fragments select test builds: init/.kunitconfig sets CONFIG_KUNIT=y + CONFIG_INITRAMFS_TEST=y; rust/.kunitconfig sets CONFIG_KUNIT + CONFIG_RUST + CONFIG_RUST_KERNEL_DOCTESTS.
- kselftest lives in tools/testing/selftests/: the top Makefile aggregates ~135 TARGETS (acct, bpf, cgroup, clone3, exec, futex, memblock-adjacent dirs, net, ...), and runner.sh/run_kselftest.sh plus ksft.py/ktap_helpers.sh provide the KTAP-emitting harness.
- Ad-hoc selftests sit beside production code: init/initramfs_test.c (CONFIG_INITRAMFS_TEST), kernel/kallsyms_selftest.c, kernel/sysctl-test.c, kernel/crash_core_test.c, kernel/resource_kunit.c, mm/dmapool_test.c and mm/gup_test.c.
- tools/testing/ also hosts standalone harnesses for library code — memblock, radix-tree, rbtree, scatterlist, vma, vsock — that compile kernel sources directly in userspace for fast unit testing.
- Rust has its own test plumbing: rust/kernel/kunit.rs plus the #[kunit] proc-macro support in rust/macros/kunit.rs, an example test in lib/kunit/kunit-example-test.c style, and CONFIG_RUST_KERNEL_DOCTESTS for doc tests.
- There is no .github/, .gitlab-ci.yml or similar CI config in the tree; contribution gating is the email review flow documented in Documentation/process/submitting-patches.rst with scripts/checkpatch.pl as the pre-submit style checker.
- Coverage is uneven by construction: selftests concentrate in tools/testing/selftests and a minority of core files carry paired test modules (e.g. kernel/sysctl-test.c for kernel/sysctl.c), so most of mm/, net/ and drivers/ has no in-tree unit coverage and relies on external fuzzing/CI. (inferred)