From 31773b8ed21905bbb547e75e25a87b50eacb287f Mon Sep 17 00:00:00 2001 From: He Yin Ling Date: Wed, 16 Jun 2021 18:19:33 +0800 Subject: [PATCH] ttfw: fix DUT check functions are called after case finished: DUT check functions are executed in receive thread. If we put data to data cache before execute the check functions, the main thread could handle the data cache first and mark test case finished. We will execute check functions first to make sure it's executed before case finished. --- tools/ci/python_packages/tiny_test_fw/DUT.py | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/ci/python_packages/tiny_test_fw/DUT.py b/tools/ci/python_packages/tiny_test_fw/DUT.py index ec798a1501..9c68a34b56 100644 --- a/tools/ci/python_packages/tiny_test_fw/DUT.py +++ b/tools/ci/python_packages/tiny_test_fw/DUT.py @@ -50,7 +50,13 @@ import time try: import Queue as _queue except ImportError: - import queue as _queue + import queue as _queue # type: ignore + +try: + from typing import Callable, List +except ImportError: + # Only used for type annotations + pass import serial from serial.tools import list_ports @@ -206,7 +212,7 @@ class _LogThread(threading.Thread, _queue.Queue): class RecvThread(threading.Thread): - CHECK_FUNCTIONS = [] + CHECK_FUNCTIONS = [] # type: List[Callable] """ DUT subclass can define a few check functions to process received data. """ def __init__(self, read, dut): @@ -251,16 +257,18 @@ class RecvThread(threading.Thread): while not self.exit_event.isSet(): raw_data = self.read(1000) if raw_data: + # we need to do line completion before call check functions + # need to call check functions first + # otherwise check functions could be called after cases finished + comp_data = self._line_completion(raw_data) + for check_function in self.CHECK_FUNCTIONS: + check_function(self, comp_data) + with self.record_data_lock: self.data_cache.put(raw_data) for capture_id in self.recorded_data: self.recorded_data[capture_id].put(raw_data) - # we need to do line completion before call check functions - comp_data = self._line_completion(raw_data) - for check_function in self.CHECK_FUNCTIONS: - check_function(self, comp_data) - def exit(self): self.exit_event.set() self.join()