doc: kselftest: Fix KBUILD_OUTPUT usage instructions
[linux-2.6-microblaze.git] / Documentation / dev-tools / kselftest.rst
1 ======================
2 Linux Kernel Selftests
3 ======================
4
5 The kernel contains a set of "self tests" under the tools/testing/selftests/
6 directory. These are intended to be small tests to exercise individual code
7 paths in the kernel. Tests are intended to be run after building, installing
8 and booting a kernel.
9
10 You can find additional information on Kselftest framework, how to
11 write new tests using the framework on Kselftest wiki:
12
13 https://kselftest.wiki.kernel.org/
14
15 On some systems, hot-plug tests could hang forever waiting for cpu and
16 memory to be ready to be offlined. A special hot-plug target is created
17 to run the full range of hot-plug tests. In default mode, hot-plug tests run
18 in safe mode with a limited scope. In limited mode, cpu-hotplug test is
19 run on a single cpu as opposed to all hotplug capable cpus, and memory
20 hotplug test is run on 2% of hotplug capable memory instead of 10%.
21
22 Running the selftests (hotplug tests are run in limited mode)
23 =============================================================
24
25 To build the tests::
26
27   $ make -C tools/testing/selftests
28
29 To run the tests::
30
31   $ make -C tools/testing/selftests run_tests
32
33 To build and run the tests with a single command, use::
34
35   $ make kselftest
36
37 Note that some tests will require root privileges.
38
39 Kselftest supports saving output files in a separate directory and then
40 running tests. To locate output files in a separate directory two syntaxes
41 are supported. In both cases the working directory must be the root of the
42 kernel src. This is applicable to "Running a subset of selftests" section
43 below.
44
45 To build, save output files in a separate directory with O= ::
46
47   $ make O=/tmp/kselftest kselftest
48
49 To build, save output files in a separate directory with KBUILD_OUTPUT ::
50
51   $ export KBUILD_OUTPUT=/tmp/kselftest; make kselftest
52
53 The O= assignment takes precedence over the KBUILD_OUTPUT environment
54 variable.
55
56 The above commands by default run the tests and print full pass/fail report.
57 Kselftest supports "summary" option to make it easier to understand the test
58 results. Please find the detailed individual test results for each test in
59 /tmp/testname file(s) when summary option is specified. This is applicable
60 to "Running a subset of selftests" section below.
61
62 To run kselftest with summary option enabled ::
63
64   $ make summary=1 kselftest
65
66 Running a subset of selftests
67 =============================
68
69 You can use the "TARGETS" variable on the make command line to specify
70 single test to run, or a list of tests to run.
71
72 To run only tests targeted for a single subsystem::
73
74   $ make -C tools/testing/selftests TARGETS=ptrace run_tests
75
76 You can specify multiple tests to build and run::
77
78   $  make TARGETS="size timers" kselftest
79
80 To build, save output files in a separate directory with O= ::
81
82   $ make O=/tmp/kselftest TARGETS="size timers" kselftest
83
84 To build, save output files in a separate directory with KBUILD_OUTPUT ::
85
86   $ export KBUILD_OUTPUT=/tmp/kselftest; make TARGETS="size timers" kselftest
87
88 See the top-level tools/testing/selftests/Makefile for the list of all
89 possible targets.
90
91 Running the full range hotplug selftests
92 ========================================
93
94 To build the hotplug tests::
95
96   $ make -C tools/testing/selftests hotplug
97
98 To run the hotplug tests::
99
100   $ make -C tools/testing/selftests run_hotplug
101
102 Note that some tests will require root privileges.
103
104
105 Install selftests
106 =================
107
108 You can use the kselftest_install.sh tool to install selftests in the
109 default location, which is tools/testing/selftests/kselftest, or in a
110 user specified location.
111
112 To install selftests in default location::
113
114    $ cd tools/testing/selftests
115    $ ./kselftest_install.sh
116
117 To install selftests in a user specified location::
118
119    $ cd tools/testing/selftests
120    $ ./kselftest_install.sh install_dir
121
122 Running installed selftests
123 ===========================
124
125 Kselftest install as well as the Kselftest tarball provide a script
126 named "run_kselftest.sh" to run the tests.
127
128 You can simply do the following to run the installed Kselftests. Please
129 note some tests will require root privileges::
130
131    $ cd kselftest
132    $ ./run_kselftest.sh
133
134 Contributing new tests
135 ======================
136
137 In general, the rules for selftests are
138
139  * Do as much as you can if you're not root;
140
141  * Don't take too long;
142
143  * Don't break the build on any architecture, and
144
145  * Don't cause the top-level "make run_tests" to fail if your feature is
146    unconfigured.
147
148 Contributing new tests (details)
149 ================================
150
151  * Use TEST_GEN_XXX if such binaries or files are generated during
152    compiling.
153
154    TEST_PROGS, TEST_GEN_PROGS mean it is the executable tested by
155    default.
156
157    TEST_CUSTOM_PROGS should be used by tests that require custom build
158    rules and prevent common build rule use.
159
160    TEST_PROGS are for test shell scripts. Please ensure shell script has
161    its exec bit set. Otherwise, lib.mk run_tests will generate a warning.
162
163    TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests.
164
165    TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the
166    executable which is not tested by default.
167    TEST_FILES, TEST_GEN_FILES mean it is the file which is used by
168    test.
169
170  * First use the headers inside the kernel source and/or git repo, and then the
171    system headers.  Headers for the kernel release as opposed to headers
172    installed by the distro on the system should be the primary focus to be able
173    to find regressions.
174
175  * If a test needs specific kernel config options enabled, add a config file in
176    the test directory to enable them.
177
178    e.g: tools/testing/selftests/android/config
179
180 Test Harness
181 ============
182
183 The kselftest_harness.h file contains useful helpers to build tests.  The tests
184 from tools/testing/selftests/seccomp/seccomp_bpf.c can be used as example.
185
186 Example
187 -------
188
189 .. kernel-doc:: tools/testing/selftests/kselftest_harness.h
190     :doc: example
191
192
193 Helpers
194 -------
195
196 .. kernel-doc:: tools/testing/selftests/kselftest_harness.h
197     :functions: TH_LOG TEST TEST_SIGNAL FIXTURE FIXTURE_DATA FIXTURE_SETUP
198                 FIXTURE_TEARDOWN TEST_F TEST_HARNESS_MAIN
199
200 Operators
201 ---------
202
203 .. kernel-doc:: tools/testing/selftests/kselftest_harness.h
204     :doc: operators
205
206 .. kernel-doc:: tools/testing/selftests/kselftest_harness.h
207     :functions: ASSERT_EQ ASSERT_NE ASSERT_LT ASSERT_LE ASSERT_GT ASSERT_GE
208                 ASSERT_NULL ASSERT_TRUE ASSERT_NULL ASSERT_TRUE ASSERT_FALSE
209                 ASSERT_STREQ ASSERT_STRNE EXPECT_EQ EXPECT_NE EXPECT_LT
210                 EXPECT_LE EXPECT_GT EXPECT_GE EXPECT_NULL EXPECT_TRUE
211                 EXPECT_FALSE EXPECT_STREQ EXPECT_STRNE