Skip to content

Commit 665fe72

Browse files
committed
Merge tag 'linux-kselftest-kunit-5.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull KUnit updates from Shuah Khan: "This consists of several fixes and an important feature to discourage running KUnit tests on production systems. Running tests on a production system could leave the system in a bad state. Summary: - Add a new taint type, TAINT_TEST to signal that a test has been run. This should discourage people from running these tests on production systems, and to make it easier to tell if tests have been run accidentally (by loading the wrong configuration, etc) - Several documentation and tool enhancements and fixes" * tag 'linux-kselftest-kunit-5.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (29 commits) Documentation: KUnit: Fix example with compilation error Documentation: kunit: Add CLI args for kunit_tool kcsan: test: Add a .kunitconfig to run KCSAN tests kunit: executor: Fix a memory leak on failure in kunit_filter_tests clk: explicitly disable CONFIG_UML_PCI_OVER_VIRTIO in .kunitconfig mmc: sdhci-of-aspeed: test: Use kunit_test_suite() macro nitro_enclaves: test: Use kunit_test_suite() macro thunderbolt: test: Use kunit_test_suite() macro kunit: flatten kunit_suite*** to kunit_suite** in .kunit_test_suites kunit: unify module and builtin suite definitions selftest: Taint kernel when test module loaded module: panic: Taint the kernel when selftest modules load Documentation: kunit: fix example run_kunit func to allow spaces in args Documentation: kunit: Cleanup run_wrapper, fix x-ref kunit: test.h: fix a kernel-doc markup kunit: tool: Enable virtio/PCI by default on UML kunit: tool: make --kunitconfig repeatable, blindly concat kunit: add coverage_uml.config to enable GCOV on UML kunit: tool: refactor internal kconfig handling, allow overriding kunit: tool: introduce --qemu_args ...
2 parents aad26f5 + 4c39251 commit 665fe72

36 files changed

+657
-592
lines changed

Documentation/admin-guide/tainted-kernels.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Bit Log Number Reason that got the kernel tainted
100100
15 _/K 32768 kernel has been live patched
101101
16 _/X 65536 auxiliary taint, defined for and used by distros
102102
17 _/T 131072 kernel was built with the struct randomization plugin
103+
18 _/N 262144 an in-kernel test has been run
103104
=== === ====== ========================================================
104105

105106
Note: The character ``_`` is representing a blank in this table to make reading

Documentation/dev-tools/kselftest.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,14 @@ assist writing kernel modules that are for use with kselftest:
275275
- ``tools/testing/selftests/kselftest_module.h``
276276
- ``tools/testing/selftests/kselftest/module.sh``
277277

278+
Note that test modules should taint the kernel with TAINT_TEST. This will
279+
happen automatically for modules which are in the ``tools/testing/``
280+
directory, or for modules which use the ``kselftest_module.h`` header above.
281+
Otherwise, you'll need to add ``MODULE_INFO(test, "Y")`` to your module
282+
source. selftests which do not load modules typically should not taint the
283+
kernel, but in cases where a non-test module is loaded, TEST_TAINT can be
284+
applied from userspace by writing to ``/proc/sys/kernel/tainted``.
285+
278286
How to use
279287
----------
280288

@@ -333,6 +341,7 @@ A bare bones test module might look like this:
333341
KSTM_MODULE_LOADERS(test_foo);
334342
MODULE_AUTHOR("John Developer <[email protected]>");
335343
MODULE_LICENSE("GPL");
344+
MODULE_INFO(test, "Y");
336345
337346
Example test script
338347
-------------------

Documentation/dev-tools/kunit/run_wrapper.rst

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ via UML. To run tests on qemu, by default it requires two flags:
192192
if we have downloaded the microblaze toolchain from the 0-day
193193
website to a directory in our home directory called toolchains.
194194

195+
This means that for most architectures, running under qemu is as simple as:
196+
197+
.. code-block:: bash
198+
199+
./tools/testing/kunit/kunit.py run --arch=x86_64
200+
201+
When cross-compiling, we'll likely need to specify a different toolchain, for
202+
example:
203+
204+
.. code-block:: bash
205+
206+
./tools/testing/kunit/kunit.py run \
207+
--arch=s390 \
208+
--cross_compile=s390x-linux-gnu-
209+
195210
If we want to run KUnit tests on an architecture not supported by
196211
the ``--arch`` flag, or want to run KUnit tests on qemu using a
197212
non-default configuration; then we can write our own``QemuConfig``.
@@ -214,14 +229,11 @@ as
214229
--jobs=12 \
215230
--qemu_config=./tools/testing/kunit/qemu_configs/x86_64.py
216231
217-
To run existing KUnit tests on non-UML architectures, see:
218-
Documentation/dev-tools/kunit/non_uml.rst.
219-
220232
Command-Line Arguments
221233
======================
222234

223235
kunit_tool has a number of other command-line arguments which can
224-
be useful for our test environment. Below the most commonly used
236+
be useful for our test environment. Below are the most commonly used
225237
command line arguments:
226238

227239
- ``--help``: Lists all available options. To list common options,
@@ -245,3 +257,64 @@ command line arguments:
245257
added or modified. Instead, enable all tests
246258
which have satisfied dependencies by adding
247259
``CONFIG_KUNIT_ALL_TESTS=y`` to your ``.kunitconfig``.
260+
261+
- ``--kunitconfig``: Specifies the path or the directory of the ``.kunitconfig``
262+
file. For example:
263+
264+
- ``lib/kunit/.kunitconfig`` can be the path of the file.
265+
266+
- ``lib/kunit`` can be the directory in which the file is located.
267+
268+
This file is used to build and run with a predefined set of tests
269+
and their dependencies. For example, to run tests for a given subsystem.
270+
271+
- ``--kconfig_add``: Specifies additional configuration options to be
272+
appended to the ``.kunitconfig`` file. For example:
273+
274+
.. code-block::
275+
276+
./tools/testing/kunit/kunit.py run --kconfig_add CONFIG_KASAN=y
277+
278+
- ``--arch``: Runs tests on the specified architecture. The architecture
279+
argument is same as the Kbuild ARCH environment variable.
280+
For example, i386, x86_64, arm, um, etc. Non-UML architectures run on qemu.
281+
Default is `um`.
282+
283+
- ``--cross_compile``: Specifies the Kbuild toolchain. It passes the
284+
same argument as passed to the ``CROSS_COMPILE`` variable used by
285+
Kbuild. This will be the prefix for the toolchain
286+
binaries such as GCC. For example:
287+
288+
- ``sparc64-linux-gnu-`` if we have the sparc toolchain installed on
289+
our system.
290+
291+
- ``$HOME/toolchains/microblaze/gcc-9.2.0-nolibc/microblaze-linux/bin/microblaze-linux``
292+
if we have downloaded the microblaze toolchain from the 0-day
293+
website to a specified path in our home directory called toolchains.
294+
295+
- ``--qemu_config``: Specifies the path to a file containing a
296+
custom qemu architecture definition. This should be a python file
297+
containing a `QemuArchParams` object.
298+
299+
- ``--qemu_args``: Specifies additional qemu arguments, for example, ``-smp 8``.
300+
301+
- ``--jobs``: Specifies the number of jobs (commands) to run simultaneously.
302+
By default, this is set to the number of cores on your system.
303+
304+
- ``--timeout``: Specifies the maximum number of seconds allowed for all tests to run.
305+
This does not include the time taken to build the tests.
306+
307+
- ``--kernel_args``: Specifies additional kernel command-line arguments. May be repeated.
308+
309+
- ``--run_isolated``: If set, boots the kernel for each individual suite/test.
310+
This is useful for debugging a non-hermetic test, one that
311+
might pass/fail based on what ran before it.
312+
313+
- ``--raw_output``: If set, generates unformatted output from kernel. Possible options are:
314+
315+
- ``all``: To view the full kernel output, use ``--raw_output=all``.
316+
317+
- ``kunit``: This is the default option and filters to KUnit output. Use ``--raw_output`` or ``--raw_output=kunit``.
318+
319+
- ``--json``: If set, stores the test results in a JSON format and prints to `stdout` or
320+
saves to a file if a filename is specified.

Documentation/dev-tools/kunit/running_tips.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ It can be handy to create a bash function like:
1515
.. code-block:: bash
1616
1717
function run_kunit() {
18-
( cd "$(git rev-parse --show-toplevel)" && ./tools/testing/kunit/kunit.py run $@ )
18+
( cd "$(git rev-parse --show-toplevel)" && ./tools/testing/kunit/kunit.py run "$@" )
1919
}
2020
2121
.. note::
@@ -123,8 +123,7 @@ Putting it together into a copy-pastable sequence of commands:
123123
.. code-block:: bash
124124
125125
# Append coverage options to the current config
126-
$ echo -e "CONFIG_DEBUG_KERNEL=y\nCONFIG_DEBUG_INFO=y\nCONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y\nCONFIG_GCOV=y" >> .kunit/.kunitconfig
127-
$ ./tools/testing/kunit/kunit.py run
126+
$ ./tools/testing/kunit/kunit.py run --kunitconfig=.kunit/ --kunitconfig=tools/testing/kunit/configs/coverage_uml.config
128127
# Extract the coverage information from the build dir (.kunit/)
129128
$ lcov -t "my_kunit_tests" -o coverage.info -c -d .kunit/
130129

Documentation/dev-tools/kunit/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ By reusing the same ``cases`` array from above, we can write the test as a
505505
const char *str;
506506
const char *sha1;
507507
};
508-
struct sha1_test_case cases[] = {
508+
const struct sha1_test_case cases[] = {
509509
{
510510
.str = "hello world",
511511
.sha1 = "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",

drivers/clk/.kunitconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ CONFIG_KUNIT=y
22
CONFIG_COMMON_CLK=y
33
CONFIG_CLK_KUNIT_TEST=y
44
CONFIG_CLK_GATE_KUNIT_TEST=y
5+
CONFIG_UML_PCI_OVER_VIRTIO=n

drivers/mmc/host/Kconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ config MMC_SDHCI_OF_ASPEED
169169
If unsure, say N.
170170

171171
config MMC_SDHCI_OF_ASPEED_TEST
172-
bool "Tests for the ASPEED SDHCI driver"
173-
depends on MMC_SDHCI_OF_ASPEED && KUNIT=y
172+
bool "Tests for the ASPEED SDHCI driver" if !KUNIT_ALL_TESTS
173+
depends on MMC_SDHCI_OF_ASPEED && KUNIT
174+
default KUNIT_ALL_TESTS
174175
help
175176
Enable KUnit tests for the ASPEED SDHCI driver. Select this
176177
option only if you will boot the kernel for the purpose of running

drivers/mmc/host/sdhci-of-aspeed-test.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,4 @@ static struct kunit_suite aspeed_sdhci_test_suite = {
9696
.test_cases = aspeed_sdhci_test_cases,
9797
};
9898

99-
static struct kunit_suite *aspeed_sdc_test_suite_array[] = {
100-
&aspeed_sdhci_test_suite,
101-
NULL,
102-
};
103-
104-
static struct kunit_suite **aspeed_sdc_test_suites
105-
__used __section(".kunit_test_suites") = aspeed_sdc_test_suite_array;
99+
kunit_test_suite(aspeed_sdhci_test_suite);

drivers/mmc/host/sdhci-of-aspeed.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -606,25 +606,6 @@ static struct platform_driver aspeed_sdc_driver = {
606606

607607
#if defined(CONFIG_MMC_SDHCI_OF_ASPEED_TEST)
608608
#include "sdhci-of-aspeed-test.c"
609-
610-
static inline int aspeed_sdc_tests_init(void)
611-
{
612-
return __kunit_test_suites_init(aspeed_sdc_test_suites);
613-
}
614-
615-
static inline void aspeed_sdc_tests_exit(void)
616-
{
617-
__kunit_test_suites_exit(aspeed_sdc_test_suites);
618-
}
619-
#else
620-
static inline int aspeed_sdc_tests_init(void)
621-
{
622-
return 0;
623-
}
624-
625-
static inline void aspeed_sdc_tests_exit(void)
626-
{
627-
}
628609
#endif
629610

630611
static int __init aspeed_sdc_init(void)
@@ -637,27 +618,14 @@ static int __init aspeed_sdc_init(void)
637618

638619
rc = platform_driver_register(&aspeed_sdc_driver);
639620
if (rc < 0)
640-
goto cleanup_sdhci;
641-
642-
rc = aspeed_sdc_tests_init();
643-
if (rc < 0) {
644-
platform_driver_unregister(&aspeed_sdc_driver);
645-
goto cleanup_sdhci;
646-
}
647-
648-
return 0;
649-
650-
cleanup_sdhci:
651-
platform_driver_unregister(&aspeed_sdhci_driver);
621+
platform_driver_unregister(&aspeed_sdhci_driver);
652622

653623
return rc;
654624
}
655625
module_init(aspeed_sdc_init);
656626

657627
static void __exit aspeed_sdc_exit(void)
658628
{
659-
aspeed_sdc_tests_exit();
660-
661629
platform_driver_unregister(&aspeed_sdc_driver);
662630
platform_driver_unregister(&aspeed_sdhci_driver);
663631
}

drivers/thunderbolt/Kconfig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ config USB4_DEBUGFS_WRITE
2828
this for production systems or distro kernels.
2929

3030
config USB4_KUNIT_TEST
31-
bool "KUnit tests"
32-
depends on KUNIT=y
31+
bool "KUnit tests" if !KUNIT_ALL_TESTS
32+
depends on (USB4=m || KUNIT=y)
33+
depends on KUNIT
34+
default KUNIT_ALL_TESTS
3335

3436
config USB4_DMA_TEST
3537
tristate "DMA traffic test driver"

0 commit comments

Comments
 (0)