Skip to content

Commit

Permalink
tests: on_target: adding modem trace test
Browse files Browse the repository at this point in the history
Signed-off-by: David Dilner <[email protected]>
  • Loading branch information
dilner committed Nov 15, 2024
1 parent 376d41b commit af1ba4e
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/on_target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ jobs:
env:
SEGGER: ${{ secrets.SEGGER_DUT_1 }}

- name: Run modem trace test
working-directory: thingy91x-oob/tests/on_target
run: |
mkdir -p results
pytest -s -v -m "dut1 and traces" \
--junit-xml=results/test-results-traces-location.xml \
tests
env:
SEGGER: ${{ secrets.SEGGER_DUT_1 }}

- name: Results
if: always()
uses: pmeier/[email protected]
Expand Down
15 changes: 13 additions & 2 deletions tests/on_target/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
import types
from utils.flash_tools import recover_device
from utils.uart import Uart
from utils.uart import Uart, UartBinary
from utils.hellonrfcloud_fota import HelloNrfCloudFOTA
import sys
sys.path.append(os.getcwd())
Expand Down Expand Up @@ -59,7 +59,6 @@ def t91x_board():
if not all_uarts:
pytest.fail("No UARTs found")
log_uart_string = all_uarts[0]

uart = Uart(log_uart_string, timeout=UART_TIMEOUT)
fota = HelloNrfCloudFOTA(device_id=f"oob-{FOTADEVICE_IMEI}", \
fingerprint=FOTADEVICE_FINGERPRINT)
Expand All @@ -86,6 +85,18 @@ def t91x_board():

scan_log_for_assertions(uart_log)

@pytest.fixture(scope="module")
def t91x_traces():
all_uarts = get_uarts()
trace_uart_string = all_uarts[1]
uart_trace = UartBinary(trace_uart_string)

yield types.SimpleNamespace(
trace=uart_trace
)

uart_trace.stop()

@pytest.fixture(scope="session")
def hex_file():
# Search for the firmware hex file in the artifacts folder
Expand Down
1 change: 1 addition & 0 deletions tests/on_target/tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ markers =
fullmfw_fota: fullmfw fota tests
wifi: wifi location tests
gnss: device used for GNSS tests
traces: modem trace tests
71 changes: 71 additions & 0 deletions tests/on_target/tests/test_traces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
##########################################################################################
# Copyright (c) 2024 Nordic Semiconductor
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
##########################################################################################

import pytest
import time
import os
from utils.flash_tools import flash_device, reset_device
import sys
sys.path.append(os.getcwd())
from utils.logger import get_logger

logger = get_logger()

trace_collection_time = 60
trace_read_timeout = 60
treashold_lost_traces = 200

@pytest.mark.traces
@pytest.mark.dut1
def test_traces(t91x_board, t91x_traces, hex_file):
flash_device(os.path.abspath(hex_file))
time.sleep(5)
t91x_board.uart.xfactoryreset()
t91x_board.uart.flush()
reset_device()

t91x_board.uart.wait_for_str("nrf_modem_lib_trace: Trace thread ready", timeout=60)
t91x_board.uart.write("modem_trace size\r\n")
t91x_board.uart.wait_for_str("Modem trace data size:", timeout=5)
modem_trace_size_1 = t91x_board.uart.extract_value(r"Modem trace data size: (\d+) bytes")
assert modem_trace_size_1

logger.info("Collecting modem traces for 60 seconds")
time.sleep(trace_collection_time)
t91x_board.uart.write("modem_trace stop\r\n")
log_len = t91x_board.uart.wait_for_str("Modem trace stop command issued. This may produce a few more traces. Please wait at least 1 second before attempting to read out trace data.", timeout=10)
time.sleep(1)
t91x_board.uart.write("modem_trace size\r\n")
t91x_board.uart.wait_for_str("Modem trace data size:", timeout=5, start_pos=log_len)
modem_trace_size_2 = t91x_board.uart.extract_value(r"Modem trace data size: (\d+) bytes", start_pos=log_len)
assert modem_trace_size_2
assert int(modem_trace_size_2[0]) > int(modem_trace_size_1[0])

logger.info("Dumping modem traces to uart1")
uart1_before_dump = t91x_traces.trace.get_size()
t91x_board.uart.write("modem_trace dump_uart\r\n")
t91x_board.uart.wait_for_str_ordered(["Reading out", "bytes of trace data"], timeout=5)
modem_trace_size_to_read = t91x_board.uart.extract_value(r"Reading out (\d+) bytes of trace data")
assert modem_trace_size_to_read
assert int(modem_trace_size_to_read[0]) >= int(modem_trace_size_2[0])
start_t = time.time()
while True:
uart1_size = t91x_traces.trace.get_size()
logger.debug(f"Uart1 log size {uart1_size} bytes after {time.time()-start_t} seconds")
if uart1_size - uart1_before_dump == int(modem_trace_size_to_read[0]):
break
if start_t + trace_read_timeout < time.time():
if abs(uart1_size - uart1_before_dump - int(modem_trace_size_to_read[0])) < treashold_lost_traces:
logger.warning(f"Uart1 log size {uart1_size}, expected {int(modem_trace_size_to_read[0]) + uart1_before_dump}\n \
uart1 log size before dump: {uart1_before_dump}")
break
raise AssertionError(f"Timeout waiting for uart1 log size to match the expected size \n \
Expected size: {int(modem_trace_size_to_read[0]) + uart1_before_dump} bytes \n \
Actual size: {uart1_size} bytes \n \
uart1 log size before dump: {uart1_before_dump} bytes")
time.sleep(1)
modem_trace_size_read = t91x_board.uart.extract_value(r"Total trace bytes read from flash: (\d+)")
assert modem_trace_size_read
assert int(modem_trace_size_read[0]) == int(modem_trace_size_to_read[0])

0 comments on commit af1ba4e

Please sign in to comment.