Skip to content

Commit

Permalink
scripts: twister: Fix trailing CR/LF at BinaryHandler logs
Browse files Browse the repository at this point in the history
Fix trailing `\\r\\n` (escaped CR/LF) didn't cut off because of rstrip()
removed by #58338, so the CR/LF suffix was never found as the actual line
end was `\\r\\n\n`.

Add ANSI code sequence to `test_handlers` Twister unit test.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
  • Loading branch information
golowanow authored and fabiobaltieri committed Sep 27, 2024
1 parent 58d9e3d commit 2ddab56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 3 additions & 4 deletions scripts/pylib/twister/twisterlib/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,9 @@ def _output_handler(self, proc, harness):
reader_t.join(this_timeout)
if not reader_t.is_alive() and self.line != b"":
line_decoded = self.line.decode('utf-8', "replace")
if line_decoded.endswith(suffix):
stripped_line = line_decoded[:-len(suffix)].rstrip()
else:
stripped_line = line_decoded.rstrip()
stripped_line = line_decoded.rstrip()
if stripped_line.endswith(suffix):
stripped_line = stripped_line[:-len(suffix)].rstrip()
logger.debug("OUTPUT: %s", stripped_line)
log_out_fp.write(strip_ansi_sequences(line_decoded))
log_out_fp.flush()
Expand Down
8 changes: 5 additions & 3 deletions scripts/tests/twister/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,19 @@ def mock_kill_function(pid, sig):

TESTDATA_3 = [
(
[b'This\\r\\n', b'is\r', b'a short', b'file.'],
[b'This\\r\\n\n', b'is\r', b'some \x1B[31mANSI\x1B[39m in\n', b'a short\n', b'file.'],
mock.Mock(status=TwisterStatus.NONE, capture_coverage=False),
[
mock.call('This\\r\\n'),
mock.call('This\\r\\n\n'),
mock.call('is\r'),
mock.call('a short'),
mock.call('some ANSI in\n'),
mock.call('a short\n'),
mock.call('file.')
],
[
mock.call('This'),
mock.call('is'),
mock.call('some \x1B[31mANSI\x1B[39m in'),
mock.call('a short'),
mock.call('file.')
],
Expand Down

0 comments on commit 2ddab56

Please sign in to comment.