Blame view
Documentation/dev-tools/kselftest.rst
4.27 KB
cef04cdcb
|
1 |
====================== |
80d034285
|
2 |
Linux Kernel Selftests |
cef04cdcb
|
3 |
====================== |
80d034285
|
4 5 |
The kernel contains a set of "self tests" under the tools/testing/selftests/ |
3409f9ab7
|
6 7 8 |
directory. These are intended to be small tests to exercise individual code paths in the kernel. Tests are intended to be run after building, installing and booting a kernel. |
80d034285
|
9 |
|
ddddda9bc
|
10 11 12 13 14 15 16 17 18 |
On some systems, hot-plug tests could hang forever waiting for cpu and memory to be ready to be offlined. A special hot-plug target is created to run full range of hot-plug tests. In default mode, hot-plug tests run in safe mode with a limited scope. In limited mode, cpu-hotplug test is run on a single cpu as opposed to all hotplug capable cpus, and memory hotplug test is run on 2% of hotplug capable memory instead of 10%. Running the selftests (hotplug tests are run in limited mode) ============================================================= |
80d034285
|
19 |
|
cef04cdcb
|
20 |
To build the tests:: |
fde662d9c
|
21 |
$ make -C tools/testing/selftests |
cef04cdcb
|
22 23 |
To run the tests:: |
80d034285
|
24 |
|
fde662d9c
|
25 |
$ make -C tools/testing/selftests run_tests |
80d034285
|
26 |
|
cef04cdcb
|
27 |
To build and run the tests with a single command, use:: |
80d034285
|
28 |
|
fde662d9c
|
29 |
$ make kselftest |
3c415707b
|
30 |
|
cef04cdcb
|
31 |
Note that some tests will require root privileges. |
80d034285
|
32 |
|
80d034285
|
33 |
|
3c415707b
|
34 |
Running a subset of selftests |
cef04cdcb
|
35 |
============================= |
3c415707b
|
36 37 |
You can use the "TARGETS" variable on the make command line to specify single test to run, or a list of tests to run. |
cef04cdcb
|
38 |
To run only tests targeted for a single subsystem:: |
fde662d9c
|
39 |
$ make -C tools/testing/selftests TARGETS=ptrace run_tests |
3c415707b
|
40 |
|
cef04cdcb
|
41 |
You can specify multiple tests to build and run:: |
fde662d9c
|
42 |
$ make TARGETS="size timers" kselftest |
3c415707b
|
43 44 45 |
See the top-level tools/testing/selftests/Makefile for the list of all possible targets. |
80d034285
|
46 |
|
80d034285
|
47 |
|
ddddda9bc
|
48 49 |
Running the full range hotplug selftests ======================================== |
cef04cdcb
|
50 |
To build the hotplug tests:: |
fde662d9c
|
51 |
$ make -C tools/testing/selftests hotplug |
cef04cdcb
|
52 53 |
To run the hotplug tests:: |
ddddda9bc
|
54 |
|
fde662d9c
|
55 |
$ make -C tools/testing/selftests run_hotplug |
ddddda9bc
|
56 |
|
cef04cdcb
|
57 |
Note that some tests will require root privileges. |
80d034285
|
58 |
|
3c415707b
|
59 |
|
76caa6ca9
|
60 61 62 63 |
Install selftests ================= You can use kselftest_install.sh tool installs selftests in default |
9332ef9db
|
64 |
location which is tools/testing/selftests/kselftest or a user specified |
76caa6ca9
|
65 |
location. |
cef04cdcb
|
66 |
To install selftests in default location:: |
76caa6ca9
|
67 |
|
fde662d9c
|
68 69 |
$ cd tools/testing/selftests $ ./kselftest_install.sh |
cef04cdcb
|
70 71 |
To install selftests in a user specified location:: |
fde662d9c
|
72 73 |
$ cd tools/testing/selftests $ ./kselftest_install.sh install_dir |
76caa6ca9
|
74 |
|
78566cf13
|
75 76 77 78 79 80 81 |
Running installed selftests =========================== 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 |
fde662d9c
|
82 |
note some tests will require root privileges:: |
78566cf13
|
83 |
|
fde662d9c
|
84 85 |
$ cd kselftest $ ./run_kselftest.sh |
76caa6ca9
|
86 |
|
80d034285
|
87 88 |
Contributing new tests ====================== |
4db1fa664
|
89 |
In general, the rules for selftests are |
80d034285
|
90 91 92 93 94 95 96 97 98 |
* Do as much as you can if you're not root; * Don't take too long; * Don't break the build on any architecture, and * Don't cause the top-level "make run_tests" to fail if your feature is unconfigured. |
88baa78d1
|
99 |
|
cef04cdcb
|
100 101 |
Contributing new tests (details) ================================ |
88baa78d1
|
102 103 104 |
* Use TEST_GEN_XXX if such binaries or files are generated during compiling. |
fde662d9c
|
105 |
|
88baa78d1
|
106 107 |
TEST_PROGS, TEST_GEN_PROGS mean it is the excutable tested by default. |
fde662d9c
|
108 |
|
88baa78d1
|
109 110 111 112 |
TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the executable which is not tested by default. TEST_FILES, TEST_GEN_FILES mean it is the file which is used by test. |
7e6a32abd
|
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
Test Harness ============ The kselftest_harness.h file contains useful helpers to build tests. The tests from tools/testing/selftests/seccomp/seccomp_bpf.c can be used as example. Example ------- .. kernel-doc:: tools/testing/selftests/kselftest_harness.h :doc: example Helpers ------- .. kernel-doc:: tools/testing/selftests/kselftest_harness.h :functions: TH_LOG TEST TEST_SIGNAL FIXTURE FIXTURE_DATA FIXTURE_SETUP FIXTURE_TEARDOWN TEST_F TEST_HARNESS_MAIN Operators --------- .. kernel-doc:: tools/testing/selftests/kselftest_harness.h :doc: operators .. kernel-doc:: tools/testing/selftests/kselftest_harness.h :functions: ASSERT_EQ ASSERT_NE ASSERT_LT ASSERT_LE ASSERT_GT ASSERT_GE ASSERT_NULL ASSERT_TRUE ASSERT_NULL ASSERT_TRUE ASSERT_FALSE ASSERT_STREQ ASSERT_STRNE EXPECT_EQ EXPECT_NE EXPECT_LT EXPECT_LE EXPECT_GT EXPECT_GE EXPECT_NULL EXPECT_TRUE EXPECT_FALSE EXPECT_STREQ EXPECT_STRNE |