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>master
parent
591cd656a1
commit
b5f92fc4a7
|
|
@ -63,6 +63,7 @@ class KunitExecRequest(KunitParseRequest):
|
|||
run_isolated: Optional[str]
|
||||
list_tests: bool
|
||||
list_tests_attr: bool
|
||||
list_suites: bool
|
||||
|
||||
@dataclass
|
||||
class KunitRequest(KunitExecRequest, KunitBuildRequest):
|
||||
|
|
@ -168,6 +169,12 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -
|
|||
for line in attr_output:
|
||||
print(line.rstrip())
|
||||
return KunitResult(status=KunitStatus.SUCCESS, elapsed_time=0.0)
|
||||
if request.list_suites:
|
||||
tests = _list_tests(linux, request)
|
||||
output = _suites_from_test_list(tests)
|
||||
for line in output:
|
||||
print(line.rstrip())
|
||||
return KunitResult(status=KunitStatus.SUCCESS, elapsed_time=0.0)
|
||||
if request.run_isolated:
|
||||
tests = _list_tests(linux, request)
|
||||
if request.run_isolated == 'test':
|
||||
|
|
@ -438,6 +445,9 @@ def add_exec_opts(parser: argparse.ArgumentParser) -> None:
|
|||
parser.add_argument('--list_tests_attr', help='If set, list all tests and test '
|
||||
'attributes.',
|
||||
action='store_true')
|
||||
parser.add_argument('--list_suites', help='If set, list all suites that will be '
|
||||
'run.',
|
||||
action='store_true')
|
||||
|
||||
def add_parse_opts(parser: argparse.ArgumentParser) -> None:
|
||||
parser.add_argument('--raw_output', help='If set don\'t parse output from kernel. '
|
||||
|
|
@ -501,7 +511,8 @@ def run_handler(cli_args: argparse.Namespace) -> None:
|
|||
kernel_args=cli_args.kernel_args,
|
||||
run_isolated=cli_args.run_isolated,
|
||||
list_tests=cli_args.list_tests,
|
||||
list_tests_attr=cli_args.list_tests_attr)
|
||||
list_tests_attr=cli_args.list_tests_attr,
|
||||
list_suites=cli_args.list_suites)
|
||||
result = run_tests(linux, request)
|
||||
if result.status != KunitStatus.SUCCESS:
|
||||
sys.exit(1)
|
||||
|
|
@ -550,7 +561,8 @@ def exec_handler(cli_args: argparse.Namespace) -> None:
|
|||
kernel_args=cli_args.kernel_args,
|
||||
run_isolated=cli_args.run_isolated,
|
||||
list_tests=cli_args.list_tests,
|
||||
list_tests_attr=cli_args.list_tests_attr)
|
||||
list_tests_attr=cli_args.list_tests_attr,
|
||||
list_suites=cli_args.list_suites)
|
||||
result = exec_tests(linux, exec_request)
|
||||
stdout.print_with_timestamp((
|
||||
'Elapsed time: %.3fs\n') % (result.elapsed_time))
|
||||
|
|
|
|||
|
|
@ -881,7 +881,7 @@ class KUnitMainTest(unittest.TestCase):
|
|||
self.linux_source_mock.run_kernel.return_value = ['TAP version 14', 'init: random output'] + want
|
||||
|
||||
got = kunit._list_tests(self.linux_source_mock,
|
||||
kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*', '', None, None, 'suite', False, False))
|
||||
kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*', '', None, None, 'suite', False, False, False))
|
||||
self.assertEqual(got, want)
|
||||
# Should respect the user's filter glob when listing tests.
|
||||
self.linux_source_mock.run_kernel.assert_called_once_with(
|
||||
|
|
@ -894,7 +894,7 @@ class KUnitMainTest(unittest.TestCase):
|
|||
|
||||
# Should respect the user's filter glob when listing tests.
|
||||
mock_tests.assert_called_once_with(mock.ANY,
|
||||
kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*.test*', '', None, None, 'suite', False, False))
|
||||
kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*.test*', '', None, None, 'suite', False, False, False))
|
||||
self.linux_source_mock.run_kernel.assert_has_calls([
|
||||
mock.call(args=None, build_dir='.kunit', filter_glob='suite.test*', filter='', filter_action=None, timeout=300),
|
||||
mock.call(args=None, build_dir='.kunit', filter_glob='suite2.test*', filter='', filter_action=None, timeout=300),
|
||||
|
|
@ -907,13 +907,23 @@ class KUnitMainTest(unittest.TestCase):
|
|||
|
||||
# Should respect the user's filter glob when listing tests.
|
||||
mock_tests.assert_called_once_with(mock.ANY,
|
||||
kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*', '', None, None, 'test', False, False))
|
||||
kunit.KunitExecRequest(None, None, False, False, '.kunit', 300, 'suite*', '', None, None, 'test', False, False, False))
|
||||
self.linux_source_mock.run_kernel.assert_has_calls([
|
||||
mock.call(args=None, build_dir='.kunit', filter_glob='suite.test1', filter='', filter_action=None, timeout=300),
|
||||
mock.call(args=None, build_dir='.kunit', filter_glob='suite.test2', filter='', filter_action=None, timeout=300),
|
||||
mock.call(args=None, build_dir='.kunit', filter_glob='suite2.test1', filter='', filter_action=None, timeout=300),
|
||||
])
|
||||
|
||||
@mock.patch.object(kunit, '_list_tests')
|
||||
@mock.patch.object(sys, 'stdout', new_callable=io.StringIO)
|
||||
def test_list_suites(self, mock_stdout, mock_tests):
|
||||
mock_tests.return_value = ['suite.test1', 'suite.test2', 'suite2.test1']
|
||||
kunit.main(['run', '--list_suites'])
|
||||
|
||||
want = ['suite', 'suite2']
|
||||
output = mock_stdout.getvalue().split()
|
||||
self.assertEqual(output, want)
|
||||
|
||||
@mock.patch.object(sys, 'stdout', new_callable=io.StringIO)
|
||||
def test_list_cmds(self, mock_stdout):
|
||||
kunit.main(['--list-cmds'])
|
||||
|
|
|
|||
Loading…
Reference in New Issue