4
4
Test Style and Nomenclature
5
5
===========================
6
6
7
- To make finding, writing, and using KUnit tests as simple as possible, it's
7
+ To make finding, writing, and using KUnit tests as simple as possible, it is
8
8
strongly encouraged that they are named and written according to the guidelines
9
- below. While it's possible to write KUnit tests which do not follow these rules,
9
+ below. While it is possible to write KUnit tests which do not follow these rules,
10
10
they may break some tooling, may conflict with other tests, and may not be run
11
11
automatically by testing systems.
12
12
13
- It's recommended that you only deviate from these guidelines when:
13
+ It is recommended that you only deviate from these guidelines when:
14
14
15
- 1. Porting tests to KUnit which are already known with an existing name, or
16
- 2. Writing tests which would cause serious problems if automatically run (e.g.,
17
- non-deterministically producing false positives or negatives, or taking an
18
- extremely long time to run) .
15
+ 1. Porting tests to KUnit which are already known with an existing name.
16
+ 2. Writing tests which would cause serious problems if automatically run. For
17
+ example, non-deterministically producing false positives or negatives, or
18
+ taking a long time to run.
19
19
20
20
Subsystems, Suites, and Tests
21
21
=============================
22
22
23
- In order to make tests as easy to find as possible , they're grouped into suites
24
- and subsystems. A test suite is a group of tests which test a related area of
25
- the kernel, and a subsystem is a set of test suites which test different parts
26
- of the same kernel subsystem or driver.
23
+ To make tests easy to find, they are grouped into suites and subsystems. A test
24
+ suite is a group of tests which test a related area of the kernel. A subsystem
25
+ is a set of test suites which test different parts of a kernel subsystem
26
+ or a driver.
27
27
28
28
Subsystems
29
29
----------
30
30
31
31
Every test suite must belong to a subsystem. A subsystem is a collection of one
32
32
or more KUnit test suites which test the same driver or part of the kernel. A
33
- rule of thumb is that a test subsystem should match a single kernel module. If
34
- the code being tested can't be compiled as a module, in many cases the subsystem
35
- should correspond to a directory in the source tree or an entry in the
36
- MAINTAINERS file. If unsure, follow the conventions set by tests in similar
37
- areas.
33
+ test subsystem should match a single kernel module. If the code being tested
34
+ cannot be compiled as a module, in many cases the subsystem should correspond to
35
+ a directory in the source tree or an entry in the ``MAINTAINERS `` file. If
36
+ unsure, follow the conventions set by tests in similar areas.
38
37
39
38
Test subsystems should be named after the code being tested, either after the
40
39
module (wherever possible), or after the directory or files being tested. Test
41
40
subsystems should be named to avoid ambiguity where necessary.
42
41
43
42
If a test subsystem name has multiple components, they should be separated by
44
43
underscores. *Do not * include "test" or "kunit" directly in the subsystem name
45
- unless you are actually testing other tests or the kunit framework itself.
46
-
47
- Example subsystems could be:
44
+ unless we are actually testing other tests or the kunit framework itself. For
45
+ example, subsystems could be called:
48
46
49
47
``ext4 ``
50
48
Matches the module and filesystem name.
@@ -56,48 +54,46 @@ Example subsystems could be:
56
54
Has several components (``snd ``, ``hda ``, ``codec ``, ``hdmi ``) separated by
57
55
underscores. Matches the module name.
58
56
59
- Avoid names like these :
57
+ Avoid names as shown in examples below :
60
58
61
59
``linear-ranges ``
62
60
Names should use underscores, not dashes, to separate words. Prefer
63
61
``linear_ranges ``.
64
62
``qos-kunit-test ``
65
- As well as using underscores, this name should not have "kunit-test" as a
66
- suffix, and ``qos `` is ambiguous as a subsystem name. `` power_qos `` would be a
67
- better name.
63
+ This name should use underscores, and not have "kunit-test" as a
64
+ suffix. ``qos `` is also ambiguous as a subsystem name, because several parts
65
+ of the kernel have a `` qos `` subsystem. `` power_qos `` would be a better name.
68
66
``pc_parallel_port ``
69
67
The corresponding module name is ``parport_pc ``, so this subsystem should also
70
68
be named ``parport_pc ``.
71
69
72
70
.. note ::
73
- The KUnit API and tools do not explicitly know about subsystems. They're
74
- simply a way of categorising test suites and naming modules which
75
- provides a simple, consistent way for humans to find and run tests. This
76
- may change in the future, though .
71
+ The KUnit API and tools do not explicitly know about subsystems. They are
72
+ a way of categorizing test suites and naming modules which provides a
73
+ simple, consistent way for humans to find and run tests. This may change
74
+ in the future.
77
75
78
76
Suites
79
77
------
80
78
81
79
KUnit tests are grouped into test suites, which cover a specific area of
82
- functionality being tested. Test suites can have shared initialisation and
83
- shutdown code which is run for all tests in the suite.
84
- Not all subsystems will need to be split into multiple test suites (e.g. simple drivers).
80
+ functionality being tested. Test suites can have shared initialization and
81
+ shutdown code which is run for all tests in the suite. Not all subsystems need
82
+ to be split into multiple test suites (for example, simple drivers).
85
83
86
84
Test suites are named after the subsystem they are part of. If a subsystem
87
85
contains several suites, the specific area under test should be appended to the
88
86
subsystem name, separated by an underscore.
89
87
90
88
In the event that there are multiple types of test using KUnit within a
91
- subsystem (e.g. , both unit tests and integration tests), they should be put into
92
- separate suites, with the type of test as the last element in the suite name.
93
- Unless these tests are actually present, avoid using ``_test ``, ``_unittest `` or
94
- similar in the suite name.
89
+ subsystem (for example , both unit tests and integration tests), they should be
90
+ put into separate suites, with the type of test as the last element in the suite
91
+ name. Unless these tests are actually present, avoid using ``_test ``, ``_unittest ``
92
+ or similar in the suite name.
95
93
96
94
The full test suite name (including the subsystem name) should be specified as
97
95
the ``.name `` member of the ``kunit_suite `` struct, and forms the base for the
98
- module name (see below).
99
-
100
- Example test suites could include:
96
+ module name. For example, test suites could include:
101
97
102
98
``ext4_inode ``
103
99
Part of the ``ext4 `` subsystem, testing the ``inode `` area.
@@ -109,34 +105,35 @@ Example test suites could include:
109
105
The ``kasan `` subsystem has only one suite, so the suite name is the same as
110
106
the subsystem name.
111
107
112
- Avoid names like :
108
+ Avoid names, for example :
113
109
114
110
``ext4_ext4_inode ``
115
- There's no reason to state the subsystem twice.
111
+ There is no reason to state the subsystem twice.
116
112
``property_entry ``
117
113
The suite name is ambiguous without the subsystem name.
118
114
``kasan_integration_test ``
119
115
Because there is only one suite in the ``kasan `` subsystem, the suite should
120
- just be called ``kasan ``. There's no need to redundantly add
121
- ``integration_test ``. Should a separate test suite with, for example, unit
122
- tests be added, then that suite could be named ``kasan_unittest `` or similar.
116
+ just be called as ``kasan ``. Do not redundantly add
117
+ ``integration_test ``. It should be a separate test suite. For example, if the
118
+ unit tests are added, then that suite could be named as ``kasan_unittest `` or
119
+ similar.
123
120
124
121
Test Cases
125
122
----------
126
123
127
124
Individual tests consist of a single function which tests a constrained
128
- codepath, property, or function. In the test output, individual tests' results
129
- will show up as subtests of the suite's results.
125
+ codepath, property, or function. In the test output, an individual test's
126
+ results will show up as subtests of the suite's results.
130
127
131
- Tests should be named after what they're testing. This is often the name of the
128
+ Tests should be named after what they are testing. This is often the name of the
132
129
function being tested, with a description of the input or codepath being tested.
133
130
As tests are C functions, they should be named and written in accordance with
134
131
the kernel coding style.
135
132
136
133
.. note ::
137
134
As tests are themselves functions, their names cannot conflict with
138
135
other C identifiers in the kernel. This may require some creative
139
- naming. It's a good idea to make your test functions `static ` to avoid
136
+ naming. It is a good idea to make your test functions `static ` to avoid
140
137
polluting the global namespace.
141
138
142
139
Example test names include:
@@ -162,16 +159,16 @@ This Kconfig entry must:
162
159
* be named ``CONFIG_<name>_KUNIT_TEST ``: where <name> is the name of the test
163
160
suite.
164
161
* be listed either alongside the config entries for the driver/subsystem being
165
- tested, or be under [Kernel Hacking]→ [Kernel Testing and Coverage]
166
- * depend on ``CONFIG_KUNIT ``
162
+ tested, or be under [Kernel Hacking]-> [Kernel Testing and Coverage]
163
+ * depend on ``CONFIG_KUNIT ``.
167
164
* be visible only if ``CONFIG_KUNIT_ALL_TESTS `` is not enabled.
168
165
* have a default value of ``CONFIG_KUNIT_ALL_TESTS ``.
169
- * have a brief description of KUnit in the help text
166
+ * have a brief description of KUnit in the help text.
170
167
171
- Unless there's a specific reason not to (e.g. the test is unable to be built as
172
- a module), Kconfig entries for tests should be tristate.
168
+ If we are not able to meet above conditions (for example, the test is unable to
169
+ be built as a module), Kconfig entries for tests should be tristate.
173
170
174
- An example Kconfig entry:
171
+ For example, a Kconfig entry might look like :
175
172
176
173
.. code-block :: none
177
174
@@ -182,8 +179,8 @@ An example Kconfig entry:
182
179
help
183
180
This builds unit tests for foo.
184
181
185
- For more information on KUnit and unit tests in general, please refer
186
- to the KUnit documentation in Documentation/dev-tools/kunit/.
182
+ For more information on KUnit and unit tests in general,
183
+ please refer to the KUnit documentation in Documentation/dev-tools/kunit/.
187
184
188
185
If unsure, say N.
189
186
0 commit comments