How to write your first kernel selftest
summary
Kernel selftests are small userspace programs (mostly C, some shell) placed under tools/testing/selftests that exercise the running kernel; they build locally with make install and run through the generated harness run_kselftest which emits TAP output for CI. Examples show meaningful checks in a few dozen lines (getpid+readlink or the 5.8 proc multiple-mount regression). Tests can crash a machine so use a VM, and they simplify merging and backporting fixes alongside code.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 1:12What are kernel selftests
- 3:03Where are they kept
- 4:09Why kernel selftests
- 4:58Benefits
- 6:40Build
- 8:10Run
- 9:32Run all tests
- 10:43Simple selftest
- 12:37Another small test
- 15:37What needs testing
- 17:37Summary
related talks
20m"How to write your first kernel selftest"
30mKernel Testing with KUnit: Bridging the Gap
23mExperiences and lessons we learned using kselftest and pote
44mKUnit - Unit Testing for the Linux Kernel
36mLinux Kernel Developer Panel
43mGetting to Know the Linux Kernel: A Beginner's Guide
46mLinux Kernel Functional Testing, or How to Build and Test Millions of Linux Kernels
19mUpstream kernel CI using patchew and TDC
