From af1ba4eade5c3d8a18edea9defa0f9486b98b90d Mon Sep 17 00:00:00 2001 From: David Dilner Date: Thu, 7 Nov 2024 14:44:22 +0100 Subject: [PATCH] tests: on_target: adding modem trace test Signed-off-by: David Dilner --- .github/workflows/on_target.yml | 10 ++++ tests/on_target/tests/conftest.py | 15 +++++- tests/on_target/tests/pytest.ini | 1 + tests/on_target/tests/test_traces.py | 71 ++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 tests/on_target/tests/test_traces.py diff --git a/.github/workflows/on_target.yml b/.github/workflows/on_target.yml index 9b9389de..3ccdd844 100644 --- a/.github/workflows/on_target.yml +++ b/.github/workflows/on_target.yml @@ -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/pytest-results-action@v0.7.1 diff --git a/tests/on_target/tests/conftest.py b/tests/on_target/tests/conftest.py index fd848038..d1684a4e 100644 --- a/tests/on_target/tests/conftest.py +++ b/tests/on_target/tests/conftest.py @@ -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()) @@ -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) @@ -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 diff --git a/tests/on_target/tests/pytest.ini b/tests/on_target/tests/pytest.ini index 9b3e6386..8ecdf2af 100644 --- a/tests/on_target/tests/pytest.ini +++ b/tests/on_target/tests/pytest.ini @@ -9,3 +9,4 @@ markers = fullmfw_fota: fullmfw fota tests wifi: wifi location tests gnss: device used for GNSS tests + traces: modem trace tests diff --git a/tests/on_target/tests/test_traces.py b/tests/on_target/tests/test_traces.py new file mode 100644 index 00000000..db2eab48 --- /dev/null +++ b/tests/on_target/tests/test_traces.py @@ -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])