From 340e2dff1288bdab5dbb470a213320c8ace0f57b Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 18 Nov 2020 15:48:27 +1100 Subject: [PATCH 1/3] ci: Log failure to close any DUT --- tools/ci/python_packages/tiny_test_fw/Env.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/ci/python_packages/tiny_test_fw/Env.py b/tools/ci/python_packages/tiny_test_fw/Env.py index d54535351e..90d84e3405 100644 --- a/tools/ci/python_packages/tiny_test_fw/Env.py +++ b/tools/ci/python_packages/tiny_test_fw/Env.py @@ -18,6 +18,7 @@ import threading import functools import netifaces +import traceback from . import EnvConfig @@ -190,6 +191,7 @@ class Env(object): dut.print_debug_info() dut.close() except Exception as e: + traceback.print_exc() dut_close_errors.append(e) self.allocated_duts = dict() return dut_close_errors From 34a84c829ca6e7fae68aff2528557a8fe7f984f6 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 24 Nov 2020 18:32:09 +1100 Subject: [PATCH 2/3] 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/ci/python_packages/tiny_test_fw/DUT.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/ci/python_packages/tiny_test_fw/DUT.py b/tools/ci/python_packages/tiny_test_fw/DUT.py index ccb3797726..34eb6de159 100644 --- a/tools/ci/python_packages/tiny_test_fw/DUT.py +++ b/tools/ci/python_packages/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,12 @@ 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 try: - data = data.decode("utf-8", "ignore") - except UnicodeDecodeError: - data = data.decode("iso8859-1", ) + return data.decode(sys.stdout.encoding, "backslashreplace") + except (UnicodeDecodeError, TypeError): # Python <3.5 doesn't support backslashreplace + return data.decode(sys.stdout.encoding, "replace") return data From baaf4de7030d888c51265656a25729f3f6ebac63 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 3 Mar 2021 18:14:17 +1100 Subject: [PATCH 3/3] ci: Fix missing sys.stdout.encoding in python2 runners Regression in fed98cd6adbe6576beda5076d0840eac0b4944e6 --- tools/ci/python_packages/tiny_test_fw/DUT.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/ci/python_packages/tiny_test_fw/DUT.py b/tools/ci/python_packages/tiny_test_fw/DUT.py index 34eb6de159..c23f6b976e 100644 --- a/tools/ci/python_packages/tiny_test_fw/DUT.py +++ b/tools/ci/python_packages/tiny_test_fw/DUT.py @@ -81,10 +81,13 @@ def _decode_data(data): if isinstance(data, bytes): # 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 + encoding = sys.stdout.encoding + if encoding is None: + encoding = 'ascii' try: - return data.decode(sys.stdout.encoding, "backslashreplace") + return data.decode(encoding, "backslashreplace") except (UnicodeDecodeError, TypeError): # Python <3.5 doesn't support backslashreplace - return data.decode(sys.stdout.encoding, "replace") + return data.decode(encoding, "replace") return data