Skip to content

Commit 595a56a

Browse files
committed
Merge tag 'linux-kselftest-kunit-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kunit updates from Shuah Khan: "This consists of: - Several config fragment fixes from Anders Roxell to improve test coverage. - Improvements to kunit run script to use defconfig as default and restructure the code for config/build/exec/parse from Vitor Massaru Iha and David Gow. - Miscellaneous documentation warn fix" * tag 'linux-kselftest-kunit-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: security: apparmor: default KUNIT_* fragments to KUNIT_ALL_TESTS fs: ext4: default KUNIT_* fragments to KUNIT_ALL_TESTS drivers: base: default KUNIT_* fragments to KUNIT_ALL_TESTS lib: Kconfig.debug: default KUNIT_* fragments to KUNIT_ALL_TESTS kunit: default KUNIT_* fragments to KUNIT_ALL_TESTS kunit: Kconfig: enable a KUNIT_ALL_TESTS fragment kunit: Fix TabError, remove defconfig code and handle when there is no kunitconfig kunit: use KUnit defconfig by default kunit: use --build_dir=.kunit as default Documentation: test.h - fix warnings kunit: kunit_tool: Separate out config/build/exec/parse
2 parents fc2fb38 + 6d6861d commit 595a56a

File tree

11 files changed

+351
-89
lines changed

11 files changed

+351
-89
lines changed

Documentation/dev-tools/kunit/start.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ test targets as well. The ``.kunitconfig`` should also contain any other config
3232
options required by the tests.
3333

3434
A good starting point for a ``.kunitconfig`` is the KUnit defconfig:
35+
3536
.. code-block:: bash
3637
3738
cd $PATH_TO_LINUX_REPO
3839
cp arch/um/configs/kunit_defconfig .kunitconfig
3940
4041
You can then add any other Kconfig options you wish, e.g.:
42+
4143
.. code-block:: none
4244
43-
CONFIG_LIST_KUNIT_TEST=y
45+
CONFIG_LIST_KUNIT_TEST=y
4446
4547
:doc:`kunit_tool <kunit-tool>` will ensure that all config options set in
4648
``.kunitconfig`` are set in the kernel ``.config`` before running the tests.
@@ -54,8 +56,8 @@ using.
5456
other tools (such as make menuconfig) to adjust other config options.
5557

5658

57-
Running the tests
58-
-----------------
59+
Running the tests (KUnit Wrapper)
60+
---------------------------------
5961

6062
To make sure that everything is set up correctly, simply invoke the Python
6163
wrapper from your kernel repo:
@@ -105,8 +107,9 @@ have config options ending in ``_KUNIT_TEST``.
105107
KUnit and KUnit tests can be compiled as modules: in this case the tests in a
106108
module will be run when the module is loaded.
107109

108-
Running the tests
109-
-----------------
110+
111+
Running the tests (w/o KUnit Wrapper)
112+
-------------------------------------
110113

111114
Build and run your kernel as usual. Test output will be written to the kernel
112115
log in `TAP <https://testanything.org/>`_ format.

Documentation/dev-tools/kunit/usage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ able to run one test case per invocation.
595595
KUnit debugfs representation
596596
============================
597597
When kunit test suites are initialized, they create an associated directory
598-
in /sys/kernel/debug/kunit/<test-suite>. The directory contains one file
598+
in ``/sys/kernel/debug/kunit/<test-suite>``. The directory contains one file
599599

600600
- results: "cat results" displays results of each test case and the results
601601
of the entire suite for the last test run.
@@ -604,4 +604,4 @@ The debugfs representation is primarily of use when kunit test suites are
604604
run in a native environment, either as modules or builtin. Having a way
605605
to display results like this is valuable as otherwise results can be
606606
intermixed with other events in dmesg output. The maximum size of each
607-
results file is KUNIT_LOG_SIZE bytes (defined in include/kunit/test.h).
607+
results file is KUNIT_LOG_SIZE bytes (defined in ``include/kunit/test.h``).

drivers/base/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ config DEBUG_TEST_DRIVER_REMOVE
149149
test this functionality.
150150

151151
config PM_QOS_KUNIT_TEST
152-
bool "KUnit Test for PM QoS features"
152+
bool "KUnit Test for PM QoS features" if !KUNIT_ALL_TESTS
153153
depends on KUNIT=y
154+
default KUNIT_ALL_TESTS
154155

155156
config HMEM_REPORTING
156157
bool

drivers/base/test/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ config TEST_ASYNC_DRIVER_PROBE
99

1010
If unsure say N.
1111
config KUNIT_DRIVER_PE_TEST
12-
bool "KUnit Tests for property entry API"
12+
bool "KUnit Tests for property entry API" if !KUNIT_ALL_TESTS
1313
depends on KUNIT=y
14+
default KUNIT_ALL_TESTS

fs/ext4/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ config EXT4_DEBUG
102102
using dynamic debug control for mb_debug() / ext_debug() msgs.
103103

104104
config EXT4_KUNIT_TESTS
105-
tristate "KUnit tests for ext4"
105+
tristate "KUnit tests for ext4" if !KUNIT_ALL_TESTS
106106
select EXT4_FS
107107
depends on KUNIT
108+
default KUNIT_ALL_TESTS
108109
help
109110
This builds the ext4 KUnit tests.
110111

include/kunit/test.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ struct kunit_suite {
175175
void (*exit)(struct kunit *test);
176176
struct kunit_case *test_cases;
177177

178-
/* private - internal use only */
178+
/* private: internal use only */
179179
struct dentry *debugfs;
180180
char *log;
181181
};
@@ -232,12 +232,12 @@ void __kunit_test_suites_exit(struct kunit_suite **suites);
232232
* kunit_test_suites() - used to register one or more &struct kunit_suite
233233
* with KUnit.
234234
*
235-
* @suites: a statically allocated list of &struct kunit_suite.
235+
* @suites_list...: a statically allocated list of &struct kunit_suite.
236236
*
237-
* Registers @suites with the test framework. See &struct kunit_suite for
237+
* Registers @suites_list with the test framework. See &struct kunit_suite for
238238
* more information.
239239
*
240-
* When builtin, KUnit tests are all run as late_initcalls; this means
240+
* When builtin, KUnit tests are all run as late_initcalls; this means
241241
* that they cannot test anything where tests must run at a different init
242242
* phase. One significant restriction resulting from this is that KUnit
243243
* cannot reliably test anything that is initialize in the late_init phase;
@@ -253,8 +253,8 @@ void __kunit_test_suites_exit(struct kunit_suite **suites);
253253
* tests from the same place, and at the very least to do so after
254254
* everything else is definitely initialized.
255255
*/
256-
#define kunit_test_suites(...) \
257-
static struct kunit_suite *suites[] = { __VA_ARGS__, NULL}; \
256+
#define kunit_test_suites(suites_list...) \
257+
static struct kunit_suite *suites[] = {suites_list, NULL}; \
258258
static int kunit_test_suites_init(void) \
259259
{ \
260260
return __kunit_test_suites_init(suites); \

lib/Kconfig.debug

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,8 +2142,9 @@ config TEST_SYSCTL
21422142
If unsure, say N.
21432143

21442144
config SYSCTL_KUNIT_TEST
2145-
tristate "KUnit test for sysctl"
2145+
tristate "KUnit test for sysctl" if !KUNIT_ALL_TESTS
21462146
depends on KUNIT
2147+
default KUNIT_ALL_TESTS
21472148
help
21482149
This builds the proc sysctl unit test, which runs on boot.
21492150
Tests the API contract and implementation correctness of sysctl.
@@ -2153,8 +2154,9 @@ config SYSCTL_KUNIT_TEST
21532154
If unsure, say N.
21542155

21552156
config LIST_KUNIT_TEST
2156-
tristate "KUnit Test for Kernel Linked-list structures"
2157+
tristate "KUnit Test for Kernel Linked-list structures" if !KUNIT_ALL_TESTS
21572158
depends on KUNIT
2159+
default KUNIT_ALL_TESTS
21582160
help
21592161
This builds the linked list KUnit test suite.
21602162
It tests that the API and basic functionality of the list_head type

lib/kunit/Kconfig

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ menuconfig KUNIT
1515
if KUNIT
1616

1717
config KUNIT_DEBUGFS
18-
bool "KUnit - Enable /sys/kernel/debug/kunit debugfs representation"
18+
bool "KUnit - Enable /sys/kernel/debug/kunit debugfs representation" if !KUNIT_ALL_TESTS
19+
default KUNIT_ALL_TESTS
1920
help
2021
Enable debugfs representation for kunit. Currently this consists
2122
of /sys/kernel/debug/kunit/<test_suite>/results files for each
2223
test suite, which allow users to see results of the last test suite
2324
run that occurred.
2425

2526
config KUNIT_TEST
26-
tristate "KUnit test for KUnit"
27+
tristate "KUnit test for KUnit" if !KUNIT_ALL_TESTS
28+
default KUNIT_ALL_TESTS
2729
help
2830
Enables the unit tests for the KUnit test framework. These tests test
2931
the KUnit test framework itself; the tests are both written using
@@ -32,7 +34,8 @@ config KUNIT_TEST
3234
expected.
3335

3436
config KUNIT_EXAMPLE_TEST
35-
tristate "Example test for KUnit"
37+
tristate "Example test for KUnit" if !KUNIT_ALL_TESTS
38+
default KUNIT_ALL_TESTS
3639
help
3740
Enables an example unit test that illustrates some of the basic
3841
features of KUnit. This test only exists to help new users understand
@@ -41,4 +44,18 @@ config KUNIT_EXAMPLE_TEST
4144
is intended for curious hackers who would like to understand how to
4245
use KUnit for kernel development.
4346

47+
config KUNIT_ALL_TESTS
48+
tristate "All KUnit tests with satisfied dependencies"
49+
help
50+
Enables all KUnit tests, if they can be enabled.
51+
KUnit tests run during boot and output the results to the debug log
52+
in TAP format (http://testanything.org/). Only useful for kernel devs
53+
running the KUnit test harness, and not intended for inclusion into a
54+
production build.
55+
56+
For more information on KUnit and unit tests in general please refer
57+
to the KUnit documentation in Documentation/dev-tools/kunit/.
58+
59+
If unsure, say N.
60+
4461
endif # KUNIT

security/apparmor/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ config SECURITY_APPARMOR_DEBUG_MESSAGES
7070
the kernel message buffer.
7171

7272
config SECURITY_APPARMOR_KUNIT_TEST
73-
bool "Build KUnit tests for policy_unpack.c"
73+
bool "Build KUnit tests for policy_unpack.c" if !KUNIT_ALL_TESTS
7474
depends on KUNIT=y && SECURITY_APPARMOR
75+
default KUNIT_ALL_TESTS
7576
help
7677
This builds the AppArmor KUnit tests.
7778

0 commit comments

Comments
 (0)