Skip to content

Commit 17dfa64

Browse files
committed
test: gps_simple
1 parent 49a0c6c commit 17dfa64

1 file changed

Lines changed: 39 additions & 21 deletions

File tree

  • test/case/hardware/gps_simple

test/case/hardware/gps_simple/test.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010
import infamy
1111
import infamy.gps as gps
12-
from infamy import until
12+
from infamy.util import until, wait_boot
1313

1414
lat=27.9881
1515
lon=86.9250
@@ -19,6 +19,31 @@
1919
def _near(a, b, tol):
2020
return abs(a - b) <= tol
2121

22+
def verify_position(target):
23+
state = gps.get_gps_state(target)
24+
25+
try:
26+
lat = float(state["latitude"])
27+
lon = float(state["longitude"])
28+
alt = float(state["altitude"])
29+
except (KeyError, TypeError, ValueError):
30+
test.fail()
31+
32+
if not _near(lat, lat, 1e-4):
33+
test.fail()
34+
if not _near(lon, lon, 1e-4):
35+
test.fail()
36+
if not _near(alt, alt, 0.2):
37+
test.fail()
38+
39+
try:
40+
sat_used = int(state["satellites-used"])
41+
except (KeyError, TypeError, ValueError):
42+
test.fail()
43+
44+
if sat_used != 8:
45+
test.fail()
46+
2247
with infamy.Test() as test:
2348
with test.step("Set up topology and attach to target DUT"):
2449
env = infamy.Env()
@@ -54,28 +79,21 @@ def _near(a, b, tol):
5479
until(lambda: gps.has_fix(target), attempts=60)
5580

5681
with test.step("Verify the position is near the coordinates you test with"):
57-
state = gps.get_gps_state(target)
82+
verify_position(target)
5883

59-
try:
60-
lat = float(state["latitude"])
61-
lon = float(state["longitude"])
62-
alt = float(state["altitude"])
63-
except (KeyError, TypeError, ValueError):
64-
test.fail()
65-
66-
if not _near(lat, lat, 1e-4):
67-
test.fail()
68-
if not _near(lon, lon, 1e-4):
69-
test.fail()
70-
if not _near(alt, alt, 0.2):
84+
with test.step("Save the configuration to startup configuration and reboot"):
85+
target.startup_override()
86+
target.copy("running", "startup")
87+
target.reboot()
88+
if not wait_boot(target, env):
7189
test.fail()
90+
target = env.attach("target", "mgmt", test_reset=False)
7291

73-
try:
74-
sat_used = int(state["satellites-used"])
75-
except (KeyError, TypeError, ValueError):
76-
test.fail()
77-
78-
if sat_used != 8:
79-
test.fail()
92+
with test.step("Verify GPS is activated"):
93+
until(lambda: gps.is_activated(target), attempts=500)
8094

95+
with test.step("Verify GPS has a fix"):
96+
until(lambda: gps.has_fix(target), attempts=60)
97+
with test.step("Verify the position is near the coordinates you test with"):
98+
verify_position(target)
8199
test.succeed()

0 commit comments

Comments
 (0)