Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Documentation: KUnit: Update filename best practices

Based on feedback from Linus[1] and follow-up discussions, change the
suggested file naming for KUnit tests.

Link: https://lore.kernel.org/lkml/CAHk-=wgim6pNiGTBMhP8Kd3tsB7_JTAuvNJ=XYd3wPvvk=OHog@mail.gmail.com/ [1]
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Kees Cook <kees@kernel.org>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Kees Cook and committed by
Shuah Khan
1757cc29 8400291e

+20 -9
+20 -9
Documentation/dev-tools/kunit/style.rst
··· 188 188 Test File and Module Names 189 189 ========================== 190 190 191 - KUnit tests can often be compiled as a module. These modules should be named 192 - after the test suite, followed by ``_test``. If this is likely to conflict with 193 - non-KUnit tests, the suffix ``_kunit`` can also be used. 191 + KUnit tests are often compiled as a separate module. To avoid conflicting 192 + with regular modules, KUnit modules should be named after the test suite, 193 + followed by ``_kunit`` (e.g. if "foobar" is the core module, then 194 + "foobar_kunit" is the KUnit test module). 194 195 195 - The easiest way of achieving this is to name the file containing the test suite 196 - ``<suite>_test.c`` (or, as above, ``<suite>_kunit.c``). This file should be 197 - placed next to the code under test. 196 + Test source files, whether compiled as a separate module or an 197 + ``#include`` in another source file, are best kept in a ``tests/`` 198 + subdirectory to not conflict with other source files (e.g. for 199 + tab-completion). 200 + 201 + Note that the ``_test`` suffix has also been used in some existing 202 + tests. The ``_kunit`` suffix is preferred, as it makes the distinction 203 + between KUnit and non-KUnit tests clearer. 204 + 205 + So for the common case, name the file containing the test suite 206 + ``tests/<suite>_kunit.c``. The ``tests`` directory should be placed at 207 + the same level as the code under test. For example, tests for 208 + ``lib/string.c`` live in ``lib/tests/string_kunit.c``. 198 209 199 210 If the suite name contains some or all of the name of the test's parent 200 - directory, it may make sense to modify the source filename to reduce redundancy. 201 - For example, a ``foo_firmware`` suite could be in the ``foo/firmware_test.c`` 202 - file. 211 + directory, it may make sense to modify the source filename to reduce 212 + redundancy. For example, a ``foo_firmware`` suite could be in the 213 + ``foo/tests/firmware_kunit.c`` file.