Skip to content

Commit 060352e

Browse files
dlatypovshuahkh
authored andcommitted
kunit: tool: fix extra trailing \n in raw + parsed test output
For simplcity, strip all trailing whitespace from parsed output. I imagine no one is printing out meaningful trailing whitespace via KUNIT_FAIL() or similar, and that if they are, they really shouldn't. `isolate_kunit_output()` yielded liens with trailing \n, which results in artifacty output like this: $ ./tools/testing/kunit/kunit.py run [16:16:46] [FAILED] example_simple_test [16:16:46] # example_simple_test: EXPECTATION FAILED at lib/kunit/kunit-example-test.c:29 [16:16:46] Expected 1 + 1 == 3, but [16:16:46] 1 + 1 == 2 [16:16:46] 3 == 3 [16:16:46] not ok 1 - example_simple_test [16:16:46] After this change: [16:16:46] # example_simple_test: EXPECTATION FAILED at lib/kunit/kunit-example-test.c:29 [16:16:46] Expected 1 + 1 == 3, but [16:16:46] 1 + 1 == 2 [16:16:46] 3 == 3 [16:16:46] not ok 1 - example_simple_test [16:16:46] We should *not* be expecting lines to end with \n in kunit_tool_test.py for this reason. Do the same for `raw_output()` as well which suffers from the same issue. This is a followup to [1], but rebased onto kunit-fixes to pick up the other raw_output() fix and fixes for kunit_tool_test.py. [1] https://lore.kernel.org/linux-kselftest/20201020233219.4146059-1-dlatypov@google.com/ Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Tested-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 3908814 commit 060352e

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

tools/testing/kunit/kunit_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class TestStatus(Enum):
5454
def isolate_kunit_output(kernel_output):
5555
started = False
5656
for line in kernel_output:
57+
line = line.rstrip() # line always has a trailing \n
5758
if kunit_start_re.search(line):
5859
prefix_len = len(line.split('TAP version')[0])
5960
started = True
@@ -65,7 +66,7 @@ def isolate_kunit_output(kernel_output):
6566

6667
def raw_output(kernel_output):
6768
for line in kernel_output:
68-
print(line)
69+
print(line.rstrip())
6970

7071
DIVIDER = '=' * 60
7172

tools/testing/kunit/kunit_tool_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_output_isolated_correctly(self):
102102
'test_data/test_output_isolated_correctly.log')
103103
file = open(log_path)
104104
result = kunit_parser.isolate_kunit_output(file.readlines())
105-
self.assertContains('TAP version 14\n', result)
105+
self.assertContains('TAP version 14', result)
106106
self.assertContains(' # Subtest: example', result)
107107
self.assertContains(' 1..2', result)
108108
self.assertContains(' ok 1 - example_simple_test', result)
@@ -115,7 +115,7 @@ def test_output_with_prefix_isolated_correctly(self):
115115
'test_data/test_pound_sign.log')
116116
with open(log_path) as file:
117117
result = kunit_parser.isolate_kunit_output(file.readlines())
118-
self.assertContains('TAP version 14\n', result)
118+
self.assertContains('TAP version 14', result)
119119
self.assertContains(' # Subtest: kunit-resource-test', result)
120120
self.assertContains(' 1..5', result)
121121
self.assertContains(' ok 1 - kunit_resource_test_init_resources', result)

0 commit comments

Comments
 (0)