From 0aca88a6e90efb6c4602cad4c23d72502b0cd671 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 18 Nov 2020 15:48:27 +1100 Subject: [PATCH 1/2] ci: Log failure to close any DUT --- tools/tiny-test-fw/Env.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/tiny-test-fw/Env.py b/tools/tiny-test-fw/Env.py index 3622ba3824..eeef3a67c2 100644 --- a/tools/tiny-test-fw/Env.py +++ b/tools/tiny-test-fw/Env.py @@ -18,6 +18,7 @@ import threading import functools import netifaces +import traceback import EnvConfig @@ -180,6 +181,7 @@ class Env(object): try: dut.close() except Exception as e: + traceback.print_exc() dut_close_errors.append(e) self.allocated_duts = dict() return dut_close_errors From a85b97a6f53db3381a1b76c8b01ed7fd1b4fef8f Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 24 Nov 2020 18:32:09 +1100 Subject: [PATCH 2/2] ci: ttfw: Encode serial port data to whatever the console encoding is This is a bit of a hack, but gives us a way to always log it --- tools/tiny-test-fw/DUT.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/tiny-test-fw/DUT.py b/tools/tiny-test-fw/DUT.py index 34ac285780..36d373ae38 100644 --- a/tools/tiny-test-fw/DUT.py +++ b/tools/tiny-test-fw/DUT.py @@ -40,6 +40,7 @@ If they using different port then need to implement their DUTPort class as well. from __future__ import print_function import time import re +import sys import threading import copy import functools @@ -78,11 +79,15 @@ def _expect_lock(func): def _decode_data(data): """ for python3, if the data is bytes, then decode it to string """ if isinstance(data, bytes): - # convert bytes to string + # convert bytes to string. This is a bit of a hack, we know that we want to log this + # later so encode to the stdout encoding with backslash escapes for anything non-encodable + out_enc = sys.stdout.encoding + if out_enc is None: + out_enc = 'ascii' try: - data = data.decode("utf-8", "ignore") - except UnicodeDecodeError: - data = data.decode("iso8859-1", ) + return data.decode(out_enc, "backslashreplace") + except (UnicodeDecodeError, TypeError): # Python <3.5 doesn't support backslashreplace + return data.decode(out_enc, "replace") return data