blob: a87d840bacfe11df785995eaee5698f23d565f94 [file] [log] [blame]
Jeremy Kerr80d03422013-02-27 17:05:57 -08001Linux Kernel Selftests
2
3The kernel contains a set of "self tests" under the tools/testing/selftests/
4directory. These are intended to be small unit tests to exercise individual
5code paths in the kernel.
6
Shuah Khanddddda92014-07-02 09:51:38 -06007On some systems, hot-plug tests could hang forever waiting for cpu and
8memory to be ready to be offlined. A special hot-plug target is created
9to run full range of hot-plug tests. In default mode, hot-plug tests run
10in safe mode with a limited scope. In limited mode, cpu-hotplug test is
11run on a single cpu as opposed to all hotplug capable cpus, and memory
12hotplug test is run on 2% of hotplug capable memory instead of 10%.
13
14Running the selftests (hotplug tests are run in limited mode)
15=============================================================
Jeremy Kerr80d03422013-02-27 17:05:57 -080016
17To build the tests:
Jeremy Kerr80d03422013-02-27 17:05:57 -080018 $ make -C tools/testing/selftests
19
20
21To run the tests:
Jeremy Kerr80d03422013-02-27 17:05:57 -080022 $ make -C tools/testing/selftests run_tests
23
Tim Bird3c415702014-11-19 16:16:16 -080024To build and run the tests with a single command, use:
25 $ make kselftest
26
Jeremy Kerr80d03422013-02-27 17:05:57 -080027- note that some tests will require root privileges.
28
Jeremy Kerr80d03422013-02-27 17:05:57 -080029
Tim Bird3c415702014-11-19 16:16:16 -080030Running a subset of selftests
31========================================
32You can use the "TARGETS" variable on the make command line to specify
33single test to run, or a list of tests to run.
Jeremy Kerr80d03422013-02-27 17:05:57 -080034
Tim Bird3c415702014-11-19 16:16:16 -080035To run only tests targeted for a single subsystem:
36 $ make -C tools/testing/selftests TARGETS=ptrace run_tests
37
38You can specify multiple tests to build and run:
39 $ make TARGETS="size timers" kselftest
40
41See the top-level tools/testing/selftests/Makefile for the list of all
42possible targets.
43
Jeremy Kerr80d03422013-02-27 17:05:57 -080044
Shuah Khanddddda92014-07-02 09:51:38 -060045Running the full range hotplug selftests
46========================================
47
Tim Bird3c415702014-11-19 16:16:16 -080048To build the hotplug tests:
Shuah Khanddddda92014-07-02 09:51:38 -060049 $ make -C tools/testing/selftests hotplug
50
Tim Bird3c415702014-11-19 16:16:16 -080051To run the hotplug tests:
Shuah Khanddddda92014-07-02 09:51:38 -060052 $ make -C tools/testing/selftests run_hotplug
53
54- note that some tests will require root privileges.
Jeremy Kerr80d03422013-02-27 17:05:57 -080055
Tim Bird3c415702014-11-19 16:16:16 -080056
Jeremy Kerr80d03422013-02-27 17:05:57 -080057Contributing new tests
58======================
59
60In general, the rules for for selftests are
61
62 * Do as much as you can if you're not root;
63
64 * Don't take too long;
65
66 * Don't break the build on any architecture, and
67
68 * Don't cause the top-level "make run_tests" to fail if your feature is
69 unconfigured.