Skip to content

Commit e611e83

Browse files
tests: on_target: add location test
Add location test on target. Signed-off-by: Giacomo Dematteis <giacomo.dematteis@nordicsemi.no>
1 parent bca2f9a commit e611e83

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
##########################################################################################
2+
# Copyright (c) 2024 Nordic Semiconductor
3+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
4+
##########################################################################################
5+
6+
import os
7+
from utils.flash_tools import flash_device, reset_device
8+
import sys
9+
import pytest
10+
from utils.flash_tools import flash_device, reset_device
11+
12+
sys.path.append(os.getcwd())
13+
from utils.logger import get_logger
14+
15+
logger = get_logger()
16+
17+
def test_wifi_location(t91x_board, hex_file):
18+
'''
19+
Test that the device can get location using Wi-Fi
20+
'''
21+
run_location(t91x_board, hex_file, location_method="Wi-Fi")
22+
23+
@pytest.mark.skip(reason="GNSS location is not supported on this device")
24+
def test_gnss_location(t91x_board, hex_file):
25+
'''
26+
Test that the device can get location using GNSS
27+
'''
28+
run_location(t91x_board, hex_file, location_method="GNSS")
29+
30+
def run_location(t91x_board, hex_file, location_method):
31+
flash_device(os.path.abspath(hex_file))
32+
t91x_board.uart.xfactoryreset()
33+
patterns_cloud_connection = [
34+
"Network connectivity established",
35+
"Connected to Cloud"
36+
]
37+
38+
patterns_location = ["Wi-Fi and cellular methods combined"] if location_method == "Wi-Fi" else []
39+
patterns_location = patterns_location + [
40+
"location_event_handler: Got location: lat:",
41+
"Location search done"]
42+
43+
# Cloud connection
44+
t91x_board.uart.flush()
45+
reset_device()
46+
t91x_board.uart.wait_for_str(patterns_cloud_connection, timeout=120)
47+
48+
# Location
49+
t91x_board.uart.wait_for_str(patterns_location, timeout=180)
50+
51+
# Extract coordinates from UART output
52+
values = t91x_board.uart.extract_value( \
53+
r"location_event_handler: Got location: lat: ([\d.]+), lon: ([\d.]+), acc: ([\d.]+), method: ([\d.]+)")
54+
assert values
55+
lat, lon, acc, method = values
56+
assert abs(float(lat) - 61.5) < 2 and abs(float(lon) - 10.5) < 1
57+
method = int(method)
58+
expected_method = 4 if location_method == "Wi-Fi" else 1
59+
assert method == expected_method

0 commit comments

Comments
 (0)