kunit: tool: improve compatibility of kunit_parser with KTAP specification
PATCH v6 1/1 kunit: tool: improve compatibility of kunit_parser with KTAP specification
From: Rae Moar <[email protected]>
Update to kunit_parser to improve compatibility with KTAP specification including arbitrarily nested tests. Patch accomplishes three major changes:
- Use a general Test object to represent all tests rather than TestCase and TestSuite objects. This allows for easier implementation of arbitrary levels of nested tests and promotes the idea that both test suites and test cases are tests.
- Print errors incrementally rather than all at once after the parsing finishes to maximize information given to the user in the case of the parser given invalid input and to increase the helpfulness of the timestamps given during printing. Note that kunit.py parse does not print incrementally yet. However, this fix brings us closer to this feature.
- Increase compatibility for different formats of input. Arbitrary levels of nested tests supported. Also, test cases and test suites are now supported to be present on the same level of testing.
This patch now implements the draft KTAP specification here:
https://lore.kernel.org/linux-kselftest/CA+GJov6tdjvY9x12JsJT14qn6c7NViJxqaJk+r-K1YJzPggFDQ@mail.gmail.com/
We'll update the parser as the spec evolves.
This patch adjusts the kunit_tool_test.py file to check for the correct outputs from the new parser and adds a new test to check the parsing for a KTAP result log with correct format for multiple nested subtests (test_is_test_passed-all_passed_nested.log).
This patch also alters the kunit_json.py file to allow for arbitrarily nested tests.
---
NOTE: this patch is now applied on top of
https://lore.kernel.org/linux-kselftest/[email protected]/
to resolve a conflict.
Change log from v5:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Tweak commit message to reflect the KTAP spec is a draft
- Add missing Signed-off-by
- Tweak docstrings
Change log from v3,4:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Move test_kselftest_nested from LinuxSourceTreeTest => KUnitParserTest.
- Resolve conflict with hermetic testing patches.
- max_status is no longer defined, so we need to use the TestCounts type now. And to keep --raw_output working, we need to set this to SUCCESS to avoid the default assumption that the kernel crashed.
Ignore v4, was accidentally based on v2.
Change log from v2:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Fixes bug of type disagreement in kunit_json.py for build_dir
- Removes raw_output()
- Changes docstrings in kunit_parser.py (class docstring, LineStream docstrings, add_error(), total(), get_status(), all parsing methods)
- Fixes bug of not printing diagnostic log in the case of end of lines
- Sets default status of all tests to TEST_CRASHED
- Adds and prints empty tests with crashed status in case of missing tests
- Prints 'subtest' in instance of 1 subtest instead of 'subtests'
- Includes checking for 'BUG:' message in search of crash messages in log (note that parse_crash_in_log method could be removed but would require deleting tests in kunit_tool_test.py that include the crash message that is no longer used. If removed, parser would still print log in cases of test crashed or failure, which would now include missing subtests)
- Fixes bug of including directives (other than SKIP) in test name when matching name in result line for subtests
Change log from v1:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Rebase onto kselftest/kunit branch
- Add tests to kunit_tool_test.py to check parser is correctly stripping hyphen, producing correct json objects with nested tests, correctly passing kselftest TAP output, and correctly deals with missing test plan.
- Fix bug to correctly match test name in instance of a missing test plan.
- Fix bug in kunit_tool_test.py pointed out by Daniel where it was not correctly checking for a proper match to the '0 tests run!' error message. Reverts changes back to original.
- A few minor changes to commit message using Daniel's comments.
- Change docstrings using Daniel's comments to reduce:
- Shortens some docstrings to be one-line or just description if it is self explanatory.
- Remove explicit respecification of types of parameters and returns because this is already specified in the function annoations. However, some descriptions of the parameters and returns remain and some contain the type for context. Additionally, the types of public attributes of classes remain.
- Remove any documentation of 'Return: None'
- Remove docstrings of helper methods within other methods
--- tools/testing/kunit/kunit.py | 19 +- tools/testing/kunit/kunit_json.py | 56 +- tools/testing/kunit/kunit_parser.py | 1021 ++++++++++++----- tools/testing/kunit/kunit_tool_test.py | 133 ++- .../test_is_test_passed-all_passed_nested.log | 34 + .../test_is_test_passed-kselftest.log | 14 + .../test_is_test_passed-missing_plan.log | 31 + .../kunit/test_data/test_strip_hyphen.log | 16 + 8 files changed, 940 insertions(+), 384 deletions(-) create mode 100644 tools/testing/kunit/test_data/test_is_test_passed-all_passed_nested.log create mode 100644 tools/testing/kunit/test_data/test_is_test_passed-kselftest.log create mode 100644 tools/testing/kunit/test_data/test_is_test_passed-missing_plan.log create mode 100644 tools/testing/kunit/test_data/test_strip_hyphen.log
tools/testing/kunit/kunit.py +15 -4
@@ -136,7 +136,7 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest, test_glob = request.filter_glob.split('.', maxsplit=2)[1] filter_globs = [g + '.'+ test_glob for g in filter_globs] - overall_status = kunit_parser.TestStatus.SUCCESS + test_counts = kunit_parser.TestCounts() exec_time = 0.0 for i, filter_glob in enumerate(filter_globs): kunit_parser.print_with_timestamp('Starting KUnit Kernel ({}/{})...'.format(i+1, len(filter_globs)))
@@ -155,18 +155,29 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest, test_end = time.time() exec_time += test_end - test_start - overall_status = kunit_parser.max_status(overall_status, result.status) + test_counts.add_subtest_counts(result.result.test.counts) - return KunitResult(status=result.status, result=result.result, elapsed_time=exec_time) + kunit_status = _map_to_overall_status(test_counts.get_status()) + return KunitResult(status=kunit_status, result=result.result, elapsed_time=exec_time) + +def _map_to_overall_status(test_status: kunit_parser.TestStatus) -> KunitStatus: + if test_status in (kunit_parser.TestStatus.SUCCESS, kunit_parser.TestStatus.SKIPPED): + return KunitStatus.SUCCESS + else: + return KunitStatus.TEST_FAILURE def parse_tests(request: KunitParseRequest, input_data: Iterable[str]) -> KunitResult: parse_start = time.time() test_result = kunit_parser.TestResult(kunit_parser.TestStatus.SUCCESS, - [], + kunit_parser.Test(), 'Tests not Parsed.') if request.raw_output: + # Treat unparsed results as one passing test. + test_result.test.status = kunit_parser.TestStatus.SUCCESS + test_result.test.counts.passed = 1 + output: Iterable[str] = input_data if request.raw_output == 'all': pass
tools/testing/kunit/kunit_json.py +28 -28
75 lines not on this page · raw message
tools/testing/kunit/kunit_parser.py +708 -313
1,133 lines not on this page · raw message
tools/testing/kunit/kunit_tool_test.py +94 -39
245 lines not on this page · raw message
tools/testing/kunit/test_data/test_is_test_passed-all_passed_nested.log new file +34 -0
@@ -0,0 +1,34 @@ +TAP version 14 +1..2 + # Subtest: sysctl_test + 1..4 + # sysctl_test_dointvec_null_tbl_data: sysctl_test_dointvec_null_tbl_data passed + ok 1 - sysctl_test_dointvec_null_tbl_data + # Subtest: example + 1..2 + init_suite + # example_simple_test: initializing + # example_simple_test: example_simple_test passed + ok 1 - example_simple_test + # example_mock_test: initializing + # example_mock_test: example_mock_test passed + ok 2 - example_mock_test + kunit example: all tests passed + ok 2 - example + # sysctl_test_dointvec_table_len_is_zero: sysctl_test_dointvec_table_len_is_zero passed + ok 3 - sysctl_test_dointvec_table_len_is_zero + # sysctl_test_dointvec_table_read_but_position_set: sysctl_test_dointvec_table_read_but_position_set passed + ok 4 - sysctl_test_dointvec_table_read_but_position_set +kunit sysctl_test: all tests passed +ok 1 - sysctl_test + # Subtest: example + 1..2 +init_suite + # example_simple_test: initializing + # example_simple_test: example_simple_test passed + ok 1 - example_simple_test + # example_mock_test: initializing + # example_mock_test: example_mock_test passed + ok 2 - example_mock_test +kunit example: all tests passed +ok 2 - example
tools/testing/kunit/test_data/test_is_test_passed-kselftest.log new file +14 -0
@@ -0,0 +1,14 @@ +TAP version 13 +1..2 +# selftests: membarrier: membarrier_test_single_thread +# TAP version 13 +# 1..2 +# ok 1 sys_membarrier available +# ok 2 sys membarrier invalid command test: command = -1, flags = 0, errno = 22. Failed as expected +ok 1 selftests: membarrier: membarrier_test_single_thread +# selftests: membarrier: membarrier_test_multi_thread +# TAP version 13 +# 1..2 +# ok 1 sys_membarrier available +# ok 2 sys membarrier invalid command test: command = -1, flags = 0, errno = 22. Failed as expected +ok 2 selftests: membarrier: membarrier_test_multi_thread
tools/testing/kunit/test_data/test_is_test_passed-missing_plan.log new file +31 -0
@@ -0,0 +1,31 @@ +KTAP version 1 + # Subtest: sysctl_test + # sysctl_test_dointvec_null_tbl_data: sysctl_test_dointvec_null_tbl_data passed + ok 1 - sysctl_test_dointvec_null_tbl_data + # sysctl_test_dointvec_table_maxlen_unset: sysctl_test_dointvec_table_maxlen_unset passed + ok 2 - sysctl_test_dointvec_table_maxlen_unset + # sysctl_test_dointvec_table_len_is_zero: sysctl_test_dointvec_table_len_is_zero passed + ok 3 - sysctl_test_dointvec_table_len_is_zero + # sysctl_test_dointvec_table_read_but_position_set: sysctl_test_dointvec_table_read_but_position_set passed + ok 4 - sysctl_test_dointvec_table_read_but_position_set + # sysctl_test_dointvec_happy_single_positive: sysctl_test_dointvec_happy_single_positive passed + ok 5 - sysctl_test_dointvec_happy_single_positive + # sysctl_test_dointvec_happy_single_negative: sysctl_test_dointvec_happy_single_negative passed + ok 6 - sysctl_test_dointvec_happy_single_negative + # sysctl_test_dointvec_single_less_int_min: sysctl_test_dointvec_single_less_int_min passed + ok 7 - sysctl_test_dointvec_single_less_int_min + # sysctl_test_dointvec_single_greater_int_max: sysctl_test_dointvec_single_greater_int_max passed + ok 8 - sysctl_test_dointvec_single_greater_int_max +kunit sysctl_test: all tests passed +ok 1 - sysctl_test + # Subtest: example + 1..2 +init_suite + # example_simple_test: initializing + # example_simple_test: example_simple_test passed + ok 1 - example_simple_test + # example_mock_test: initializing + # example_mock_test: example_mock_test passed + ok 2 - example_mock_test +kunit example: all tests passed +ok 2 - example
tools/testing/kunit/test_data/test_strip_hyphen.log new file +16 -0
@@ -0,0 +1,16 @@ +KTAP version 1 +1..2 + # Subtest: sysctl_test + 1..1 + # sysctl_test_dointvec_null_tbl_data: sysctl_test_dointvec_null_tbl_data passed + ok 1 - sysctl_test_dointvec_null_tbl_data +kunit sysctl_test: all tests passed +ok 1 - sysctl_test + # Subtest: example + 1..1 +init_suite + # example_simple_test: initializing + # example_simple_test: example_simple_test passed + ok 1 example_simple_test +kunit example: all tests passed +ok 2 example
base-commit: 28a8b037484044d79f3b8d409a076a925ac75f8d
Signature · 1 line
2.33.0.882.g93a45727a2-goog
Quoted 95 lines · Daniel Latypov
From: Rae Moar <[email protected]>
Update to
kunit_parserto improve compatibility with KTAP specification including arbitrarily nested tests. Patch accomplishes three major changes:- Use a general Test object to represent all tests rather than TestCase and TestSuite objects. This allows for easier implementation of arbitrary levels of nested tests and promotes the idea that both test suites and test cases are tests.
- Print errors incrementally rather than all at once after the parsing finishes to maximize information given to the user in the case of the parser given invalid input and to increase the helpfulness of the timestamps given during printing. Note that
kunit.pyparse does not print incrementally yet. However, this fix brings us closer to this feature.- Increase compatibility for different formats of input. Arbitrary levels of nested tests supported. Also, test cases and test suites are now supported to be present on the same level of testing.
This patch now implements the draft KTAP specification here:
https://lore.kernel.org/linux-kselftest/CA+GJov6tdjvY9x12JsJT14qn6c7NViJxqaJk+r-K1YJzPggFDQ@mail.gmail.com/
We'll update the parser as the spec evolves.This patch adjusts the
kunit_tool_test.pyfile to check for the correct outputs from the new parser and adds a new test to check the parsing for a KTAP result log with correct format for multiple nested subtests (test_is_test_passed-all_passed_nested.log).This patch also alters the
kunit_json.pyfile to allow for arbitrarily nested tests.Signed-off-by Rae Moar <[email protected]>Reviewed-by Brendan Higgins <[email protected]>Signed-off-by Daniel Latypov <[email protected]>Reviewed-by David Gow <[email protected]>---
NOTE: this patch is now applied on top of
https://lore.kernel.org/linux-kselftest/[email protected]/
to resolve a conflict.Change log from v5:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Tweak commit message to reflect the KTAP spec is a draft
- Add missing Signed-off-by
- Tweak docstringsChange log from v3,4:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Movetest_kselftest_nestedfrom LinuxSourceTreeTest => KUnitParserTest.
- Resolve conflict with hermetic testing patches.
-max_statusis no longer defined, so we need to use the TestCounts type now. And to keep --raw_output working, we need to set this to SUCCESS to avoid the default assumption that the kernel crashed.Ignore v4, was accidentally based on v2.
Change log from v2:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Fixes bug of type disagreement inkunit_json.pyforbuild_dir
- Removesraw_output()
- Changes docstrings inkunit_parser.py(class docstring, LineStream docstrings,add_error(),total(),get_status(), all parsing methods)
- Fixes bug of not printing diagnostic log in the case of end of lines
- Sets default status of all tests toTEST_CRASHED
- Adds and prints empty tests with crashed status in case of missing tests
- Prints 'subtest' in instance of 1 subtest instead of 'subtests'
- Includes checking for 'BUG:' message in search of crash messages in log (note thatparse_crash_in_logmethod could be removed but would require deleting tests inkunit_tool_test.pythat include the crash message that is no longer used. If removed, parser would still print log in cases of test crashed or failure, which would now include missing subtests)
- Fixes bug of including directives (other than SKIP) in test name when matching name in result line for subtestsChange log from v1:
https://lore.kernel.org/linux-kselftest/[email protected]/
- Rebase onto kselftest/kunit branch
- Add tests tokunit_tool_test.pyto check parser is correctly stripping hyphen, producing correct json objects with nested tests, correctly passing kselftest TAP output, and correctly deals with missing test plan.
- Fix bug to correctly match test name in instance of a missing test plan.
- Fix bug inkunit_tool_test.pypointed out by Daniel where it was not correctly checking for a proper match to the '0 tests run!' error message. Reverts changes back to original.
- A few minor changes to commit message using Daniel's comments.
- Change docstrings using Daniel's comments to reduce:
- Shortens some docstrings to be one-line or just description if it is self explanatory.
Quoted 8 lines
- Remove explicit respecification of types of parameters and returns because this is already specified in the function annoations. However, some descriptions of the parameters and returns remain and some contain the type for context. Additionally, the types of public attributes of classes remain.
- Remove any documentation of 'Return: None'
- Remove docstrings of helper methods within other methods
---
Looks good to me, thanks!
This is still:
Cheers,
-- David