|
9 | 9 | """ |
10 | 10 | import infamy |
11 | 11 | import infamy.gps as gps |
12 | | -from infamy import until |
| 12 | +from infamy.util import until, wait_boot |
13 | 13 |
|
14 | 14 | lat=27.9881 |
15 | 15 | lon=86.9250 |
|
19 | 19 | def _near(a, b, tol): |
20 | 20 | return abs(a - b) <= tol |
21 | 21 |
|
| 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 | + |
22 | 47 | with infamy.Test() as test: |
23 | 48 | with test.step("Set up topology and attach to target DUT"): |
24 | 49 | env = infamy.Env() |
@@ -54,28 +79,21 @@ def _near(a, b, tol): |
54 | 79 | until(lambda: gps.has_fix(target), attempts=60) |
55 | 80 |
|
56 | 81 | with test.step("Verify the position is near the coordinates you test with"): |
57 | | - state = gps.get_gps_state(target) |
| 82 | + verify_position(target) |
58 | 83 |
|
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): |
71 | 89 | test.fail() |
| 90 | + target = env.attach("target", "mgmt", test_reset=False) |
72 | 91 |
|
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) |
80 | 94 |
|
| 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) |
81 | 99 | test.succeed() |
0 commit comments