Commit 05d9d2c3 authored by Daniel Latypov's avatar Daniel Latypov Committed by Shuah Khan

kunit: tool: unit tests all check parser errors, standardize formatting a bit

Let's verify that the parser isn't reporting any errors for valid
inputs.

This change also
* does result.status checking on one line
* makes sure we consistently do it outside of the `with` block
Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
Reviewed-by: default avatarDavid Gow <davidgow@google.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent f473dd94
...@@ -136,33 +136,29 @@ class KUnitParserTest(unittest.TestCase): ...@@ -136,33 +136,29 @@ class KUnitParserTest(unittest.TestCase):
all_passed_log = test_data_path('test_is_test_passed-all_passed.log') all_passed_log = test_data_path('test_is_test_passed-all_passed.log')
with open(all_passed_log) as file: with open(all_passed_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS, self.assertEqual(result.counts.errors, 0)
result.status)
def test_parse_successful_nested_tests_log(self): def test_parse_successful_nested_tests_log(self):
all_passed_log = test_data_path('test_is_test_passed-all_passed_nested.log') all_passed_log = test_data_path('test_is_test_passed-all_passed_nested.log')
with open(all_passed_log) as file: with open(all_passed_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS, self.assertEqual(result.counts.errors, 0)
result.status)
def test_kselftest_nested(self): def test_kselftest_nested(self):
kselftest_log = test_data_path('test_is_test_passed-kselftest.log') kselftest_log = test_data_path('test_is_test_passed-kselftest.log')
with open(kselftest_log) as file: with open(kselftest_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS, self.assertEqual(result.counts.errors, 0)
result.status)
def test_parse_failed_test_log(self): def test_parse_failed_test_log(self):
failed_log = test_data_path('test_is_test_passed-failure.log') failed_log = test_data_path('test_is_test_passed-failure.log')
with open(failed_log) as file: with open(failed_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual( self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
kunit_parser.TestStatus.FAILURE, self.assertEqual(result.counts.errors, 0)
result.status)
def test_no_header(self): def test_no_header(self):
empty_log = test_data_path('test_is_test_passed-no_tests_run_no_header.log') empty_log = test_data_path('test_is_test_passed-no_tests_run_no_header.log')
...@@ -170,9 +166,8 @@ class KUnitParserTest(unittest.TestCase): ...@@ -170,9 +166,8 @@ class KUnitParserTest(unittest.TestCase):
result = kunit_parser.parse_run_tests( result = kunit_parser.parse_run_tests(
kunit_parser.extract_tap_lines(file.readlines())) kunit_parser.extract_tap_lines(file.readlines()))
self.assertEqual(0, len(result.subtests)) self.assertEqual(0, len(result.subtests))
self.assertEqual( self.assertEqual(kunit_parser.TestStatus.FAILURE_TO_PARSE_TESTS, result.status)
kunit_parser.TestStatus.FAILURE_TO_PARSE_TESTS, self.assertEqual(result.counts.errors, 1)
result.status)
def test_missing_test_plan(self): def test_missing_test_plan(self):
missing_plan_log = test_data_path('test_is_test_passed-' missing_plan_log = test_data_path('test_is_test_passed-'
...@@ -183,9 +178,7 @@ class KUnitParserTest(unittest.TestCase): ...@@ -183,9 +178,7 @@ class KUnitParserTest(unittest.TestCase):
file.readlines())) file.readlines()))
# A missing test plan is not an error. # A missing test plan is not an error.
self.assertEqual(result.counts, kunit_parser.TestCounts(passed=10, errors=0)) self.assertEqual(result.counts, kunit_parser.TestCounts(passed=10, errors=0))
self.assertEqual( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS,
result.status)
def test_no_tests(self): def test_no_tests(self):
header_log = test_data_path('test_is_test_passed-no_tests_run_with_header.log') header_log = test_data_path('test_is_test_passed-no_tests_run_with_header.log')
...@@ -193,9 +186,8 @@ class KUnitParserTest(unittest.TestCase): ...@@ -193,9 +186,8 @@ class KUnitParserTest(unittest.TestCase):
result = kunit_parser.parse_run_tests( result = kunit_parser.parse_run_tests(
kunit_parser.extract_tap_lines(file.readlines())) kunit_parser.extract_tap_lines(file.readlines()))
self.assertEqual(0, len(result.subtests)) self.assertEqual(0, len(result.subtests))
self.assertEqual( self.assertEqual(kunit_parser.TestStatus.NO_TESTS, result.status)
kunit_parser.TestStatus.NO_TESTS, self.assertEqual(result.counts.errors, 1)
result.status)
def test_no_tests_no_plan(self): def test_no_tests_no_plan(self):
no_plan_log = test_data_path('test_is_test_passed-no_tests_no_plan.log') no_plan_log = test_data_path('test_is_test_passed-no_tests_no_plan.log')
...@@ -206,7 +198,7 @@ class KUnitParserTest(unittest.TestCase): ...@@ -206,7 +198,7 @@ class KUnitParserTest(unittest.TestCase):
self.assertEqual( self.assertEqual(
kunit_parser.TestStatus.NO_TESTS, kunit_parser.TestStatus.NO_TESTS,
result.subtests[0].subtests[0].status) result.subtests[0].subtests[0].status)
self.assertEqual(1, result.counts.errors) self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, errors=1))
def test_no_kunit_output(self): def test_no_kunit_output(self):
...@@ -218,6 +210,7 @@ class KUnitParserTest(unittest.TestCase): ...@@ -218,6 +210,7 @@ class KUnitParserTest(unittest.TestCase):
print_mock.assert_any_call(StrContains('could not find any KTAP output!')) print_mock.assert_any_call(StrContains('could not find any KTAP output!'))
print_mock.stop() print_mock.stop()
self.assertEqual(0, len(result.subtests)) self.assertEqual(0, len(result.subtests))
self.assertEqual(result.counts.errors, 1)
def test_skipped_test(self): def test_skipped_test(self):
skipped_log = test_data_path('test_skip_tests.log') skipped_log = test_data_path('test_skip_tests.log')
...@@ -225,18 +218,16 @@ class KUnitParserTest(unittest.TestCase): ...@@ -225,18 +218,16 @@ class KUnitParserTest(unittest.TestCase):
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
# A skipped test does not fail the whole suite. # A skipped test does not fail the whole suite.
self.assertEqual( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS, self.assertEqual(result.counts, kunit_parser.TestCounts(passed=4, skipped=1))
result.status)
def test_skipped_all_tests(self): def test_skipped_all_tests(self):
skipped_log = test_data_path('test_skip_all_tests.log') skipped_log = test_data_path('test_skip_all_tests.log')
with open(skipped_log) as file: with open(skipped_log) as file:
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
self.assertEqual( self.assertEqual(kunit_parser.TestStatus.SKIPPED, result.status)
kunit_parser.TestStatus.SKIPPED, self.assertEqual(result.counts, kunit_parser.TestCounts(skipped=5))
result.status)
def test_ignores_hyphen(self): def test_ignores_hyphen(self):
hyphen_log = test_data_path('test_strip_hyphen.log') hyphen_log = test_data_path('test_strip_hyphen.log')
...@@ -244,9 +235,7 @@ class KUnitParserTest(unittest.TestCase): ...@@ -244,9 +235,7 @@ class KUnitParserTest(unittest.TestCase):
result = kunit_parser.parse_run_tests(file.readlines()) result = kunit_parser.parse_run_tests(file.readlines())
# A skipped test does not fail the whole suite. # A skipped test does not fail the whole suite.
self.assertEqual( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS,
result.status)
self.assertEqual( self.assertEqual(
"sysctl_test", "sysctl_test",
result.subtests[0].name) result.subtests[0].name)
...@@ -260,55 +249,49 @@ class KUnitParserTest(unittest.TestCase): ...@@ -260,55 +249,49 @@ class KUnitParserTest(unittest.TestCase):
prefix_log = test_data_path('test_config_printk_time.log') prefix_log = test_data_path('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( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS, self.assertEqual('kunit-resource-test', result.subtests[0].name)
result.status) self.assertEqual(result.counts.errors, 0)
self.assertEqual('kunit-resource-test', result.subtests[0].name)
def test_ignores_multiple_prefixes(self): def test_ignores_multiple_prefixes(self):
prefix_log = test_data_path('test_multiple_prefixes.log') prefix_log = test_data_path('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( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS, self.assertEqual('kunit-resource-test', result.subtests[0].name)
result.status) self.assertEqual(result.counts.errors, 0)
self.assertEqual('kunit-resource-test', result.subtests[0].name)
def test_prefix_mixed_kernel_output(self): def test_prefix_mixed_kernel_output(self):
mixed_prefix_log = test_data_path('test_interrupted_tap_output.log') mixed_prefix_log = test_data_path('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( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS, self.assertEqual('kunit-resource-test', result.subtests[0].name)
result.status) self.assertEqual(result.counts.errors, 0)
self.assertEqual('kunit-resource-test', result.subtests[0].name)
def test_prefix_poundsign(self): def test_prefix_poundsign(self):
pound_log = test_data_path('test_pound_sign.log') pound_log = test_data_path('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( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS, self.assertEqual('kunit-resource-test', result.subtests[0].name)
result.status) self.assertEqual(result.counts.errors, 0)
self.assertEqual('kunit-resource-test', result.subtests[0].name)
def test_kernel_panic_end(self): def test_kernel_panic_end(self):
panic_log = test_data_path('test_kernel_panic_interrupt.log') panic_log = test_data_path('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( self.assertEqual(kunit_parser.TestStatus.TEST_CRASHED, result.status)
kunit_parser.TestStatus.TEST_CRASHED, self.assertEqual('kunit-resource-test', result.subtests[0].name)
result.status) self.assertGreaterEqual(result.counts.errors, 1)
self.assertEqual('kunit-resource-test', result.subtests[0].name)
def test_pound_no_prefix(self): def test_pound_no_prefix(self):
pound_log = test_data_path('test_pound_no_prefix.log') pound_log = test_data_path('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( self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
kunit_parser.TestStatus.SUCCESS, self.assertEqual('kunit-resource-test', result.subtests[0].name)
result.status) self.assertEqual(result.counts.errors, 0)
self.assertEqual('kunit-resource-test', result.subtests[0].name)
def test_summarize_failures(self): def test_summarize_failures(self):
output = """ output = """
......
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