aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/dev-tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-07-07 17:04:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-07 17:04:47 -0400
commitef3ad0898a60d30da7f170032992914998c366e5 (patch)
tree6076ccc1d0769a3b997f7948ab773e8bffcc784d /Documentation/dev-tools
parent37949075ab628e8ef36a877108c2d95b13221cc5 (diff)
parente67f85fb96ca80e5a60ea69c536affed0affc77d (diff)
Merge tag 'linux-kselftest-4.13-rc1-update' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest updates from Shuah Khan: "This update consists of: - TAP13 framework and changes to some tests to convert to TAP13. Converting kselftest output to standard format will help identify run to run differences and pin point failures easily. TAP13 format has been in use for several years and the output is human friendly. Please find the specification: https://testanything.org/tap-version-13-specification.html Credit goes to Tim Bird for recommending TAP13 as a suitable format, and to Grag KH for kick starting the work with help from Paul Elder and Alice Ferrazzi The first phase of the TAp13 conversion is included in this update. Future updates will include updates to rest of the tests. - Masami Hiramatsu fixed ftrace to run on 4.9 stable kernels. - Kselftest documnetation has been converted to ReST format. Document now has a new home under Documentation/dev-tools. - kselftest_harness.h is now available for general use as a result of Mickaël Salaün's work. - Several fixes to skip and/or fail tests gracefully on older releases" * tag 'linux-kselftest-4.13-rc1-update' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (48 commits) selftests: membarrier: use ksft_* var arg msg api selftests: breakpoints: breakpoint_test_arm64: convert test to use TAP13 selftests: breakpoints: step_after_suspend_test use ksft_* var arg msg api selftests: breakpoint_test: use ksft_* var arg msg api kselftest: add ksft_print_msg() function to output general information kselftest: make ksft_* output functions variadic selftests/capabilities: Fix the test_execve test selftests: intel_pstate: add .gitignore selftests: fix memory-hotplug test selftests: add missing test name in memory-hotplug test selftests: check percentage range for memory-hotplug test selftests: check hot-pluggagble memory for memory-hotplug test selftests: typo correction for memory-hotplug test selftests: ftrace: Use md5sum to take less time of checking logs tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict kselftest.rst: do some adjustments after ReST conversion selftest/net/Makefile: Specify output with $(OUTPUT) selftest/intel_pstate/aperf: Use LDLIBS instead of LDFLAGS selftest/memfd/Makefile: Fix build error selftests: lib: Skip tests on missing test modules ...
Diffstat (limited to 'Documentation/dev-tools')
-rw-r--r--Documentation/dev-tools/index.rst1
-rw-r--r--Documentation/dev-tools/kselftest.rst155
2 files changed, 156 insertions, 0 deletions
diff --git a/Documentation/dev-tools/index.rst b/Documentation/dev-tools/index.rst
index 4ac991dbddb7..a81787cd47d7 100644
--- a/Documentation/dev-tools/index.rst
+++ b/Documentation/dev-tools/index.rst
@@ -24,6 +24,7 @@ whole; patches welcome!
24 kmemcheck 24 kmemcheck
25 gdb-kernel-debugging 25 gdb-kernel-debugging
26 kgdb 26 kgdb
27 kselftest
27 28
28 29
29.. only:: subproject and html 30.. only:: subproject and html
diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst
new file mode 100644
index 000000000000..ebd03d11d2c2
--- /dev/null
+++ b/Documentation/dev-tools/kselftest.rst
@@ -0,0 +1,155 @@
1======================
2Linux Kernel Selftests
3======================
4
5The kernel contains a set of "self tests" under the tools/testing/selftests/
6directory. These are intended to be small tests to exercise individual code
7paths in the kernel. Tests are intended to be run after building, installing
8and booting a kernel.
9
10On some systems, hot-plug tests could hang forever waiting for cpu and
11memory to be ready to be offlined. A special hot-plug target is created
12to run full range of hot-plug tests. In default mode, hot-plug tests run
13in safe mode with a limited scope. In limited mode, cpu-hotplug test is
14run on a single cpu as opposed to all hotplug capable cpus, and memory
15hotplug test is run on 2% of hotplug capable memory instead of 10%.
16
17Running the selftests (hotplug tests are run in limited mode)
18=============================================================
19
20To build the tests::
21
22 $ make -C tools/testing/selftests
23
24To run the tests::
25
26 $ make -C tools/testing/selftests run_tests
27
28To build and run the tests with a single command, use::
29
30 $ make kselftest
31
32Note that some tests will require root privileges.
33
34
35Running a subset of selftests
36=============================
37
38You can use the "TARGETS" variable on the make command line to specify
39single test to run, or a list of tests to run.
40
41To run only tests targeted for a single subsystem::
42
43 $ make -C tools/testing/selftests TARGETS=ptrace run_tests
44
45You can specify multiple tests to build and run::
46
47 $ make TARGETS="size timers" kselftest
48
49See the top-level tools/testing/selftests/Makefile for the list of all
50possible targets.
51
52
53Running the full range hotplug selftests
54========================================
55
56To build the hotplug tests::
57
58 $ make -C tools/testing/selftests hotplug
59
60To run the hotplug tests::
61
62 $ make -C tools/testing/selftests run_hotplug
63
64Note that some tests will require root privileges.
65
66
67Install selftests
68=================
69
70You can use kselftest_install.sh tool installs selftests in default
71location which is tools/testing/selftests/kselftest or a user specified
72location.
73
74To install selftests in default location::
75
76 $ cd tools/testing/selftests
77 $ ./kselftest_install.sh
78
79To install selftests in a user specified location::
80
81 $ cd tools/testing/selftests
82 $ ./kselftest_install.sh install_dir
83
84Running installed selftests
85===========================
86
87Kselftest install as well as the Kselftest tarball provide a script
88named "run_kselftest.sh" to run the tests.
89
90You can simply do the following to run the installed Kselftests. Please
91note some tests will require root privileges::
92
93 $ cd kselftest
94 $ ./run_kselftest.sh
95
96Contributing new tests
97======================
98
99In general, the rules for selftests are
100
101 * Do as much as you can if you're not root;
102
103 * Don't take too long;
104
105 * Don't break the build on any architecture, and
106
107 * Don't cause the top-level "make run_tests" to fail if your feature is
108 unconfigured.
109
110Contributing new tests (details)
111================================
112
113 * Use TEST_GEN_XXX if such binaries or files are generated during
114 compiling.
115
116 TEST_PROGS, TEST_GEN_PROGS mean it is the excutable tested by
117 default.
118
119 TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the
120 executable which is not tested by default.
121 TEST_FILES, TEST_GEN_FILES mean it is the file which is used by
122 test.
123
124Test Harness
125============
126
127The kselftest_harness.h file contains useful helpers to build tests. The tests
128from tools/testing/selftests/seccomp/seccomp_bpf.c can be used as example.
129
130Example
131-------
132
133.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
134 :doc: example
135
136
137Helpers
138-------
139
140.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
141 :functions: TH_LOG TEST TEST_SIGNAL FIXTURE FIXTURE_DATA FIXTURE_SETUP
142 FIXTURE_TEARDOWN TEST_F TEST_HARNESS_MAIN
143
144Operators
145---------
146
147.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
148 :doc: operators
149
150.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
151 :functions: ASSERT_EQ ASSERT_NE ASSERT_LT ASSERT_LE ASSERT_GT ASSERT_GE
152 ASSERT_NULL ASSERT_TRUE ASSERT_NULL ASSERT_TRUE ASSERT_FALSE
153 ASSERT_STREQ ASSERT_STRNE EXPECT_EQ EXPECT_NE EXPECT_LT
154 EXPECT_LE EXPECT_GT EXPECT_GE EXPECT_NULL EXPECT_TRUE
155 EXPECT_FALSE EXPECT_STREQ EXPECT_STRNE