Fix GPS modem selection and add a GPS-only time source
This commit is contained in:
1 parent
eaf08abcd4
commit
a50c01b416
18 files changed
+682
-16
No files matched your search
@@ -177,6 +177,10 @@ chmod 0755 "$TARGET_ROOTFS/usr/bin/bananarchy-idle-blank.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-idle-lock.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-screen-wake.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-battery-charge-event.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-gps-modem.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-gps-time-sync.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-sync-gps-time.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-gps" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-time-sync.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-sync-net-time.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-network-event.sh" \
|
||||
|
||||
@@ -1205,6 +1205,54 @@ if [ -x "$BASE_DIR/scripts/test-battery-charge-event.py" ] && \
|
||||
fail "host charger plug/unplug event test failed"
|
||||
fi
|
||||
|
||||
echo "[check] GPS-only time source..."
|
||||
GPS_TIME="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-gps-time-sync.sh"
|
||||
GPS_MODEM="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-gps-modem.sh"
|
||||
GPS_WRAPPER="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-sync-gps-time.sh"
|
||||
GPS_CLI="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-gps"
|
||||
GPS_SRC="$BASE_DIR/src/dwm-plugins/gps_plugin.cpp"
|
||||
DMENU_SRC="$BASE_DIR/src/sxmo-dmenu/dmenu.c"
|
||||
for f in "$GPS_TIME" "$GPS_MODEM" "$GPS_WRAPPER" "$GPS_CLI" \
|
||||
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-time-sync.sh"; do
|
||||
if [ ! -x "$f" ]; then
|
||||
fail "${f#$BASE_DIR/} is missing or not executable"
|
||||
fi
|
||||
if ! sh -n "$f" 2>/dev/null; then
|
||||
fail "shell syntax: ${f#$BASE_DIR/}"
|
||||
fi
|
||||
done
|
||||
for token in 'bananarchy-gps-modem.sh' 'gpsModemArg' \
|
||||
'--location-enable-3gpp'; do
|
||||
if ! grep -qF -- "$token" "$GPS_SRC"; then
|
||||
fail "gps_plugin.cpp is missing the GPS modem fix: $token"
|
||||
fi
|
||||
done
|
||||
for token in 'Sync GPS time' '@toggle:time_source' 'read_time_source'; do
|
||||
if ! grep -qF "$token" "$DMENU_SRC"; then
|
||||
fail "dmenu.c is missing the GPS time source option: $token"
|
||||
fi
|
||||
done
|
||||
if ! grep -qF 'GPS is the sole time source' \
|
||||
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-time-sync.sh"; then
|
||||
fail "network time helper no longer honours the GPS-only source"
|
||||
fi
|
||||
if ! strings "$BASE_DIR/prebuilt/sxmo-x11/usr/lib/dwm/plugins/gps.so" 2>/dev/null | \
|
||||
grep -qF 'bananarchy-gps-modem.sh'; then
|
||||
fail "shipped gps.so is stale: rebuild with scripts/build-sxmo-x11.sh"
|
||||
fi
|
||||
if ! strings "$BASE_DIR/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dmenu.so" 2>/dev/null | \
|
||||
grep -qF 'Sync GPS time'; then
|
||||
fail "shipped dmenu.so is stale: rebuild with scripts/build-sxmo-x11.sh"
|
||||
fi
|
||||
if ! grep -q 'bananarchy-gps-time-sync.sh' "$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then
|
||||
fail "apply-bananarchy-overlay.sh no longer installs the GPS time helper"
|
||||
fi
|
||||
if [ -x "$BASE_DIR/scripts/test-gps-time-sync.py" ] && \
|
||||
command -v python3 >/dev/null 2>&1 && \
|
||||
! "$BASE_DIR/scripts/test-gps-time-sync.py" >/dev/null 2>&1; then
|
||||
fail "host GPS-only time source test failed"
|
||||
fi
|
||||
|
||||
if [ "$FAILURES" -ne 0 ]; then
|
||||
echo "[check] $FAILURES check(s) failed."
|
||||
exit 1
|
||||
|
||||
Executable
+187
@@ -0,0 +1,187 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Host integration test for the GPS-only datetime source.
|
||||
|
||||
Runs the real shell helpers with stubbed mmcli/date/chronyd, verifying that a
|
||||
GNSS fix sets the clock without ever consulting NTP, and that the network time
|
||||
helper stays inert while the GPS-only source is selected.
|
||||
"""
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
BASE = pathlib.Path(__file__).resolve().parent.parent
|
||||
BIN = BASE / "overlay/rootfs/usr/bin"
|
||||
GPS_TIME = BIN / "bananarchy-gps-time-sync.sh"
|
||||
GPS_WRAPPER = BIN / "bananarchy-sync-gps-time.sh"
|
||||
NET_TIME = BIN / "bananarchy-time-sync.sh"
|
||||
GPS_MODEM = BIN / "bananarchy-gps-modem.sh"
|
||||
GPS_CLI = BIN / "bananarchy-gps"
|
||||
|
||||
STUBS = {
|
||||
"date": '''#!/bin/sh
|
||||
if [ "$1" = "-u" ] && [ "$2" = "-s" ]; then
|
||||
printf '%s\\n' "$3" >> "$FAKE_ROOT/date.log"
|
||||
exit 0
|
||||
fi
|
||||
if [ "$1" = "+%s" ]; then
|
||||
n=0
|
||||
[ -r "$FAKE_ROOT/epoch" ] && read -r n < "$FAKE_ROOT/epoch"
|
||||
n=$((n + 1))
|
||||
printf '%s\\n' "$n" > "$FAKE_ROOT/epoch"
|
||||
printf '%s\\n' "$n"
|
||||
exit 0
|
||||
fi
|
||||
exit 0
|
||||
''',
|
||||
"mmcli": '''#!/bin/sh
|
||||
case "$*" in
|
||||
*--location-get*) cat "$FAKE_ROOT/location" ;;
|
||||
*-L*) printf ' /org/freedesktop/ModemManager1/Modem/0 [QUALCOMM]\\n' ;;
|
||||
*--location-status*) printf ' capabilities: 3gpp-lac-ci, gps-raw, gps-nmea\\n' ;;
|
||||
esac
|
||||
exit 0
|
||||
''',
|
||||
"bananarchy-gps-modem.sh": '''#!/bin/sh
|
||||
case "${1:-path}" in
|
||||
path|enable|disable) printf '/org/freedesktop/ModemManager1/Modem/0\\n' ;;
|
||||
status) printf 'modem=/org/freedesktop/ModemManager1/Modem/0\\n' ;;
|
||||
esac
|
||||
exit 0
|
||||
''',
|
||||
"rc-service": '''#!/bin/sh
|
||||
printf '%s\\n' "$*" >> "$FAKE_ROOT/rc.log"
|
||||
exit 0
|
||||
''',
|
||||
"chronyc": '''#!/bin/sh
|
||||
printf 'chronyc %s\\n' "$*" >> "$FAKE_ROOT/chronyc.log"
|
||||
exit 0
|
||||
''',
|
||||
"bananarchy-net-sync-stub": '''#!/bin/sh
|
||||
printf 'net-sync %s\\n' "$*" >> "$FAKE_ROOT/net.log"
|
||||
exit 0
|
||||
''',
|
||||
"hwclock": '#!/bin/sh\nexit 0\n',
|
||||
"sleep": '#!/bin/sh\nexit 0\n',
|
||||
"su": '#!/bin/sh\nexit 0\n',
|
||||
"notify-send": '''#!/bin/sh
|
||||
printf '%s\\n' "$*" >> "$FAKE_ROOT/notify.log"
|
||||
exit 0
|
||||
''',
|
||||
}
|
||||
|
||||
ISO_SAMPLE = (
|
||||
"modem.location.gps.utc : '2026-11-10T12:34:56Z'\n"
|
||||
"modem.location.gps.latitude : 50.4501\n"
|
||||
"modem.location.gps.longitude : 30.5234\n"
|
||||
)
|
||||
RMC_SAMPLE = (
|
||||
"modem.location.gps.nmea.value : "
|
||||
"$GNRMC,123456.00,A,5000.0000,N,03000.0000,E,0.0,0.0,101126,,,A\n"
|
||||
)
|
||||
|
||||
|
||||
def fail(message):
|
||||
sys.stderr.write("FAIL: %s\n" % message)
|
||||
return 1
|
||||
|
||||
|
||||
def main():
|
||||
for path in (GPS_TIME, GPS_WRAPPER, NET_TIME, GPS_MODEM, GPS_CLI):
|
||||
if not path.is_file():
|
||||
return fail("missing %s" % path)
|
||||
if path.suffix == ".sh" or path.name in ("bananarchy-gps", "bananarchy-time-sync.sh"):
|
||||
if subprocess.run(["sh", "-n", str(path)]).returncode:
|
||||
return fail("shell syntax: %s" % path.name)
|
||||
with tempfile.TemporaryDirectory(prefix="bananarchy-gps-time-") as tmp:
|
||||
root = pathlib.Path(tmp)
|
||||
bindir = root / "bin"
|
||||
home = root / "home"
|
||||
(home / ".config/sxmo").mkdir(parents=True)
|
||||
bindir.mkdir()
|
||||
for name, body in STUBS.items():
|
||||
target = bindir / name
|
||||
target.write_text(body, encoding="utf-8")
|
||||
target.chmod(0o755)
|
||||
env = dict(os.environ)
|
||||
env.update({
|
||||
"PATH": str(bindir) + os.pathsep + os.environ["PATH"],
|
||||
"FAKE_ROOT": str(root),
|
||||
"HOME": str(home),
|
||||
"BANANARCHY_TIME_SOURCE_FILE": str(home / ".config/sxmo/time_source"),
|
||||
"BANANARCHY_GPS_TIME_RUNDIR": str(root / "run"),
|
||||
"BANANARCHY_GPS_TIME_NO_ESCALATION": "1",
|
||||
"BANANARCHY_TIME_SYNC_NO_ESCALATION": "1",
|
||||
"BANANARCHY_GPS_TIME_TIMEOUT": "5",
|
||||
"BANANARCHY_STATUS_REFRESH": "true",
|
||||
"BANANARCHY_GPS_MODEM": str(bindir / "bananarchy-gps-modem.sh"),
|
||||
"BANANARCHY_MMCLI": str(bindir / "mmcli"),
|
||||
"BANANARCHY_NET_SYNC": str(bindir / "bananarchy-net-sync-stub"),
|
||||
"BANANARCHY_GPS_TIME_HELPER": str(GPS_TIME),
|
||||
})
|
||||
|
||||
def run(script, *args):
|
||||
return subprocess.run(["sh", str(script), *args], env=env,
|
||||
capture_output=True, text=True)
|
||||
|
||||
def text(name):
|
||||
p = root / name
|
||||
return p.read_text() if p.exists() else ""
|
||||
|
||||
(root / "location").write_text(ISO_SAMPLE, encoding="utf-8")
|
||||
if run(GPS_TIME, "get").stdout.strip() != "network":
|
||||
return fail("default time source is not network")
|
||||
res = run(GPS_TIME, "source", "gps")
|
||||
if "Time source: gps" not in res.stdout or \
|
||||
(home / ".config/sxmo/time_source").read_text().strip() != "gps":
|
||||
return fail("cannot select the GPS-only time source")
|
||||
if "chronyd stop" not in text("rc.log"):
|
||||
return fail("GPS-only source did not stop chronyd")
|
||||
print("[ok] source: gps disables chronyd")
|
||||
|
||||
res = run(GPS_TIME, "sync")
|
||||
if "GPS time synced: 2026-11-10 12:34:56 UTC" not in res.stdout:
|
||||
return fail("ISO GPS UTC did not set the clock: %r %r" %
|
||||
(res.stdout, res.stderr))
|
||||
if "2026-11-10 12:34:56" not in text("date.log"):
|
||||
return fail("date -u -s was not called with the GNSS timestamp")
|
||||
print("[ok] sync: ModemManager GPS UTC sets the clock")
|
||||
|
||||
(root / "location").write_text(RMC_SAMPLE, encoding="utf-8")
|
||||
res = run(GPS_TIME, "sync")
|
||||
if "GPS time synced: 2026-11-10 12:34:56 UTC" not in res.stdout:
|
||||
return fail("RMC fix did not set the clock: %r %r" %
|
||||
(res.stdout, res.stderr))
|
||||
print("[ok] sync: RMC sentence fallback sets the clock")
|
||||
|
||||
# NTP must stay completely unused while the GPS source is selected.
|
||||
for action in ("boot", "network-up", "force", "sync"):
|
||||
run(NET_TIME, action)
|
||||
if text("chronyc.log"):
|
||||
return fail("network time helper consulted chronyd in GPS-only mode")
|
||||
print("[ok] network time helper stays inert in GPS-only mode")
|
||||
|
||||
res = run(GPS_WRAPPER)
|
||||
if res.returncode or "GPS time synced" not in text("notify.log"):
|
||||
return fail("Config -> Sync GPS time did not notify the user")
|
||||
print("[ok] user wrapper reports the GPS sync result")
|
||||
|
||||
res = run(GPS_TIME, "source", "network")
|
||||
if "Time source: network" not in res.stdout or \
|
||||
"chronyd start" not in text("rc.log") or \
|
||||
"net-sync force" not in text("net.log"):
|
||||
return fail("switching back to network time did not restore NTP")
|
||||
print("[ok] source: network restores chronyd and NTP")
|
||||
|
||||
# The GPS CLI resolves the modem through the shared helper.
|
||||
res = run(GPS_CLI, "status")
|
||||
if "Modem : /org/freedesktop/ModemManager1/Modem/0" not in res.stdout:
|
||||
return fail("bananarchy-gps did not use the resolved modem path")
|
||||
print("[ok] CLI: GPS status uses the resolved modem")
|
||||
print("GPS-only time source: all checks passed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user