twister: fix UnicodeDecodeError on input handling in BinaryHandler

In BinaryHandler we process input from simulator with decode('utf-8')
to convert it to string. decode has strict error handling by default -
so it raises UnicodeDecodeError exception if it can't decode input
binary sequence.

So if test start to print some junk to uart console we get
UnicodeDecodeError exception which cause the whole twister crash.

To fix that switch decode to less strict error handling when it
just replace undecoded binary sequence with unicode replacement
character.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
This commit is contained in:
Evgeniy Paltsev 2022-10-10 20:59:17 +04:00 committed by Anas Nashif
commit d9a64b7b23

View file

@ -192,11 +192,11 @@ class BinaryHandler(Handler):
reader_t.start()
reader_t.join(this_timeout)
if not reader_t.is_alive():
line = self.line
logger.debug("OUTPUT: {0}".format(line.decode('utf-8').rstrip()))
log_out_fp.write(line.decode('utf-8'))
line_decoded = self.line.decode('utf-8', "replace")
logger.debug("OUTPUT: {0}".format(line_decoded.rstrip()))
log_out_fp.write(line_decoded)
log_out_fp.flush()
harness.handle(line.decode('utf-8').rstrip())
harness.handle(line_decoded.rstrip())
if harness.state:
if not timeout_extended or harness.capture_coverage:
timeout_extended = True