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

Chapter What You’ll Learn
KUnit Writing unit tests
Runtime Checks KASAN, lockdep, UBSAN

Example

# 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


Back to top

Linux Driver Development Guide is a community resource for learning kernel driver development. Not affiliated with the Linux Foundation. Content provided for educational purposes.

This site uses Just the Docs, a documentation theme for Jekyll.