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

Configure Feed

Select the types of activity you want to include in your feed.

kunit: Add --list_suites to show suites

Currently, kunit.py allows listing all individual tests via --list_tests.
However, users often need to see only the available test suites.

Add --list_suites to show suites. This option parses the test list output
from the kernel and prints only the suite names.

Example of the output of --list_suites:
example_init
miscdev_init
printk-ringbuffer

Signed-off-by: Ryota Sakamoto <sakamo.ryota@gmail.com>
Reviewed-by: David Gow <david@davidgow.net>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Ryota Sakamoto and committed by
Shuah Khan
b5f92fc4 591cd656

+27 -5
+14 -2
tools/testing/kunit/kunit.py
··· 63 63 run_isolated: Optional[str] 64 64 list_tests: bool 65 65 list_tests_attr: bool 66 + list_suites: bool 66 67 67 68 @dataclass 68 69 class KunitRequest(KunitExecRequest, KunitBuildRequest): ··· 167 166 if request.list_tests_attr: 168 167 attr_output = _list_tests_attr(linux, request) 169 168 for line in attr_output: 169 + print(line.rstrip()) 170 + return KunitResult(status=KunitStatus.SUCCESS, elapsed_time=0.0) 171 + if request.list_suites: 172 + tests = _list_tests(linux, request) 173 + output = _suites_from_test_list(tests) 174 + for line in output: 170 175 print(line.rstrip()) 171 176 return KunitResult(status=KunitStatus.SUCCESS, elapsed_time=0.0) 172 177 if request.run_isolated: ··· 445 438 parser.add_argument('--list_tests_attr', help='If set, list all tests and test ' 446 439 'attributes.', 447 440 action='store_true') 441 + parser.add_argument('--list_suites', help='If set, list all suites that will be ' 442 + 'run.', 443 + action='store_true') 448 444 449 445 def add_parse_opts(parser: argparse.ArgumentParser) -> None: 450 446 parser.add_argument('--raw_output', help='If set don\'t parse output from kernel. ' ··· 511 501 kernel_args=cli_args.kernel_args, 512 502 run_isolated=cli_args.run_isolated, 513 503 list_tests=cli_args.list_tests, 514 - list_tests_attr=cli_args.list_tests_attr) 504 + list_tests_attr=cli_args.list_tests_attr, 505 + list_suites=cli_args.list_suites) 515 506 result = run_tests(linux, request) 516 507 if result.status != KunitStatus.SUCCESS: 517 508 sys.exit(1) ··· 561 550 kernel_args=cli_args.kernel_args, 562 551 run_isolated=cli_args.run_isolated, 563 552 list_tests=cli_args.list_tests, 564 - list_tests_attr=cli_args.list_tests_attr) 553 + list_tests_attr=cli_args.list_tests_attr, 554 + list_suites=cli_args.list_suites) 565 555 result = exec_tests(linux, exec_request) 566 556 stdout.print_with_timestamp(( 567 557 'Elapsed time: %.3fs\n') % (result.elapsed_time))
+13 -3
tools/testing/kunit/kunit_tool_test.py
··· 881 881 self.linux_source_mock.run_kernel.return_value = ['TAP version 14', 'init: random output'] + want 882 882 883 883 got = kunit._list_tests(self.linux_source_mock, 884 - kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*', '', None, None, 'suite', False, False)) 884 + kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*', '', None, None, 'suite', False, False, False)) 885 885 self.assertEqual(got, want) 886 886 # Should respect the user's filter glob when listing tests. 887 887 self.linux_source_mock.run_kernel.assert_called_once_with( ··· 894 894 895 895 # Should respect the user's filter glob when listing tests. 896 896 mock_tests.assert_called_once_with(mock.ANY, 897 - kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*.test*', '', None, None, 'suite', False, False)) 897 + kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*.test*', '', None, None, 'suite', False, False, False)) 898 898 self.linux_source_mock.run_kernel.assert_has_calls([ 899 899 mock.call(args=None, build_dir='.kunit', filter_glob='suite.test*', filter='', filter_action=None, timeout=300), 900 900 mock.call(args=None, build_dir='.kunit', filter_glob='suite2.test*', filter='', filter_action=None, timeout=300), ··· 907 907 908 908 # Should respect the user's filter glob when listing tests. 909 909 mock_tests.assert_called_once_with(mock.ANY, 910 - kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*', '', None, None, 'test', False, False)) 910 + kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*', '', None, None, 'test', False, False, False)) 911 911 self.linux_source_mock.run_kernel.assert_has_calls([ 912 912 mock.call(args=None, build_dir='.kunit', filter_glob='suite.test1', filter='', filter_action=None, timeout=300), 913 913 mock.call(args=None, build_dir='.kunit', filter_glob='suite.test2', filter='', filter_action=None, timeout=300), 914 914 mock.call(args=None, build_dir='.kunit', filter_glob='suite2.test1', filter='', filter_action=None, timeout=300), 915 915 ]) 916 + 917 + @mock.patch.object(kunit, '_list_tests') 918 + @mock.patch.object(sys, 'stdout', new_callable=io.StringIO) 919 + def test_list_suites(self, mock_stdout, mock_tests): 920 + mock_tests.return_value = ['suite.test1', 'suite.test2', 'suite2.test1'] 921 + kunit.main(['run', '--list_suites']) 922 + 923 + want = ['suite', 'suite2'] 924 + output = mock_stdout.getvalue().split() 925 + self.assertEqual(output, want) 916 926 917 927 @mock.patch.object(sys, 'stdout', new_callable=io.StringIO) 918 928 def test_list_cmds(self, mock_stdout):