DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk10 min

How to Build and Run Linux Kernel Selftests Before Submitting a Patch

A practical guide to building and running Linux kernel selftests, narrowing runs by subsystem, preserving results, troubleshooting skips and timeouts, and combining kselftest with configuration and linux-next checks before submission.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

From the root of a Linux kernel source tree, the documented one-command path is make kselftest. For more control, build headers and the selftests separately, then run them with:

make headers
make -C tools/testing/selftests
make -C tools/testing/selftests run_tests

Use TARGETS to limit testing to the subsystem touched by your patch, keep build output separate with O= or KBUILD_OUTPUT, and treat the results as one part of a patch-specific validation plan. Some tests need root, a configured or booted kernel, special hardware, or more time than the default timeout allows.

As an Amazon Associate I earn from qualifying purchases.

What Linux kernel selftests are—and what they can prove

Linux kernel selftests, usually called kselftest, are small tests kept in the kernel source tree under tools/testing/selftests/. Each test targets particular kernel code paths and normally runs as a userspace process. The official documentation is at Linux Kernel Selftests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

That userspace design matters: many tests can run against an existing kernel and do not require you to boot a newly built kernel. Other tests deliberately exercise interfaces, configurations, devices, namespaces, tracing facilities, or architecture behavior that your running kernel must provide. A test can therefore be skipped or fail because the environment is missing a prerequisite, not because the patch is wrong.

#1 Best Overall

Selftests are not a universal proof of correctness. They cover the paths represented by the selected tests, kernel configuration, architecture, hardware, permissions, and runtime conditions you used. Before submitting, combine kselftest with the builds, configurations, and integration checks appropriate to your change.

Prerequisites before you start

Use a complete kernel source tree

Run the commands from the root of the kernel source tree being tested. The target names and available tests come from that tree’s Makefiles, so do not assume that a name listed for one kernel version exists in another.

Prepare the headers

The documented sequence begins with make headers. This prepares the exported headers needed by userspace selftests. If it fails, fix the kernel-tree or toolchain problem first; a later selftest build cannot reliably compensate for missing headers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check privileges and environment

Some tests require root privileges. Others need a particular Kconfig option, a booted kernel with the relevant feature, a device, or a runtime service. Read the target’s local documentation and Makefile when a test reports a skip or permission error. Running as an unprivileged user is still useful: the kselftest contribution rules explicitly say, “Do as much as you can if you’re not root.”

Decide whether you need a newly built kernel

The suite itself is a userspace program, but the documentation generally describes tests as being run after building, installing, and booting a kernel. If your patch changes code that is only present in the kernel you built, boot that kernel before interpreting results. If the patch affects a userspace-visible interface that already exists in the running kernel, the relevant selftest may be runnable without a custom boot.

The standard build-and-run workflow

For a full default run from the source root, use the three-stage form:

  1. Prepare userspace headers:

    make headers
  2. Build the in-tree selftests:

    make -C tools/testing/selftests
  3. Run the tests:

    make -C tools/testing/selftests run_tests

The run command prints pass/fail results. A failure is a signal to inspect the individual test, its prerequisites, and the environment; it is not automatically proof that the patch introduced a regression.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When you want the shortest documented path, use:

make kselftest

This top-level target builds and runs the suite. It is convenient for a broad smoke test, while the subdirectory form makes it easier to separate preparation, compilation, and execution when diagnosing a problem.

Run only the subsystem relevant to your patch

Full-suite runs can take time and may include tests unrelated to your change. The selftest Makefile accepts TARGETS so you can select one or more collections. For example, to build and run the ptrace tests:

make -C tools/testing/selftests TARGETS=ptrace run_tests

For top-level invocation, quote multiple target names:

make TARGETS="size timers" kselftest

You can exclude a selected collection with SKIP_TARGETS:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
make TARGETS="breakpoints size timers" SKIP_TARGETS=size kselftest

Use the target names supported by the Makefile in the exact kernel tree you are testing. A name that is valid in one release, architecture, or branch may not be present in another.

Make every selected target build successfully

By default, the build can succeed when at least one target builds. That behavior is useful for heterogeneous trees but can hide a broken target in a patch-specific selection. Add FORCE_TARGETS=1 when you want every target you selected to be required to build:

make TARGETS="breakpoints size timers" FORCE_TARGETS=1 kselftest

Use this stricter mode when your patch touches several collections or when a clean build result for each selected target is part of your submission evidence.

Keep selftest build output out of the source tree

To place output in a separate directory, run the target from the kernel source root and set either O= or KBUILD_OUTPUT=:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
make O=/tmp/kselftest kselftest

or:

make KBUILD_OUTPUT=/tmp/kselftest kselftest

If both variables are set, O= takes precedence. A separate output directory is useful when you need to preserve a clean source tree, compare runs from different configurations, or remove generated files without touching checked-out sources.

Get a concise summary and per-test records

Pass summary=1 to the top-level target:

make summary=1 kselftest

Summary mode produces summarized output and writes individual results to per-test files. Save those files with your patch-testing notes so a reviewer can distinguish a pass, failure, skip, timeout, or environment error for each test.

Install the tests and use the dedicated runner

The install target copies built selftests to tools/testing/selftests/kselftest_install by default. To choose another destination, set INSTALL_PATH:

make -C tools/testing/selftests install
make -C tools/testing/selftests INSTALL_PATH=/tmp/kselftest-install install

The installed directory contains run_kselftest.sh, which is useful when you want to list, select, or repeat tests without rebuilding them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

List available tests

./run_kselftest.sh -l

The list reflects what was installed from your source tree. Use it to verify spelling before selecting a collection or individual test.

Run a collection

./run_kselftest.sh -c <collection>

Replace <collection> with a collection shown by -l. Collection-level execution is useful for rerunning the subsystem that contains your change after you have fixed an environment problem.

Run named tests

./run_kselftest.sh -t <test>

Use the test name reported by the list or by an earlier run. Named execution narrows a failure to the smallest practical reproducer before you rerun the broader collection.

Rank #3
Linux Kernel Development
  • Used Book in Good Condition

Root requirements still apply when using the installed runner. Installing the files does not grant capabilities or make an unavailable kernel feature appear.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand timeouts and hotplug behavior

The documented default timeout is 45 seconds per test. It is an operational default, not a performance benchmark. A slow machine, a heavily loaded system, virtualized hardware, or a test waiting for a resource can exceed it. The installed runner supports --override-timeout when a longer limit is justified. Record the override in your test notes so a reviewer knows the run was not using the default.

A timeout is not necessarily fatal. Inspect the test’s output and whether it was waiting for a resource before treating it as a kernel regression. Avoid simply increasing the limit until a real hang disappears; first establish what the test is waiting for.

Hotplug tests need special care. Some can wait for a CPU or memory unit to become available, so they have dedicated targets. Normal hotplug mode is intentionally limited for safety. Run the dedicated target only when your patch requires that coverage and your test environment can safely perform the requested hotplug operation.

Interpret pass, skip, failure, and missing coverage correctly

Pass

A pass means the selected test completed successfully under the kernel, architecture, configuration, hardware, permissions, and timeout you used. It does not certify untested configurations or code paths.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Skip or “not run”

Skips commonly indicate a missing Kconfig option, unsupported architecture, absent device, insufficient privilege, or a test that deliberately avoids changing the current system. Find the test’s documented prerequisite before changing the code. If the feature is intentionally unconfigured, the top-level suite should remain usable; the kselftest guidance says contributors should “Don’t cause the top-level ‘make run_tests’ to fail if your feature is unconfigured.”

Failure

Reproduce a failure with the smallest target or named test. Capture the command, kernel commit, configuration, architecture, privilege level, runner timeout, and relevant logs. Then determine whether the failure is deterministic, an environmental issue, or a regression introduced by the patch.

No result because a target did not build

Without FORCE_TARGETS=1, the overall build can succeed if at least one target builds. If a relevant target is missing from the run, rebuild with that target selected and require all selected targets to build. A compile failure is coverage information, not a passing test.

A patch-focused validation plan

Kselftest should be matched to the patch rather than treated as an all-or-nothing ritual. Use this sequence to make the evidence proportional to the change:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Identify the kernel subsystem, Kconfig symbols, architectures, devices, and userspace interfaces touched by the patch.

  2. Build the kernel configuration you intend to test, prepare headers, and build the corresponding selftest targets.

  3. Boot or otherwise provide the kernel environment required by the tests. Confirm that the running kernel is the one whose behavior you are evaluating.

  4. Run the directly relevant target with FORCE_TARGETS=1 when you need every selected target to compile, then run a broader related collection if interactions are plausible.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  5. Repeat failures with the installed runner and a named test to reduce noise. Use summary=1 or preserve per-test files for review.

  6. Record intentional skips and their prerequisites instead of presenting them as passes.

  7. Extend the matrix when the patch changes configuration-dependent code, architecture code, locking, memory management, hotplug, or other areas where one environment cannot represent all behavior.

The Linux Kernel patch submission checklist advises testing multiple builds with related Kconfig options disabled and/or set to =m when applicable. It also calls for testing against the most recent linux-next tag when appropriate, so interactions with queued changes are detected. Neither recommendation means every patch needs every configuration or the entire selftest suite; choose a matrix that exercises the code and dependencies your patch changes.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Architecture, device, and configuration coverage

Selftests run in the environment you provide. A test that passes on one architecture does not establish behavior on another, and a test that passes with a built-in feature may not cover the module case. For patches involving devices or device-facing APIs, consult the kernel’s Device testing with kselftest documentation for the additional setup and safety considerations.

When a test depends on a device, namespace, privilege, CPU, memory node, or boot parameter, write that dependency next to the result. This prevents a later reader from confusing “not applicable here” with “verified.”

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Requirements for adding or changing a selftest

If your patch adds a test, preserve the properties that let the suite run in automation and in partial environments:

Test output should follow TAP (Test Anything Protocol) so continuous-integration systems can parse individual results. Emit clear diagnostics for prerequisites and failures, and ensure cleanup runs after both success and error paths.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common problems and recovery steps

Symptom Likely cause Action
make headers fails Incomplete tree, unsupported toolchain, or source/configuration error Fix the kernel build prerequisite and rerun header preparation before building selftests.
A target is skipped Missing Kconfig option, device, architecture support, or privilege Read that target’s requirements; enable or provide the prerequisite only when it is appropriate for the test.
Overall build succeeds but a selected test is absent At least one target built and the default did not require all targets Use FORCE_TARGETS=1 and build the target explicitly.
Permission denied The test requires root or a capability not held by the current user Rerun with the required privilege in an isolated test environment, or document the limitation.
Test exceeds 45 seconds System load, virtualization, resource wait, or a genuine hang Inspect logs and resource conditions; use --override-timeout only after establishing that a longer wait is legitimate.
Hotplug test waits indefinitely CPU or memory cannot be made available, or the wrong hotplug mode was chosen Check the dedicated hotplug target and system safety constraints; do not force normal hotplug mode to perform unsupported operations.
Failure appears only on linux-next Interaction with queued changes Record the exact tag and configuration, bisect or coordinate with the affected subsystem, and include the interaction in the patch discussion.

Command reference

Purpose Command
Prepare headers make headers
Build all in-tree selftests make -C tools/testing/selftests
Run all in-tree selftests make -C tools/testing/selftests run_tests
Build and run through the top level make kselftest
Run one collection make -C tools/testing/selftests TARGETS=ptrace run_tests
Run several collections make TARGETS="size timers" kselftest
Exclude a collection make TARGETS="breakpoints size timers" SKIP_TARGETS=size kselftest
Require every selected target to build make TARGETS="breakpoints size timers" FORCE_TARGETS=1 kselftest
Use a separate output directory make O=/tmp/kselftest kselftest
Write summarized results make summary=1 kselftest
Install tests make -C tools/testing/selftests install
List installed tests ./run_kselftest.sh -l
Run an installed collection ./run_kselftest.sh -c <collection>
Run an installed named test ./run_kselftest.sh -t <test>

What to report with your patch

Include enough detail that another contributor can understand exactly what was exercised:

This record turns “selftests passed” into reproducible evidence: it tells reviewers which code paths were tested, which were unavailable, and why.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.