Appendix E: Testing
Testing strategies for kernel drivers.
Testing Layers
flowchart TB
subgraph Unit["Unit Testing"]
KUNIT["KUnit"]
end
subgraph Runtime["Runtime Checks"]
KASAN["KASAN (memory)"]
LOCKDEP["lockdep (locking)"]
UBSAN["UBSAN (undefined)"]
end
subgraph Integration["Integration"]
SELFTEST["kselftest"]
SYZKALLER["syzkaller (fuzzing)"]
end
Unit --> Runtime
Runtime --> Integration
style Unit fill:#7a8f73,stroke:#2e7d32
style Runtime fill:#738f99,stroke:#0277bd
style Integration fill:#8f8a73,stroke:#f9a825
Quick Start
| Tool |
Purpose |
Enable |
| KUnit |
Unit tests |
CONFIG_KUNIT=y |
| KASAN |
Memory bugs |
CONFIG_KASAN=y |
| lockdep |
Lock issues |
CONFIG_PROVE_LOCKING=y |
| UBSAN |
Undefined behavior |
CONFIG_UBSAN=y |
Chapters
Example
Recommended Config
# Debug options
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_KERNEL=y
# Memory debugging
CONFIG_KASAN=y
CONFIG_KASAN_INLINE=y
# Lock debugging
CONFIG_PROVE_LOCKING=y
CONFIG_DEBUG_LOCK_ALLOC=y
# Undefined behavior
CONFIG_UBSAN=y
# Unit testing
CONFIG_KUNIT=y
Further Reading
Table of contents