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 kernelci.org 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 kselftest_install.sh 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 run_kselftest.sh 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.
  • https://git.kernel.org/cgit/linux/kernel/git/shuah/linux-kselftest.git/
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 serves 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 /

Leave a Reply

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

Comments Protected by WP-SpamShield Anti-Spam