Skip to content

Commit

Permalink
kunit: tool: add test for parsing attributes
Browse files Browse the repository at this point in the history
Add test for parsing attributes to kunit_tool_test.py. Test checks
attributes are parsed and saved in the test logs.

This test also checks that the attributes have not interfered with the
parsing of other test information, specifically the suite header as
the test plan was being incorrectely parsed.

Signed-off-by: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
Rae Moar authored and Shuah Khan committed Dec 18, 2023
1 parent 8ae27bc commit 6eb0ea2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tools/testing/kunit/kunit_tool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,22 @@ def test_parse_subtest_header(self):
kunit_parser.parse_run_tests(file.readlines())
self.print_mock.assert_any_call(StrContains('suite (1 subtest)'))

def test_parse_attributes(self):
ktap_log = test_data_path('test_parse_attributes.log')
with open(ktap_log) as file:
result = kunit_parser.parse_run_tests(file.readlines())

# Test should pass with no errors
self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, errors=0))
self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)

# Ensure suite header is parsed correctly
self.print_mock.assert_any_call(StrContains('suite (1 subtest)'))

# Ensure attributes in correct test log
self.assertContains('# module: example', result.subtests[0].log)
self.assertContains('# test.speed: slow', result.subtests[0].subtests[0].log)

def test_show_test_output_on_failure(self):
output = """
KTAP version 1
Expand Down
9 changes: 9 additions & 0 deletions tools/testing/kunit/test_data/test_parse_attributes.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
KTAP version 1
1..1
KTAP version 1
# Subtest: suite
# module: example
1..1
# test.speed: slow
ok 1 test
ok 1 suite

0 comments on commit 6eb0ea2

Please sign in to comment.