blob: 5bd5903358392573d068ee457a26cbadfde7ad30 [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/
Aleksander Alekseev3409f9a2016-08-18 12:36:53 +03004directory. These are intended to be small tests to exercise individual code
5paths in the kernel. Tests are intended to be run after building, installing
6and booting a kernel.
Jeremy Kerr80d03422013-02-27 17:05:57 -08007
Shuah Khanddddda92014-07-02 09:51:38 -06008On some systems, hot-plug tests could hang forever waiting for cpu and
9memory to be ready to be offlined. A special hot-plug target is created
10to run full range of hot-plug tests. In default mode, hot-plug tests run
11in safe mode with a limited scope. In limited mode, cpu-hotplug test is
12run on a single cpu as opposed to all hotplug capable cpus, and memory
13hotplug test is run on 2% of hotplug capable memory instead of 10%.
14
15Running the selftests (hotplug tests are run in limited mode)
16=============================================================
Jeremy Kerr80d03422013-02-27 17:05:57 -080017
18To build the tests:
Jeremy Kerr80d03422013-02-27 17:05:57 -080019 $ make -C tools/testing/selftests
20
21
22To run the tests:
Jeremy Kerr80d03422013-02-27 17:05:57 -080023 $ make -C tools/testing/selftests run_tests
24
Tim Bird3c415702014-11-19 16:16:16 -080025To build and run the tests with a single command, use:
26 $ make kselftest
27
Jeremy Kerr80d03422013-02-27 17:05:57 -080028- note that some tests will require root privileges.
29
Jeremy Kerr80d03422013-02-27 17:05:57 -080030
Tim Bird3c415702014-11-19 16:16:16 -080031Running a subset of selftests
32========================================
33You can use the "TARGETS" variable on the make command line to specify
34single test to run, or a list of tests to run.
Jeremy Kerr80d03422013-02-27 17:05:57 -080035
Tim Bird3c415702014-11-19 16:16:16 -080036To run only tests targeted for a single subsystem:
37 $ make -C tools/testing/selftests TARGETS=ptrace run_tests
38
39You can specify multiple tests to build and run:
40 $ make TARGETS="size timers" kselftest
41
42See the top-level tools/testing/selftests/Makefile for the list of all
43possible targets.
44
Jeremy Kerr80d03422013-02-27 17:05:57 -080045
Shuah Khanddddda92014-07-02 09:51:38 -060046Running the full range hotplug selftests
47========================================
48
Tim Bird3c415702014-11-19 16:16:16 -080049To build the hotplug tests:
Shuah Khanddddda92014-07-02 09:51:38 -060050 $ make -C tools/testing/selftests hotplug
51
Tim Bird3c415702014-11-19 16:16:16 -080052To run the hotplug tests:
Shuah Khanddddda92014-07-02 09:51:38 -060053 $ make -C tools/testing/selftests run_hotplug
54
55- note that some tests will require root privileges.
Jeremy Kerr80d03422013-02-27 17:05:57 -080056
Tim Bird3c415702014-11-19 16:16:16 -080057
Wang Long76caa6c2015-09-23 09:35:25 +000058Install selftests
59=================
60
61You can use kselftest_install.sh tool installs selftests in default
Masahiro Yamada9332ef92017-02-27 14:28:47 -080062location which is tools/testing/selftests/kselftest or a user specified
Wang Long76caa6c2015-09-23 09:35:25 +000063location.
64
65To install selftests in default location:
66 $ cd tools/testing/selftests
67 $ ./kselftest_install.sh
68
Masahiro Yamada9332ef92017-02-27 14:28:47 -080069To install selftests in a user specified location:
Wang Long76caa6c2015-09-23 09:35:25 +000070 $ cd tools/testing/selftests
71 $ ./kselftest_install.sh install_dir
72
Shuah Khan78566cf2016-11-07 13:24:14 -070073Running installed selftests
74===========================
75
76Kselftest install as well as the Kselftest tarball provide a script
77named "run_kselftest.sh" to run the tests.
78
79You can simply do the following to run the installed Kselftests. Please
80note some tests will require root privileges.
81
82cd kselftest
83./run_kselftest.sh
Wang Long76caa6c2015-09-23 09:35:25 +000084
Jeremy Kerr80d03422013-02-27 17:05:57 -080085Contributing new tests
86======================
87
Zhiyi Sun4db1fa62016-02-24 00:08:11 +080088In general, the rules for selftests are
Jeremy Kerr80d03422013-02-27 17:05:57 -080089
90 * Do as much as you can if you're not root;
91
92 * Don't take too long;
93
94 * Don't break the build on any architecture, and
95
96 * Don't cause the top-level "make run_tests" to fail if your feature is
97 unconfigured.
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +080098
99Contributing new tests(details)
100===============================
101
102 * Use TEST_GEN_XXX if such binaries or files are generated during
103 compiling.
104 TEST_PROGS, TEST_GEN_PROGS mean it is the excutable tested by
105 default.
106 TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the
107 executable which is not tested by default.
108 TEST_FILES, TEST_GEN_FILES mean it is the file which is used by
109 test.