Skip to content

Commit

Permalink
bot: imrpove rtt log
Browse files Browse the repository at this point in the history
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
  • Loading branch information
piotrnarajowski committed Oct 4, 2024
1 parent 6652482 commit 4ac4add
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions autopts/ptsprojects/mynewt/iutctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion autopts/ptsprojects/zephyr/iutctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
20 changes: 17 additions & 3 deletions autopts/rtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4ac4add

Please sign in to comment.