From b79778d273259ac8a85f1ddbc8fc574da02db485 Mon Sep 17 00:00:00 2001 From: He Yin Ling Date: Thu, 1 Jul 2021 17:43:50 +0800 Subject: [PATCH 1/2] ttfw: full_stdout should not return data after pattern in expect --- tools/ci/python_packages/tiny_test_fw/DUT.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci/python_packages/tiny_test_fw/DUT.py b/tools/ci/python_packages/tiny_test_fw/DUT.py index 9c68a34b56..0a1e28506f 100644 --- a/tools/ci/python_packages/tiny_test_fw/DUT.py +++ b/tools/ci/python_packages/tiny_test_fw/DUT.py @@ -604,6 +604,7 @@ class BaseDUT(object): while True: ret, index = method(data, pattern) if ret is not None: + stdout = data[:index] self.data_cache.flush(index) break time_remaining = start_time + timeout - time.time() @@ -611,7 +612,6 @@ class BaseDUT(object): break # wait for new data from cache data = self.data_cache.get_data(time_remaining) - stdout = data if ret is None: pattern = _pattern_to_string(pattern) From 1708febe48551b0c1c58f7839c61bc32d61f947a Mon Sep 17 00:00:00 2001 From: He Yin Ling Date: Thu, 1 Jul 2021 17:48:53 +0800 Subject: [PATCH 2/2] ttfw: fix incorrect length when flush data cache after expect: data cache is unicode. while we use bytes in RegEx expect. The index of matched pattern is calculated with bytes, could be different from unicode. Now we fix this issue by using unicode in expect. --- tools/ci/python_packages/tiny_test_fw/DUT.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/ci/python_packages/tiny_test_fw/DUT.py b/tools/ci/python_packages/tiny_test_fw/DUT.py index 0a1e28506f..cdd90be9a2 100644 --- a/tools/ci/python_packages/tiny_test_fw/DUT.py +++ b/tools/ci/python_packages/tiny_test_fw/DUT.py @@ -548,13 +548,11 @@ class BaseDUT(object): :return: match groups if match succeed otherwise None """ ret = None - if isinstance(pattern.pattern, type(u'')): - pattern = re.compile(BaseDUT.u_to_bytearray(pattern.pattern)) - if isinstance(data, type(u'')): - data = BaseDUT.u_to_bytearray(data) + if isinstance(pattern.pattern, bytes): + pattern = re.compile(_decode_data(pattern.pattern)) match = pattern.search(data) if match: - ret = tuple(None if x is None else x.decode() for x in match.groups()) + ret = tuple(x for x in match.groups()) index = match.end() else: index = -1