Skip to content

Commit 06f049a

Browse files
committed
test: gps_simple: wait for full position data before verify_position()
has_fix() only checks that fix-mode is set (2d/3d), but altitude and other fields may not yet be populated in the operational datastore when gpsd is still processing its first NMEA cycles after boot. Calling verify_position() immediately after has_fix() passes can therefore race and fail with: KeyError: 'altitude' This manifests reliably on the second GPS receiver (gps1) after reboot, because it is initialized slightly later than gps0 and hits the window where fix-mode is set but altitude has not yet appeared. not ok 11 - Verify gps1 position is near the coordinates # Traceback (most recent call last): # File "test/case/hardware/gps_simple/test.py", line 29, in verify_position # alt = float(state["altitude"]) # ~~~~~^^^^^^^^^^^^ # KeyError: 'altitude' Add has_position() to infamy/gps.py, which gates on fix-mode AND all position fields (latitude, longitude, altitude, satellites-used) being present. Replace the has_fix() polls in both the pre- and post-reboot verify steps with has_position(). Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 1c6c772 commit 06f049a

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

test/case/hardware/gps_simple/test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def verify_position(target, name="gps0"):
8585
until(lambda: gps.is_activated(target, "gps1"), attempts=500)
8686

8787
with test.step("Verify both GPS receivers have a fix"):
88-
until(lambda: gps.has_fix(target, "gps0"), attempts=60)
89-
until(lambda: gps.has_fix(target, "gps1"), attempts=60)
88+
until(lambda: gps.has_position(target, "gps0"), attempts=60)
89+
until(lambda: gps.has_position(target, "gps1"), attempts=60)
9090

9191
with test.step("Verify gps0 position is near the coordinates"):
9292
verify_position(target, "gps0")
@@ -107,8 +107,8 @@ def verify_position(target, name="gps0"):
107107
until(lambda: gps.is_activated(target, "gps1"), attempts=500)
108108

109109
with test.step("Verify both GPS receivers have a fix"):
110-
until(lambda: gps.has_fix(target, "gps0"), attempts=60)
111-
until(lambda: gps.has_fix(target, "gps1"), attempts=60)
110+
until(lambda: gps.has_position(target, "gps0"), attempts=60)
111+
until(lambda: gps.has_position(target, "gps1"), attempts=60)
112112

113113
with test.step("Verify gps0 position is near the coordinates"):
114114
verify_position(target, "gps0")

test/infamy/gps.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,13 @@ def has_fix(target, name="gps0"):
208208
if not state:
209209
return False
210210
return state.get("fix-mode") in ("2d", "3d")
211+
212+
213+
def has_position(target, name="gps0"):
214+
"""Check if GPS has a fix and all position fields are populated."""
215+
state = get_gps_state(target, name)
216+
if not state:
217+
return False
218+
if state.get("fix-mode") not in ("2d", "3d"):
219+
return False
220+
return all(k in state for k in ("latitude", "longitude", "altitude", "satellites-used"))

0 commit comments

Comments
 (0)