Commit 521b619a authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-kunit-fixes-5.10-rc3' of...

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
parents 3249fe45 0d0d2451
...@@ -197,7 +197,7 @@ Now add the following to ``drivers/misc/Kconfig``: ...@@ -197,7 +197,7 @@ Now add the following to ``drivers/misc/Kconfig``:
config MISC_EXAMPLE_TEST config MISC_EXAMPLE_TEST
bool "Test for my example" bool "Test for my example"
depends on MISC_EXAMPLE && KUNIT depends on MISC_EXAMPLE && KUNIT=y
and the following to ``drivers/misc/Makefile``: and the following to ``drivers/misc/Makefile``:
......
...@@ -561,6 +561,11 @@ Once the kernel is built and installed, a simple ...@@ -561,6 +561,11 @@ Once the kernel is built and installed, a simple
...will run the tests. ...will run the tests.
.. note::
Note that you should make sure your test depends on ``KUNIT=y`` in Kconfig
if the test does not support module build. Otherwise, it will trigger
compile errors if ``CONFIG_KUNIT`` is ``m``.
Writing new tests for other architectures Writing new tests for other architectures
----------------------------------------- -----------------------------------------
......
...@@ -252,13 +252,14 @@ static inline int kunit_run_all_tests(void) ...@@ -252,13 +252,14 @@ static inline int kunit_run_all_tests(void)
} }
#endif /* IS_BUILTIN(CONFIG_KUNIT) */ #endif /* IS_BUILTIN(CONFIG_KUNIT) */
#ifdef MODULE
/** /**
* kunit_test_suites() - used to register one or more &struct kunit_suite * kunit_test_suites_for_module() - used to register one or more
* with KUnit. * &struct kunit_suite with KUnit.
* *
* @suites_list...: a statically allocated list of &struct kunit_suite. * @__suites: a statically allocated list of &struct kunit_suite.
* *
* Registers @suites_list with the test framework. See &struct kunit_suite for * Registers @__suites with the test framework. See &struct kunit_suite for
* more information. * more information.
* *
* If a test suite is built-in, module_init() gets translated into * If a test suite is built-in, module_init() gets translated into
...@@ -267,7 +268,6 @@ static inline int kunit_run_all_tests(void) ...@@ -267,7 +268,6 @@ static inline int kunit_run_all_tests(void)
* module_{init|exit} functions for the builtin case when registering * module_{init|exit} functions for the builtin case when registering
* suites via kunit_test_suites() below. * suites via kunit_test_suites() below.
*/ */
#ifdef MODULE
#define kunit_test_suites_for_module(__suites) \ #define kunit_test_suites_for_module(__suites) \
static int __init kunit_test_suites_init(void) \ static int __init kunit_test_suites_init(void) \
{ \ { \
...@@ -294,7 +294,7 @@ static inline int kunit_run_all_tests(void) ...@@ -294,7 +294,7 @@ static inline int kunit_run_all_tests(void)
* kunit_test_suites() - used to register one or more &struct kunit_suite * kunit_test_suites() - used to register one or more &struct kunit_suite
* with KUnit. * with KUnit.
* *
* @suites: a statically allocated list of &struct kunit_suite. * @__suites: a statically allocated list of &struct kunit_suite.
* *
* Registers @suites with the test framework. See &struct kunit_suite for * Registers @suites with the test framework. See &struct kunit_suite for
* more information. * more information.
...@@ -308,10 +308,10 @@ static inline int kunit_run_all_tests(void) ...@@ -308,10 +308,10 @@ static inline int kunit_run_all_tests(void)
* module. * module.
* *
*/ */
#define kunit_test_suites(...) \ #define kunit_test_suites(__suites...) \
__kunit_test_suites(__UNIQUE_ID(array), \ __kunit_test_suites(__UNIQUE_ID(array), \
__UNIQUE_ID(suites), \ __UNIQUE_ID(suites), \
__VA_ARGS__) ##__suites)
#define kunit_test_suite(suite) kunit_test_suites(&suite) #define kunit_test_suite(suite) kunit_test_suites(&suite)
......
...@@ -66,7 +66,6 @@ def isolate_kunit_output(kernel_output): ...@@ -66,7 +66,6 @@ def isolate_kunit_output(kernel_output):
def raw_output(kernel_output): def raw_output(kernel_output):
for line in kernel_output: for line in kernel_output:
print(line) print(line)
yield line
DIVIDER = '=' * 60 DIVIDER = '=' * 60
...@@ -242,7 +241,7 @@ def parse_test_suite(lines: List[str], expected_suite_index: int) -> TestSuite: ...@@ -242,7 +241,7 @@ def parse_test_suite(lines: List[str], expected_suite_index: int) -> TestSuite:
return None return None
test_suite.name = name test_suite.name = name
expected_test_case_num = parse_subtest_plan(lines) expected_test_case_num = parse_subtest_plan(lines)
if not expected_test_case_num: if expected_test_case_num is None:
return None return None
while expected_test_case_num > 0: while expected_test_case_num > 0:
test_case = parse_test_case(lines) test_case = parse_test_case(lines)
......
...@@ -179,7 +179,7 @@ class KUnitParserTest(unittest.TestCase): ...@@ -179,7 +179,7 @@ class KUnitParserTest(unittest.TestCase):
print_mock = mock.patch('builtins.print').start() print_mock = mock.patch('builtins.print').start()
result = kunit_parser.parse_run_tests( result = kunit_parser.parse_run_tests(
kunit_parser.isolate_kunit_output(file.readlines())) kunit_parser.isolate_kunit_output(file.readlines()))
print_mock.assert_any_call(StrContains("no kunit output detected")) print_mock.assert_any_call(StrContains('no tests run!'))
print_mock.stop() print_mock.stop()
file.close() file.close()
...@@ -198,6 +198,9 @@ class KUnitParserTest(unittest.TestCase): ...@@ -198,6 +198,9 @@ class KUnitParserTest(unittest.TestCase):
'test_data/test_config_printk_time.log') 'test_data/test_config_printk_time.log')
with open(prefix_log) as file: with open(prefix_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual(
kunit_parser.TestStatus.SUCCESS,
result.status)
self.assertEqual('kunit-resource-test', result.suites[0].name) self.assertEqual('kunit-resource-test', result.suites[0].name)
def test_ignores_multiple_prefixes(self): def test_ignores_multiple_prefixes(self):
...@@ -205,6 +208,9 @@ class KUnitParserTest(unittest.TestCase): ...@@ -205,6 +208,9 @@ class KUnitParserTest(unittest.TestCase):
'test_data/test_multiple_prefixes.log') 'test_data/test_multiple_prefixes.log')
with open(prefix_log) as file: with open(prefix_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual(
kunit_parser.TestStatus.SUCCESS,
result.status)
self.assertEqual('kunit-resource-test', result.suites[0].name) self.assertEqual('kunit-resource-test', result.suites[0].name)
def test_prefix_mixed_kernel_output(self): def test_prefix_mixed_kernel_output(self):
...@@ -212,24 +218,36 @@ class KUnitParserTest(unittest.TestCase): ...@@ -212,24 +218,36 @@ class KUnitParserTest(unittest.TestCase):
'test_data/test_interrupted_tap_output.log') 'test_data/test_interrupted_tap_output.log')
with open(mixed_prefix_log) as file: with open(mixed_prefix_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual(
kunit_parser.TestStatus.SUCCESS,
result.status)
self.assertEqual('kunit-resource-test', result.suites[0].name) self.assertEqual('kunit-resource-test', result.suites[0].name)
def test_prefix_poundsign(self): def test_prefix_poundsign(self):
pound_log = get_absolute_path('test_data/test_pound_sign.log') pound_log = get_absolute_path('test_data/test_pound_sign.log')
with open(pound_log) as file: with open(pound_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual(
kunit_parser.TestStatus.SUCCESS,
result.status)
self.assertEqual('kunit-resource-test', result.suites[0].name) self.assertEqual('kunit-resource-test', result.suites[0].name)
def test_kernel_panic_end(self): def test_kernel_panic_end(self):
panic_log = get_absolute_path('test_data/test_kernel_panic_interrupt.log') panic_log = get_absolute_path('test_data/test_kernel_panic_interrupt.log')
with open(panic_log) as file: with open(panic_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual(
kunit_parser.TestStatus.TEST_CRASHED,
result.status)
self.assertEqual('kunit-resource-test', result.suites[0].name) self.assertEqual('kunit-resource-test', result.suites[0].name)
def test_pound_no_prefix(self): def test_pound_no_prefix(self):
pound_log = get_absolute_path('test_data/test_pound_no_prefix.log') pound_log = get_absolute_path('test_data/test_pound_no_prefix.log')
with open(pound_log) as file: with open(pound_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual(
kunit_parser.TestStatus.SUCCESS,
result.status)
self.assertEqual('kunit-resource-test', result.suites[0].name) self.assertEqual('kunit-resource-test', result.suites[0].name)
class KUnitJsonTest(unittest.TestCase): class KUnitJsonTest(unittest.TestCase):
......
[ 0.060000] printk: console [mc-1] enabled [ 0.060000] printk: console [mc-1] enabled
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0 [ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000] TAP version 14 [ 0.060000] TAP version 14
[ 0.060000] 1..3
[ 0.060000] # Subtest: kunit-resource-test [ 0.060000] # Subtest: kunit-resource-test
[ 0.060000] 1..5 [ 0.060000] 1..5
[ 0.060000] ok 1 - kunit_resource_test_init_resources [ 0.060000] ok 1 - kunit_resource_test_init_resources
......
[ 0.060000] printk: console [mc-1] enabled [ 0.060000] printk: console [mc-1] enabled
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0 [ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000] TAP version 14 [ 0.060000] TAP version 14
[ 0.060000] 1..3
[ 0.060000] # Subtest: kunit-resource-test [ 0.060000] # Subtest: kunit-resource-test
[ 0.060000] 1..5 [ 0.060000] 1..5
[ 0.060000] ok 1 - kunit_resource_test_init_resources [ 0.060000] ok 1 - kunit_resource_test_init_resources
......
[ 0.060000] printk: console [mc-1] enabled [ 0.060000] printk: console [mc-1] enabled
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0 [ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000] TAP version 14 [ 0.060000] TAP version 14
[ 0.060000] 1..3
[ 0.060000] # Subtest: kunit-resource-test [ 0.060000] # Subtest: kunit-resource-test
[ 0.060000] 1..5 [ 0.060000] 1..5
[ 0.060000] ok 1 - kunit_resource_test_init_resources [ 0.060000] ok 1 - kunit_resource_test_init_resources
......
[ 0.060000][ T1] printk: console [mc-1] enabled [ 0.060000][ T1] printk: console [mc-1] enabled
[ 0.060000][ T1] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0 [ 0.060000][ T1] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000][ T1] TAP version 14 [ 0.060000][ T1] TAP version 14
[ 0.060000][ T1] 1..3
[ 0.060000][ T1] # Subtest: kunit-resource-test [ 0.060000][ T1] # Subtest: kunit-resource-test
[ 0.060000][ T1] 1..5 [ 0.060000][ T1] 1..5
[ 0.060000][ T1] ok 1 - kunit_resource_test_init_resources [ 0.060000][ T1] ok 1 - kunit_resource_test_init_resources
......
printk: console [mc-1] enabled printk: console [mc-1] enabled
random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0 random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
TAP version 14 TAP version 14
1..3
# Subtest: kunit-resource-test # Subtest: kunit-resource-test
1..5 1..5
ok 1 - kunit_resource_test_init_resources ok 1 - kunit_resource_test_init_resources
......
[ 0.060000] printk: console [mc-1] enabled [ 0.060000] printk: console [mc-1] enabled
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0 [ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000] TAP version 14 [ 0.060000] TAP version 14
[ 0.060000] 1..3
[ 0.060000] # Subtest: kunit-resource-test [ 0.060000] # Subtest: kunit-resource-test
[ 0.060000] 1..5 [ 0.060000] 1..5
[ 0.060000] ok 1 - kunit_resource_test_init_resources [ 0.060000] ok 1 - kunit_resource_test_init_resources
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment