November 29, 2016 - Shuah Khan

An Introduction to Testing the Linux Kernel with Kselftest

The Linux kernel contains a set of developer unit and regression tests (Kselftests) under tools/testing/selftests; these tests exercise individual code paths in the kernel. In this blog post, I’ll explain how to build and run these tests, run Kselftest on a system it’s built on, and how to install and run tests on a target test system.

Even though kselftest’s main purpose is for developer regression test, testers and users can also use it to ensure there are no regressions in a new kernel. Kselftest is run everyday on several Linux kernel trees on the 0-Day and Linux kernel integration test rings.

How to Build Kselftest

The tests are intended to be run after building, installing, and booting a kernel.

Boot the new kernel, then execute the following

Please note, some tests require root privileges.

You can run a subset of selftests using “TARGETS” make command variable to specify
single test or a list of tests to run.

See the top-level tools/testing/selftests/Makefile for the list of all possible targets.

Install Kselftest

You can use tool installs selftests in default location which is tools/testing/selftests/kselftest or an user specified location.

Generate the Kselftest Install Package

The generated Kselftest tarball can be copied to target test system for running tests.

Run Installed Kselftests

Kselftest install as well as the Kselftest tarball provide a script named to run the tests. You can simply do the following to run the installed Kselftests. Please note some tests will require root privileges.

Interpret Kselftest Results

When Kselftest suite is run each test prints out Pass or Fail and the reason for failure. Example results for a few tests in the suite:

Additional Resources

To learn more about using Kselftest, check out the following resources

  • Documentation/kselftest.txt, and
  • the Kselftest source files, located in tools/testing/selftests.
Shuah Khan

About Shuah Khan

Shuah Khan is a Senior Linux Kernel Developer at Samsung's Open Source Group. She is a Linux Kernel Maintainer and Contributor who focuses on Linux Media Core and Power Management. She maintains Kernel Selftest framework. She has contributed to IOMMU, and DMA areas. In addition, she is helping with stable release kernel testing. She authored Linux Kernel Testing and Debugging paper published on the Linux Journal and writes Linux Journal kernel news articles. She has presented at several Linux conferences and Linux Kernel Developer Keynote Panels. She served on the Linux Foundation Technical Advisory Board. Prior to joining Samsung, she worked as a kernel and software developer at HP and Lucent.

Image Credits: OSDC

Development / Linux Kernel Development / kselftest / regression testing / Unit Testing /


  • Dhinakar says:


    I work for Samsung in Bangalore. I am looking for open source tests for linux kernel validation for various IPs. May I know what are the tests available in Kselftest and how different are they compared to LTP or Autotest?


    • Shuah Khan Shuah Khan says:

      Kselftest is a kernel regression and unit testing suite for kernel developers. These tests are written by kernel developers to regression test kernel features. Unlike LTP and Autotest, Kselftest consists of black and white box tests. Kselftest is part of kernel sources and please find them under tools/testing/selftests. Please find the details on how to run the tests in Documentation/kselftest.txt

  • Suresh says:


    I want to run Kselftest in my arm target board. Can you tell me the steps to cross-compile it. And can we use the cross compiled images in my ARM board?

Leave a Reply

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

Comments Protected by WP-SpamShield Anti-Spam