Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location WiFi - twister+pytest test for native_sim and playback data #725

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/zephyr/location/wifi/pytest/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2025 Golioth, Inc.
#
# SPDX-License-Identifier: Apache-2.0

import pytest

@pytest.fixture(scope='session')
def anyio_backend():
return 'trio'
43 changes: 43 additions & 0 deletions examples/zephyr/location/wifi/pytest/test_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2025 Golioth, Inc.
#
# SPDX-License-Identifier: Apache-2.0

from collections import namedtuple
import re

from twister_harness.device.device_adapter import DeviceAdapter
from twister_harness.helpers.shell import Shell

import pytest


pytestmark = pytest.mark.anyio


async def test_location_wifi(shell: Shell, dut: DeviceAdapter, device):
# Set Golioth credential

golioth_cred = (await device.credentials.list())[0]
shell.exec_command(f"settings set golioth/psk-id {golioth_cred.identity}")
shell.exec_command(f"settings set golioth/psk {golioth_cred.key}")

# Wait for Golioth connection

dut.readlines_until(regex=".*Golioth CoAP client connected", timeout=90.0)

# Verify position

pattern = re.compile(r".* (?P<lon>\d+\.\d+) (?P<lat>\d+\.\d+) \((?P<acc>\d+)\)")
Position = namedtuple('Position', ('lon', 'lat', 'acc'))

positions = []
for _ in range(5):
lines = dut.readlines_until(regex=pattern, timeout=10.0)
m = pattern.search(lines[-1])
pos = Position(*[float(m[p]) for p in ['lon', 'lat', 'acc']])
positions.append(pos)

for pos in positions:
assert pos.lon == pytest.approx(50.663974800, 1e-3)
assert pos.lat == pytest.approx(17.942322850, 1e-3)
assert pos.acc < 1000
11 changes: 9 additions & 2 deletions examples/zephyr/location/wifi/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ sample:
description: Location WiFi
name: location wifi
common:
build_only: true
tags:
- golioth
- location
- socket
tests:
sample.golioth.location_wifi:
build_only: true
platform_allow:
- esp32_devkitc_wrover/esp32/procpu
- nrf52840dk/nrf52840
sample.golioth.location_wifi.playback:
harness: pytest
extra_args: EXTRA_CONF_FILE="../../common/runtime_settings.conf"
extra_configs:
- CONFIG_GOLIOTH_SAMPLE_TWISTER_TEST=y
- arch:posix:CONFIG_NATIVE_UART_0_ON_STDINOUT=y
platform_allow:
- native_sim
- native_sim/native/64
- nrf52840dk/nrf52840
Loading