From 4ac4add4f40af5efa709a598488ff67ed5e5eb0e Mon Sep 17 00:00:00 2001 From: Piotr Narajowski Date: Fri, 4 Oct 2024 14:21:25 +0200 Subject: [PATCH] bot: imrpove rtt log Work in progress. This should stop rtt read process only if we are sure that test case has ended and there is no more data to send --- autopts/ptsprojects/mynewt/iutctl.py | 8 ++++---- autopts/ptsprojects/zephyr/iutctl.py | 1 - autopts/rtt.py | 20 +++++++++++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/autopts/ptsprojects/mynewt/iutctl.py b/autopts/ptsprojects/mynewt/iutctl.py index 4cb6541b3a..a609914667 100644 --- a/autopts/ptsprojects/mynewt/iutctl.py +++ b/autopts/ptsprojects/mynewt/iutctl.py @@ -150,8 +150,8 @@ def reset(self): self.start(self.test_case) self.flush_serial() - self.rtt_logger_stop() - self.btmon_stop() + # self.rtt_logger_stop() + # self.btmon_stop() if not self.gdb: self.board.reset() @@ -199,8 +199,8 @@ def stop(self): self.iut_log_file.close() self.iut_log_file = None - self.rtt_logger_stop() - self.btmon_stop() + # self.rtt_logger_stop() + # self.btmon_stop() if self.socat_process: self.socat_process.terminate() diff --git a/autopts/ptsprojects/zephyr/iutctl.py b/autopts/ptsprojects/zephyr/iutctl.py index 209dca1476..74e3b167ca 100644 --- a/autopts/ptsprojects/zephyr/iutctl.py +++ b/autopts/ptsprojects/zephyr/iutctl.py @@ -205,7 +205,6 @@ def rtt_logger_start(self): def rtt_logger_stop(self): if self.rtt_logger: - time.sleep(0.1) # Make sure all logs have been collected, in case test failed early. self.rtt_logger.stop() def wait_iut_ready_event(self, reset=True): diff --git a/autopts/rtt.py b/autopts/rtt.py index 3583b9582f..90542a07d5 100644 --- a/autopts/rtt.py +++ b/autopts/rtt.py @@ -38,6 +38,8 @@ class RTT: def __init__(self): self.read_thread = None self.stop_thread = threading.Event() + self.rtt_stop = False + self.test_end = False pylink.logger.setLevel(logging.WARNING) def _get_buffer_index(self, buffer_name): @@ -57,14 +59,22 @@ def _get_buffer_index(self, buffer_name): if buf.name == buffer_name: return buf_index - @staticmethod - def _read_from_buffer(jlink, buffer_index, stop_thread, user_callback, user_data): + def _read_from_buffer(self, jlink, buffer_index, stop_thread, user_callback, user_data): + count = 0 + threshold = 5 try: while not stop_thread.is_set() and jlink.connected() and not get_global_end(): byte_list = jlink.rtt_read(buffer_index, 1024) if len(byte_list) > 0: + count = 0 user_callback(bytes(byte_list), user_data) - except BaseException: + elif self.test_end: + count += 1 + if count >= threshold: + # we have reached the threshold for consecutive empty reads, we can stop rtt_read + self.rtt_stop = True + except BaseException as e: + self.rtt_stop = True pass # JLink closed def init_jlink(self, device_core, debugger_snr): @@ -235,6 +245,10 @@ def start(self, buffer_name, log_filename, device_core, debugger_snr): def stop(self): log("%s.%s", self.__class__, self.stop.__name__) + + self.rtt_reader.test_end = True + while not self.rtt_reader.rtt_stop: + time.sleep(0.1) self.rtt_reader.stop() if self.log_file: