Skip to content

Commit 521b619

Browse files
committed
Merge tag 'linux-kselftest-kunit-fixes-5.10-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kunit fixes from Shuah Khan: "Several kunit_tool and documentation fixes" * tag 'linux-kselftest-kunit-fixes-5.10-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kunit: tools: fix kunit_tool tests for parsing test plans Documentation: kunit: Update Kconfig parts for KUNIT's module support kunit: test: fix remaining kernel-doc warnings kunit: Don't fail test suites if one of them is empty kunit: Fix kunit.py --raw_output option
2 parents 3249fe4 + 0d0d245 commit 521b619

File tree

11 files changed

+51
-23
lines changed

11 files changed

+51
-23
lines changed

Documentation/dev-tools/kunit/start.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Now add the following to ``drivers/misc/Kconfig``:
197197
198198
config MISC_EXAMPLE_TEST
199199
bool "Test for my example"
200-
depends on MISC_EXAMPLE && KUNIT
200+
depends on MISC_EXAMPLE && KUNIT=y
201201
202202
and the following to ``drivers/misc/Makefile``:
203203

Documentation/dev-tools/kunit/usage.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ Once the kernel is built and installed, a simple
561561
562562
...will run the tests.
563563

564+
.. note::
565+
Note that you should make sure your test depends on ``KUNIT=y`` in Kconfig
566+
if the test does not support module build. Otherwise, it will trigger
567+
compile errors if ``CONFIG_KUNIT`` is ``m``.
568+
564569
Writing new tests for other architectures
565570
-----------------------------------------
566571

include/kunit/test.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,14 @@ static inline int kunit_run_all_tests(void)
252252
}
253253
#endif /* IS_BUILTIN(CONFIG_KUNIT) */
254254

255+
#ifdef MODULE
255256
/**
256-
* kunit_test_suites() - used to register one or more &struct kunit_suite
257-
* with KUnit.
257+
* kunit_test_suites_for_module() - used to register one or more
258+
* &struct kunit_suite with KUnit.
258259
*
259-
* @suites_list...: a statically allocated list of &struct kunit_suite.
260+
* @__suites: a statically allocated list of &struct kunit_suite.
260261
*
261-
* Registers @suites_list with the test framework. See &struct kunit_suite for
262+
* Registers @__suites with the test framework. See &struct kunit_suite for
262263
* more information.
263264
*
264265
* If a test suite is built-in, module_init() gets translated into
@@ -267,7 +268,6 @@ static inline int kunit_run_all_tests(void)
267268
* module_{init|exit} functions for the builtin case when registering
268269
* suites via kunit_test_suites() below.
269270
*/
270-
#ifdef MODULE
271271
#define kunit_test_suites_for_module(__suites) \
272272
static int __init kunit_test_suites_init(void) \
273273
{ \
@@ -294,7 +294,7 @@ static inline int kunit_run_all_tests(void)
294294
* kunit_test_suites() - used to register one or more &struct kunit_suite
295295
* with KUnit.
296296
*
297-
* @suites: a statically allocated list of &struct kunit_suite.
297+
* @__suites: a statically allocated list of &struct kunit_suite.
298298
*
299299
* Registers @suites with the test framework. See &struct kunit_suite for
300300
* more information.
@@ -308,10 +308,10 @@ static inline int kunit_run_all_tests(void)
308308
* module.
309309
*
310310
*/
311-
#define kunit_test_suites(...) \
311+
#define kunit_test_suites(__suites...) \
312312
__kunit_test_suites(__UNIQUE_ID(array), \
313313
__UNIQUE_ID(suites), \
314-
__VA_ARGS__)
314+
##__suites)
315315

316316
#define kunit_test_suite(suite) kunit_test_suites(&suite)
317317

tools/testing/kunit/kunit_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def isolate_kunit_output(kernel_output):
6666
def raw_output(kernel_output):
6767
for line in kernel_output:
6868
print(line)
69-
yield line
7069

7170
DIVIDER = '=' * 60
7271

@@ -242,7 +241,7 @@ def parse_test_suite(lines: List[str], expected_suite_index: int) -> TestSuite:
242241
return None
243242
test_suite.name = name
244243
expected_test_case_num = parse_subtest_plan(lines)
245-
if not expected_test_case_num:
244+
if expected_test_case_num is None:
246245
return None
247246
while expected_test_case_num > 0:
248247
test_case = parse_test_case(lines)

tools/testing/kunit/kunit_tool_test.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_no_kunit_output(self):
179179
print_mock = mock.patch('builtins.print').start()
180180
result = kunit_parser.parse_run_tests(
181181
kunit_parser.isolate_kunit_output(file.readlines()))
182-
print_mock.assert_any_call(StrContains("no kunit output detected"))
182+
print_mock.assert_any_call(StrContains('no tests run!'))
183183
print_mock.stop()
184184
file.close()
185185

@@ -198,39 +198,57 @@ def test_ignores_prefix_printk_time(self):
198198
'test_data/test_config_printk_time.log')
199199
with open(prefix_log) as file:
200200
result = kunit_parser.parse_run_tests(file.readlines())
201-
self.assertEqual('kunit-resource-test', result.suites[0].name)
201+
self.assertEqual(
202+
kunit_parser.TestStatus.SUCCESS,
203+
result.status)
204+
self.assertEqual('kunit-resource-test', result.suites[0].name)
202205

203206
def test_ignores_multiple_prefixes(self):
204207
prefix_log = get_absolute_path(
205208
'test_data/test_multiple_prefixes.log')
206209
with open(prefix_log) as file:
207210
result = kunit_parser.parse_run_tests(file.readlines())
208-
self.assertEqual('kunit-resource-test', result.suites[0].name)
211+
self.assertEqual(
212+
kunit_parser.TestStatus.SUCCESS,
213+
result.status)
214+
self.assertEqual('kunit-resource-test', result.suites[0].name)
209215

210216
def test_prefix_mixed_kernel_output(self):
211217
mixed_prefix_log = get_absolute_path(
212218
'test_data/test_interrupted_tap_output.log')
213219
with open(mixed_prefix_log) as file:
214220
result = kunit_parser.parse_run_tests(file.readlines())
215-
self.assertEqual('kunit-resource-test', result.suites[0].name)
221+
self.assertEqual(
222+
kunit_parser.TestStatus.SUCCESS,
223+
result.status)
224+
self.assertEqual('kunit-resource-test', result.suites[0].name)
216225

217226
def test_prefix_poundsign(self):
218227
pound_log = get_absolute_path('test_data/test_pound_sign.log')
219228
with open(pound_log) as file:
220229
result = kunit_parser.parse_run_tests(file.readlines())
221-
self.assertEqual('kunit-resource-test', result.suites[0].name)
230+
self.assertEqual(
231+
kunit_parser.TestStatus.SUCCESS,
232+
result.status)
233+
self.assertEqual('kunit-resource-test', result.suites[0].name)
222234

223235
def test_kernel_panic_end(self):
224236
panic_log = get_absolute_path('test_data/test_kernel_panic_interrupt.log')
225237
with open(panic_log) as file:
226238
result = kunit_parser.parse_run_tests(file.readlines())
227-
self.assertEqual('kunit-resource-test', result.suites[0].name)
239+
self.assertEqual(
240+
kunit_parser.TestStatus.TEST_CRASHED,
241+
result.status)
242+
self.assertEqual('kunit-resource-test', result.suites[0].name)
228243

229244
def test_pound_no_prefix(self):
230245
pound_log = get_absolute_path('test_data/test_pound_no_prefix.log')
231246
with open(pound_log) as file:
232247
result = kunit_parser.parse_run_tests(file.readlines())
233-
self.assertEqual('kunit-resource-test', result.suites[0].name)
248+
self.assertEqual(
249+
kunit_parser.TestStatus.SUCCESS,
250+
result.status)
251+
self.assertEqual('kunit-resource-test', result.suites[0].name)
234252

235253
class KUnitJsonTest(unittest.TestCase):
236254

tools/testing/kunit/test_data/test_config_printk_time.log

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[ 0.060000] printk: console [mc-1] enabled
22
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
33
[ 0.060000] TAP version 14
4+
[ 0.060000] 1..3
45
[ 0.060000] # Subtest: kunit-resource-test
56
[ 0.060000] 1..5
67
[ 0.060000] ok 1 - kunit_resource_test_init_resources
@@ -28,4 +29,4 @@
2829
[ 0.060000] Stack:
2930
[ 0.060000] 602086f8 601bc260 705c0000 705c0000
3031
[ 0.060000] 602086f8 6005fcec 705c0000 6002c6ab
31-
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010
32+
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010

tools/testing/kunit/test_data/test_interrupted_tap_output.log

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[ 0.060000] printk: console [mc-1] enabled
22
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
33
[ 0.060000] TAP version 14
4+
[ 0.060000] 1..3
45
[ 0.060000] # Subtest: kunit-resource-test
56
[ 0.060000] 1..5
67
[ 0.060000] ok 1 - kunit_resource_test_init_resources
@@ -34,4 +35,4 @@
3435
[ 0.060000] Stack:
3536
[ 0.060000] 602086f8 601bc260 705c0000 705c0000
3637
[ 0.060000] 602086f8 6005fcec 705c0000 6002c6ab
37-
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010
38+
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010

tools/testing/kunit/test_data/test_kernel_panic_interrupt.log

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[ 0.060000] printk: console [mc-1] enabled
22
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
33
[ 0.060000] TAP version 14
4+
[ 0.060000] 1..3
45
[ 0.060000] # Subtest: kunit-resource-test
56
[ 0.060000] 1..5
67
[ 0.060000] ok 1 - kunit_resource_test_init_resources
@@ -22,4 +23,4 @@
2223
[ 0.060000] Stack:
2324
[ 0.060000] 602086f8 601bc260 705c0000 705c0000
2425
[ 0.060000] 602086f8 6005fcec 705c0000 6002c6ab
25-
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010
26+
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010

tools/testing/kunit/test_data/test_multiple_prefixes.log

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[ 0.060000][ T1] printk: console [mc-1] enabled
22
[ 0.060000][ T1] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
33
[ 0.060000][ T1] TAP version 14
4+
[ 0.060000][ T1] 1..3
45
[ 0.060000][ T1] # Subtest: kunit-resource-test
56
[ 0.060000][ T1] 1..5
67
[ 0.060000][ T1] ok 1 - kunit_resource_test_init_resources
@@ -28,4 +29,4 @@
2829
[ 0.060000][ T1] Stack:
2930
[ 0.060000][ T1] 602086f8 601bc260 705c0000 705c0000
3031
[ 0.060000][ T1] 602086f8 6005fcec 705c0000 6002c6ab
31-
[ 0.060000][ T1] 6005fcec 601bc260 705c0000 3000000010
32+
[ 0.060000][ T1] 6005fcec 601bc260 705c0000 3000000010

tools/testing/kunit/test_data/test_pound_no_prefix.log

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
printk: console [mc-1] enabled
22
random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
33
TAP version 14
4+
1..3
45
# Subtest: kunit-resource-test
56
1..5
67
ok 1 - kunit_resource_test_init_resources
@@ -30,4 +31,4 @@
3031
Stack:
3132
602086f8 601bc260 705c0000 705c0000
3233
602086f8 6005fcec 705c0000 6002c6ab
33-
6005fcec 601bc260 705c0000 3000000010
34+
6005fcec 601bc260 705c0000 3000000010

tools/testing/kunit/test_data/test_pound_sign.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[ 0.060000] printk: console [mc-1] enabled
22
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
33
[ 0.060000] TAP version 14
4+
[ 0.060000] 1..3
45
[ 0.060000] # Subtest: kunit-resource-test
56
[ 0.060000] 1..5
67
[ 0.060000] ok 1 - kunit_resource_test_init_resources

0 commit comments

Comments
 (0)