From a7b8429062cb1069b06829a9fac0b8640c27bd4f Mon Sep 17 00:00:00 2001 From: David Dilner Date: Tue, 22 Oct 2024 10:56:52 +0200 Subject: [PATCH] test: on_target: add location tests adds location tests for Wi-Fi and GNSS. GNSS not active yet. Signed-off-by: David Dilner --- .github/workflows/on_target.yml | 10 +++++ tests/on_target/tests/pytest.ini | 2 + tests/on_target/tests/test_location.py | 54 ++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/on_target/tests/test_location.py diff --git a/.github/workflows/on_target.yml b/.github/workflows/on_target.yml index 820a806e..4e08fd9c 100644 --- a/.github/workflows/on_target.yml +++ b/.github/workflows/on_target.yml @@ -211,6 +211,16 @@ jobs: NRF91_CUSTOM_APP_ZIP: artifacts/usb_uart_bridge_app.zip LOG_FILENAME: oob_conn_bridge_test_log + - name: Run Wi-Fi location tests + working-directory: thingy91x-oob/tests/on_target + run: | + mkdir -p results + pytest -s -v -m "dut1 and wifi" \ + --junit-xml=results/test-results-wifi-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/pytest.ini b/tests/on_target/tests/pytest.ini index 09109b1c..30f15ce9 100644 --- a/tests/on_target/tests/pytest.ini +++ b/tests/on_target/tests/pytest.ini @@ -5,3 +5,5 @@ markers = uart: uart tests fota: standard fota tests fullmfw_fota: fullmfw fota tests + wifi: wifi location tests + gnss: device used for GNSS tests diff --git a/tests/on_target/tests/test_location.py b/tests/on_target/tests/test_location.py new file mode 100644 index 00000000..603a78ac --- /dev/null +++ b/tests/on_target/tests/test_location.py @@ -0,0 +1,54 @@ +########################################################################################## +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +########################################################################################## + +import pytest +import time +import os +import re +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() + +@pytest.mark.wifi +@pytest.mark.dut1 +def test_wifi_location(t91x_board, hex_file): + run_location(t91x_board, hex_file, location_method="Wi-Fi") + +@pytest.mark.gnss +def test_gnss_location(t91x_board, hex_file): + run_location(t91x_board, hex_file, location_method="GNSS") + +def run_location(t91x_board, hex_file, location_method): + flash_device(os.path.abspath(hex_file)) + time.sleep(5) + t91x_board.uart.xfactoryreset() + patterns_cloud_connection = [ + "Network connectivity established", + "Connected to Cloud" + ] + patterns_location = [ + f"location_core_location_get_pos: Requesting location with '{location_method}' method", + f"location: LOCATION_REQ_MODE_ALL: acquired location using '{location_method}'", + "location_event_handler: Got location: lat:", + "blocked_run: Location search done",] + + # Cloud connection + t91x_board.uart.flush() + reset_device() + t91x_board.uart.wait_for_str(patterns_cloud_connection, timeout=60) + + # Location + t91x_board.uart.wait_for_str(patterns_location, timeout=180) + + # Extract coordinates from UART output + location_pattern = re.compile(r"location_event_handler: Got location: lat: ([\d.]+), lon: ([\d.]+), acc: ([\d.]+)") + match = location_pattern.search(t91x_board.uart.log) + assert match, "Failed to extract coordinates from UART output" + lat, lon, _ = match.groups() + assert abs(float(lat) - 61.5) < 2 and abs(float(lon) - 10.5) < 1, \ + f"Coordinates ({lat}, {lon}) are not in the same part of the world as the test servers."