Skip to content

Commit

Permalink
bot: improve 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 7, 2024
1 parent 6652482 commit 5c0905e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
12 changes: 5 additions & 7 deletions autopts/ptsprojects/mynewt/iutctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,17 @@ def rtt_logger_start(self):
'_iutctl.log')
self.rtt_logger.start('Terminal', log_file, self.device_core, self.debugger_snr)

def rtt_logger_stop(self):
def rtt_logger_stop(self, reset):
if self.rtt_logger:
self.rtt_logger.stop()
self.rtt_logger.stop(reset)

def reset(self):
"""Restart IUT related processes and reset the IUT"""
log("%s.%s", self.__class__, self.reset.__name__)

self.stop()
self.stop(reset=True)
self.start(self.test_case)
self.flush_serial()

self.rtt_logger_stop()
self.btmon_stop()

if not self.gdb:
Expand Down Expand Up @@ -180,7 +178,7 @@ def wait_iut_ready_event(self):
def get_supported_svcs(self):
btp.read_supp_svcs()

def stop(self):
def stop(self, reset=False):
"""Powers off the Mynewt OS"""
log("%s.%s", self.__class__, self.stop.__name__)

Expand All @@ -199,7 +197,7 @@ def stop(self):
self.iut_log_file.close()
self.iut_log_file = None

self.rtt_logger_stop()
self.rtt_logger_stop(reset)
self.btmon_stop()

if self.socat_process:
Expand Down
13 changes: 6 additions & 7 deletions autopts/ptsprojects/zephyr/iutctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,17 @@ def rtt_logger_start(self):
'_iutctl.log')
self.rtt_logger.start('Logger', log_file, self.device_core, self.debugger_snr)

def rtt_logger_stop(self):
def rtt_logger_stop(self, reset):
if self.rtt_logger:
time.sleep(0.1) # Make sure all logs have been collected, in case test failed early.
self.rtt_logger.stop()
self.rtt_logger.stop(reset)

def wait_iut_ready_event(self, reset=True):
"""Wait until IUT sends ready event after power up"""
stack = get_stack()

if reset:
# For HW, the IUT ready event is triggered at board.reset()
self.stop()
self.stop(reset)
# For QEMU, the IUT ready event is sent at startup of the process.
self.start(self.test_case)

Expand All @@ -225,7 +224,7 @@ def wait_iut_ready_event(self, reset=True):
# two IUT events may be received because of cleanup.
stack.core.event_queues[defs.CORE_EV_IUT_READY].clear()
if not ev:
self.stop()
self.stop(reset)
raise Exception('IUT ready event NOT received!')

log("IUT ready event received OK")
Expand All @@ -244,14 +243,14 @@ def hw_reset(self):
if len(stack.core.event_queues[defs.CORE_EV_IUT_READY]) == 0:
self.board.reset()

def stop(self):
def stop(self, reset=False):
"""Powers off the Zephyr OS"""
log("%s.%s", self.__class__, self.stop.__name__)

if not self.is_running:
return

self.rtt_logger_stop()
self.rtt_logger_stop(reset)
self.btmon_stop()

stack = get_stack()
Expand Down
27 changes: 22 additions & 5 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 @@ -233,9 +243,16 @@ def start(self, buffer_name, log_filename, device_core, debugger_snr):
self.log_file = open(log_filename, 'ab')
self.rtt_reader.start(buffer_name, device_core, debugger_snr, self._on_line_read_callback, (self.log_file,))

def stop(self):
def stop(self, reset):
log("%s.%s", self.__class__, self.stop.__name__)
self.rtt_reader.stop()

if reset:
self.rtt_reader.stop()
else:
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:
self.log_file.close()
Expand Down

0 comments on commit 5c0905e

Please sign in to comment.