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