On this page
Debugging and Testing
Coverage: printk/dynamic debug → KGDB → KUnit → kselftest → LTP → syzkaller → fault injection → lockdep integration Kernel versions: 2.6 ~ 6.x
printk: Kernel Logging
// kernel/printk/printk.c
;
// Log level filtering:
// KERN_EMERG(0) KERN_ALERT(1) KERN_CRIT(2) KERN_ERR(3)
// KERN_WARNING(4) KERN_NOTICE(5) KERN_INFO(6) KERN_DEBUG(7)
// Console output filtering:
echo 4 > /proc/sys/kernel/printk // Only output ERROR and above to console
// 5.x+ Structured logging: dev_printk, pr_fmt
Dynamic Debug
# Enable debug logging by module/function/file/line (runtime, no recompilation needed)
# p=printk, f=include func name, l=include line, t=include thread id
# View enabled entries
|
KGDB: Kernel-level GDB
# Remote kernel debugging via serial port (similar to gdbserver)
# boot: kgdboc=ttyS0,115200 kgdbwait
# gdb vmlinux → target remote /dev/ttyS0 → set breakpoints, step through
# SysRq-g to enter KGDB
KUnit: Kernel Unit Testing
// lib/kunit/
// Similar to user-space unit testing frameworks, executes entirely within the kernel
static void
static struct kunit_case my_test_cases = ;
// Run: Built-in at compile time → Automatically executed at boot → Results in dmesg
kselftest: Kernel Self-Test Suite
# Kernel self-contained tests (tools/testing/selftests/)
# Covers: syscalls, memory management, networking, BPF, filesystems, ...
Syzkaller: Fuzzing
LTP (Linux Test Project)
# Largest kernel/glibc regression test suite (github.com/linux-test-project/ltp)
Fault Injection
# Fault injection framework: Simulate various hardware/memory/IO faults
# Verify that error handling paths are correct
# Memory allocation failure:
# IO error:
References
- Source Code:
kernel/printk/,kernel/debug/,lib/kunit/,tools/testing/selftests/ - Kernel Documentation:
Documentation/dev-tools/,Documentation/admin-guide/dynamic-debug-howto.rst - Tools: syzkaller (github.com/google/syzkaller), LTP (github.com/linux-test-project/ltp)
Keywords: printk, dynamic debug, KGDB, KUnit, kselftest, syzkaller, LTP, fault injection