Skip to main content
skill CX Codex

kernel-testing — Claude Code skill: KUnit, kselftest, syzkaller

Skill for Linux kernel testing: KUnit for unit tests, kselftest for regression checks, syzkaller for fuzzing, and LTP for syscall compatibility. Activates on kunit.py queries, syzkaller config, or KernelCI setup.

MIT 382 installs ★ 298 updated 2026-06-27

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mohitmishra786/low-level-dev-skills --skill kernel-testing -a claude-code
Open on GitHub

What kernel-testing does

Available on Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, and OpenCode. Covers four testing layers: KUnit runs unit tests in kernel context with macros like KUNIT_EXPECT_EQ; kselftest checks syscall and ioctl behavior from userspace code in tools/testing/selftests/; syzkaller fuzzes kernel interfaces with kcov coverage reporting; Linux Test Project validates syscall compatibility across distributions.

Build the kernel with CONFIG_KUNIT=y and optionally CONFIG_KCOV=y, CONFIG_KASAN=y for debugging. Syzkaller needs a QEMU VM configured in JSON with the full path to a compiled kernel image. KernelCI ties these tests into CI/CD, validating patches against allmodconfig and uploading results.

The skill includes templates: KUnit test structure with kunit_test_suite, Makefile for kselftest, syzkaller config, and a complete KernelCI pipeline. Each part stands alone — write KUnit tests without syzkaller, or run LTP in isolation for regression validation.

What it helps with

  • write a KUnit test for a kernel function
  • add a selftest to tools/testing/selftests/
  • configure syzkaller with kcov to fuzz syscalls
  • set up kernel patch testing in KernelCI
  • measure code coverage during test runs

Example prompts for the agent

  • Write a KUnit test for kmalloc with error checking
  • Build and run kselftest for the open syscall
  • Set up syzkaller fuzzing with CONFIG_KASAN and show me how to reproduce a crash

How to install kernel-testing

1Skills CLI (Vercel)

npx skills add mohitmishra786/low-level-dev-skills --skill kernel-testing -a claude-code

2Manually: put the files in place

~/.claude/skills/kernel-testing/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/kernel-testing/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about kernel-testing

How do I install kernel-testing in Claude Code?

Run npx skills add mohitmishra786/low-level-dev-skills --skill kernel-testing -a claude-code, then edit ~/.claude/skills/kernel-testing/SKILL.md. For other platforms, change the flag: -a codex for Codex, -a cursor for Cursor, -a gemini-cli for Gemini CLI.

What does kernel-testing do?

It guides writing KUnit unit tests, kselftest regression checks, syzkaller fuzzing with kcov, and KernelCI integration. Covers the full range of kernel testing from function-level logic to syscall and ioctl behavior.

What kernel config is needed for KUnit and syzkaller?

Minimum: CONFIG_KUNIT=y for KUnit tests. For syzkaller, add CONFIG_KCOV=y (coverage), CONFIG_KASAN=y (error detection), and CONFIG_DEBUG_INFO_DWARF5=y for debugging. Use scripts/config --enable KUNIT KCOV KASAN and rebuild.

Source text

SKILL.md · MIT
---
name: kernel-testing
description: Linux kernel testing skill for KUnit, kselftest, syzkaller, and LTP. Use when writing KUnit tests, running kselftest harness, configuring syzkaller fuzzing, or integrating KernelCI. Activates on queries about kunit_test_suite, kunit.py, kselftest, syzkaller, kcov, or Linux Test Project.
---

# Kernel Testing

## Purpose

Guide agents through testing the Linux kernel: KUnit in-kernel unit tests, the kselftest harness, syzkaller fuzzing with kcov coverage, Linux Test Project (LTP) syscall regression, and KernelCI integration for continuous testing.

## When to Use

- Writing unit tests for kernel library code or driver helpers
- Adding regression tests to `tools/testing/selftests/`
- Fuzzing syscalls and ioctl interfaces with syzkaller
- Measuring kernel code coverage with kcov
- Running LTP for syscall compatibility validation
- Setting up CI for kernel patches

## Workflow

### 1. KUnit — in-kernel unit tests

```c
// test_example.c
#include <kunit/test.h>

static void example_test(struct kunit *test)
{
    KUNIT_EXPECT_EQ(test, 1 + 1, 2);
    KUNIT_ASSERT_NOT_ERR_OR_NULL(test, kmalloc(16, GFP_KERNEL));
}

static struct kunit_case example_test_cases[] = {
    KUNIT_CASE(example_test),
    {}
};

static struct kunit_suite example_suite = {
    .name = "example",
    .test_cases = example_test_cases,
};
kunit_test_suite(example_suite);

MODULE_LICENSE("GPL");
```

```makefile
# Makefile
obj-$(CONFIG_KUNIT) += test_example.o
```

```bash
# Run KUnit (in-tree)
./tools/testing/kunit/kunit.py run

# Run specific test
./tools/testing/kunit/kunit.py run --filter example

# With cross-compilation
./tools/testing/kunit/kunit.py run --cross_compile aarch64-linux-gnu- \
    --arch arm64
```

KUnit runs in kernel context (UMH or dedicated kunit kernel). Use `kunit_kmalloc` for test allocations.

### 2. kselftest harness

```bash
# Build all selftests
cd tools/testing/selftests
make -j$(nproc)

# Run all
make run_tests

# Run specific test
./memfd/memfd_test
./mount/run_unprivileged_remount.sh
```

Adding a new selftest:

```
tools/testing/selftests/mytest/
├── Makefile
├── mytest.c
└── config        # optional kconfig requirements
```

```makefile
# tools/testing/selftests/mytest/Makefile
CFLAGS += -Wall
TEST_GEN_FILES := mytest
TEST_PROGS := mytest

include ../lib.mk
```

```bash
# Run from top-level
make -C tools/testing/selftests/mytest run_tests
```

### 3. syzkaller fuzzing

```bash
# Install syzkaller
git clone https://github.com/google/syzkaller
cd syzkaller && make

# Manager config (manager.cfg)
{
    "target": "linux/amd64",
    "http": "127.0.0.1:56741",
    "workdir": "/tmp/syzkaller",
    "kernel_obj": "/path/to/kernel/build",
    "syzkaller": "/path/to/syzkaller",
    "procs": 8,
    "type": "qemu",
    "vm": {
        "count": 4,
        "kernel": "/path/to/bzImage",
        "cpu": 2,
        "mem": 2048
    }
}
```

```bash
# Start manager
./bin/syz-manager -config manager.cfg

# Reproduce a crash
./bin/syz-repro -config manager.cfg crash-report.txt
```

Kernel requirements: `CONFIG_KCOV`, `CONFIG_DEBUG_FS`, `CONFIG_KASAN` (recommended).

### 4. kcov — kernel coverage

```bash
# Enable kcov on instrumented kernel
# CONFIG_KCOV=y in kernel config

# syzkaller uses kcov automatically
# Manual coverage via debugfs
ls /sys/kernel/debug/kcov/
```

Coverage guides syzkaller toward unexplored kernel paths.

### 5. Linux Test Project (LTP)

```bash
# Build LTP
git clone https://github.com/linux-test-project/ltp
cd ltp
make autotools
./configure
make -j$(nproc)
make install

# Run syscall tests
cd /opt/ltp
./runltp -f syscalls

# Run specific test
./runltp -f syscalls -s pipe01
```

LTP categories: syscalls, FS, network, IPC, controllers, security.

### 6. KernelCI

```bash
# Local kernel build test (simplified workflow)
# KernelCI tests patches against multiple defconfigs

# Submit build to KernelCI (project-specific tokens)
# See https://kernelci.org/docs/

# Check boot and kselftest results in KernelCI dashboard
```

Typical CI pipeline:

```
Patch → build (allmodconfig) → boot test (QEMU) → kselftest → LTP subset
```

### 7. Testing decision tree

```
What to test?
├── Pure kernel function logic → KUnit
├── Userspace-visible behavior (syscall, ioctl) → kselftest
├── Security/crash finding → syzkaller + KASAN
├── Regression across distros → LTP
└── Upstream patch CI → KernelCI
```

### 8. Debug-friendly test kernel config

```
CONFIG_KUNIT=y
CONFIG_KCOV=y
CONFIG_KASAN=y
CONFIG_DEBUG_INFO_DWARF5=y
CONFIG_FRAME_POINTER=y
CONFIG_FTRACE=y
```

```bash
make kvm_guest.config   # reasonable test config base
scripts/config --enable KUNIT KCOV KASAN
make olddefconfig
```

## Common Problems

| Symptom | Cause | Fix |
|---------|-------|-----|
| KUnit tests not found | CONFIG_KUNIT disabled | Enable in .config; rebuild |
| kselftest SKIP | Missing kernel feature | Check `config` file requirements |
| syzkaller no crashes | Wrong VM config | Verify QEMU boots; check kernel cmdline |
| kcov zero coverage | CONFIG_KCOV off | Rebuild kernel with kcov |
| LTP massive failures | Wrong environment | Run as root; check prerequisites in README |
| kunit.py hangs | UML vs hardware mismatch | Specify `--arch` and cross-compile |

## Related Skills

- `skills/low-level-programming/linux-kernel-modules` — modules under test
- `skills/kernel/device-drivers` — driver logic to unit test
- `skills/kernel/kernel-debugging` — debug failures found by tests
- `skills/runtimes/fuzzing` — userspace fuzzing concepts (libFuzzer)
- `skills/runtimes/sanitizers` — KASAN/KMSAN for kernel
- `skills/virtualization/qemu-kvm` — QEMU for kernel boot testing

© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills

Similar skills

All skills for Testing and QA →

From the same set140

The whole set →
gpio-baremetal gpio-baremetal configures GPIO modes, alternate functions, pull resistors, and EXTI interrupts on bare-metal microcontrollers without HAL. CX Codex +1 383installs apple-silicon A skill for developers building on Apple Silicon: tuning code for unified memory, Metal Performance Shaders, Instruments profiling, Rosetta 2 behavior, and 16KB page size quirks. CX Codex +1 383installs code-generation-and-backends code-generation-and-backends explains LLVM backend stages, from IR legalization to assembly output. Use it to investigate llc, TableGen patterns, or the outline of a new target port. CX Codex +1 382installs jit-compilation jit-compilation teaches the agent to build a JIT: LLVM ORC and LLJIT, Cranelift, inline caches, trampolines, Rust dynasm. Useful for interpreter hot paths and REPLs. CX Codex +1 382installs branch-prediction-and-speculation branch-prediction-and-speculation is a Claude Code skill that explains CPU branch prediction and speculative execution to help optimize hot loops and protect code from cache timing leaks. CX Codex +1 382installs os-dev-scratch os-dev-scratch is a Claude Code skill for building a minimal x86-64 OS, from boot stages to drivers and context switching. It activates on questions about kernel boot, interrupts, page tables, or QEMU. CX Codex +1 381installs kernel-security kernel-security — a skill for SELinux and AppArmor policies, seccomp-bpf sandboxing, KASLR, Intel CET, ARM PAC and BTI. Write LSM rules, triage kernel CVEs, and configure kernel mitigations. CX Codex +1 381installs peripherals-from-datasheet peripherals-from-datasheet guides driver development directly from MCU reference manuals. Helpful when writing bare-metal register code without a vendor HAL or migrating peripherals across chips. CX Codex +1 380installs

Project sponsors

Companies that keep this analytics open