Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 1 | Linux Kernel Selftests |
| 2 | |
| 3 | The kernel contains a set of "self tests" under the tools/testing/selftests/ |
Aleksander Alekseev | 3409f9a | 2016-08-18 12:36:53 +0300 | [diff] [blame] | 4 | directory. These are intended to be small tests to exercise individual code |
| 5 | paths in the kernel. Tests are intended to be run after building, installing |
| 6 | and booting a kernel. |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 7 | |
Shuah Khan | ddddda9 | 2014-07-02 09:51:38 -0600 | [diff] [blame] | 8 | On some systems, hot-plug tests could hang forever waiting for cpu and |
| 9 | memory to be ready to be offlined. A special hot-plug target is created |
| 10 | to run full range of hot-plug tests. In default mode, hot-plug tests run |
| 11 | in safe mode with a limited scope. In limited mode, cpu-hotplug test is |
| 12 | run on a single cpu as opposed to all hotplug capable cpus, and memory |
| 13 | hotplug test is run on 2% of hotplug capable memory instead of 10%. |
| 14 | |
| 15 | Running the selftests (hotplug tests are run in limited mode) |
| 16 | ============================================================= |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 17 | |
| 18 | To build the tests: |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 19 | $ make -C tools/testing/selftests |
| 20 | |
| 21 | |
| 22 | To run the tests: |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 23 | $ make -C tools/testing/selftests run_tests |
| 24 | |
Tim Bird | 3c41570 | 2014-11-19 16:16:16 -0800 | [diff] [blame] | 25 | To build and run the tests with a single command, use: |
| 26 | $ make kselftest |
| 27 | |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 28 | - note that some tests will require root privileges. |
| 29 | |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 30 | |
Tim Bird | 3c41570 | 2014-11-19 16:16:16 -0800 | [diff] [blame] | 31 | Running a subset of selftests |
| 32 | ======================================== |
| 33 | You can use the "TARGETS" variable on the make command line to specify |
| 34 | single test to run, or a list of tests to run. |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 35 | |
Tim Bird | 3c41570 | 2014-11-19 16:16:16 -0800 | [diff] [blame] | 36 | To run only tests targeted for a single subsystem: |
| 37 | $ make -C tools/testing/selftests TARGETS=ptrace run_tests |
| 38 | |
| 39 | You can specify multiple tests to build and run: |
| 40 | $ make TARGETS="size timers" kselftest |
| 41 | |
| 42 | See the top-level tools/testing/selftests/Makefile for the list of all |
| 43 | possible targets. |
| 44 | |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 45 | |
Shuah Khan | ddddda9 | 2014-07-02 09:51:38 -0600 | [diff] [blame] | 46 | Running the full range hotplug selftests |
| 47 | ======================================== |
| 48 | |
Tim Bird | 3c41570 | 2014-11-19 16:16:16 -0800 | [diff] [blame] | 49 | To build the hotplug tests: |
Shuah Khan | ddddda9 | 2014-07-02 09:51:38 -0600 | [diff] [blame] | 50 | $ make -C tools/testing/selftests hotplug |
| 51 | |
Tim Bird | 3c41570 | 2014-11-19 16:16:16 -0800 | [diff] [blame] | 52 | To run the hotplug tests: |
Shuah Khan | ddddda9 | 2014-07-02 09:51:38 -0600 | [diff] [blame] | 53 | $ make -C tools/testing/selftests run_hotplug |
| 54 | |
| 55 | - note that some tests will require root privileges. |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 56 | |
Tim Bird | 3c41570 | 2014-11-19 16:16:16 -0800 | [diff] [blame] | 57 | |
Wang Long | 76caa6c | 2015-09-23 09:35:25 +0000 | [diff] [blame] | 58 | Install selftests |
| 59 | ================= |
| 60 | |
| 61 | You can use kselftest_install.sh tool installs selftests in default |
| 62 | location which is tools/testing/selftests/kselftest or an user specified |
| 63 | location. |
| 64 | |
| 65 | To install selftests in default location: |
| 66 | $ cd tools/testing/selftests |
| 67 | $ ./kselftest_install.sh |
| 68 | |
| 69 | To install selftests in an user specified location: |
| 70 | $ cd tools/testing/selftests |
| 71 | $ ./kselftest_install.sh install_dir |
| 72 | |
| 73 | |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 74 | Contributing new tests |
| 75 | ====================== |
| 76 | |
Zhiyi Sun | 4db1fa6 | 2016-02-24 00:08:11 +0800 | [diff] [blame] | 77 | In general, the rules for selftests are |
Jeremy Kerr | 80d0342 | 2013-02-27 17:05:57 -0800 | [diff] [blame] | 78 | |
| 79 | * Do as much as you can if you're not root; |
| 80 | |
| 81 | * Don't take too long; |
| 82 | |
| 83 | * Don't break the build on any architecture, and |
| 84 | |
| 85 | * Don't cause the top-level "make run_tests" to fail if your feature is |
| 86 | unconfigured. |