Implement 2720 Flip cover display behaviour
This commit is contained in:
1 parent
a50c01b416
commit
ec55fb1457
20 files changed
+630
-49
No files matched your search
@@ -177,6 +177,8 @@ 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-cover-status.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-cover-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" \
|
||||
|
||||
@@ -1253,6 +1253,60 @@ if [ -x "$BASE_DIR/scripts/test-gps-time-sync.py" ] && \
|
||||
fail "host GPS-only time source test failed"
|
||||
fi
|
||||
|
||||
echo "[check] Cover display behaviour..."
|
||||
COVER_SRC="$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c"
|
||||
VOL_SRC="$BASE_DIR/src/bananarchy-daemons/bananarchy-volume-keys.c"
|
||||
COVER_CONF="$BASE_DIR/overlay/rootfs/etc/bananarchy/cover-display.conf"
|
||||
COVER_EVENT="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-cover-event.sh"
|
||||
COVER_STATUS="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-cover-status.sh"
|
||||
COVER_INIT="$BASE_DIR/overlay/rootfs/etc/init.d/bananarchy-cover-display"
|
||||
NET_EVENT="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-network-event.sh"
|
||||
for token in 'BUTTON' 'NETWORK' 'blank_timeout_ms' 'set_backlight' \
|
||||
'idle_blank_timeout' 'CLOCK_REDRAW_MS'; do
|
||||
if ! grep -qF -- "$token" "$COVER_SRC"; then
|
||||
fail "bananarchy-cover-idle.c is missing cover behaviour: $token"
|
||||
fi
|
||||
done
|
||||
for token in 'cover_button' 'lid_is_closed' 'KEY_POWER'; do
|
||||
if ! grep -qF -- "$token" "$VOL_SRC"; then
|
||||
fail "bananarchy-volume-keys.c no longer wakes the cover: $token"
|
||||
fi
|
||||
done
|
||||
if ! grep -qF 'blank_timeout = auto' "$COVER_CONF" || \
|
||||
! grep -qF 'backlight_path' "$COVER_CONF"; then
|
||||
fail "cover display config no longer shares the Screen blank timeout"
|
||||
fi
|
||||
for f in "$COVER_EVENT" "$COVER_STATUS" "$NET_EVENT" "$COVER_INIT"; do
|
||||
if ! sh -n "$f" 2>/dev/null; then
|
||||
fail "shell syntax: ${f#$BASE_DIR/}"
|
||||
fi
|
||||
done
|
||||
if [ ! -x "$COVER_STATUS" ]; then
|
||||
fail "bananarchy-cover-status.sh is missing or not executable"
|
||||
fi
|
||||
if ! grep -qF 'bananarchy-cover-status.sh' "$COVER_EVENT" || \
|
||||
! grep -qF 'BUTTON' "$COVER_EVENT" || \
|
||||
! grep -qF 'network)' "$COVER_EVENT"; then
|
||||
fail "cover event bridge lost the network/button commands"
|
||||
fi
|
||||
if ! grep -qF 'bananarchy-cover-event.sh network' "$NET_EVENT" || \
|
||||
! grep -qF 'bananarchy-cover-event.sh network' "$COVER_INIT"; then
|
||||
fail "network indicators are not published to the cover daemon"
|
||||
fi
|
||||
for f in "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle" \
|
||||
"$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-volume-keys"; do
|
||||
if ! strings "$f" 2>/dev/null | grep -qF 'BUTTON'; then
|
||||
fail "${f#$BASE_DIR/} is stale: rebuild with scripts/build-bananarchy-daemons.sh"
|
||||
fi
|
||||
done
|
||||
if [ ! -x "$BASE_DIR/scripts/test-cover-idle.py" ]; then
|
||||
fail "missing host integration test scripts/test-cover-idle.py"
|
||||
fi
|
||||
if command -v gcc >/dev/null 2>&1 && \
|
||||
! "$BASE_DIR/scripts/test-cover-idle.py" >/dev/null 2>&1; then
|
||||
fail "host cover display behaviour test failed"
|
||||
fi
|
||||
|
||||
if [ "$FAILURES" -ne 0 ]; then
|
||||
echo "[check] $FAILURES check(s) failed."
|
||||
exit 1
|
||||
|
||||
Executable
+225
@@ -0,0 +1,225 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Host integration test for the 2720 Flip cover display behaviour.
|
||||
|
||||
Compiles bananarchy-cover-idle.c on the host, runs it against a fake
|
||||
framebuffer/backlight, and drives its real IPC protocol to verify:
|
||||
- flip open => fully off (black frame, backlight 0);
|
||||
- flip closed + external BUTTON => clock, date and network indicators;
|
||||
- no button => the main Screen blank timeout blanks the cover again;
|
||||
- blank_timeout = auto follows Config -> Screen blank (0 = never).
|
||||
"""
|
||||
import hashlib
|
||||
import os
|
||||
import pathlib
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
BASE = pathlib.Path(__file__).resolve().parent.parent
|
||||
SRC = BASE / "src/bananarchy-daemons/bananarchy-cover-idle.c"
|
||||
VOL_SRC = BASE / "src/bananarchy-daemons/bananarchy-volume-keys.c"
|
||||
FB_WIDTH, FB_HEIGHT, FB_BPP = 240, 240, 32
|
||||
FRAME_SIZE = FB_WIDTH * FB_HEIGHT * (FB_BPP // 8)
|
||||
|
||||
|
||||
class Cover:
|
||||
def __init__(self, root, exe, config, main_cfg):
|
||||
self.root = root
|
||||
self.sock_path = root / "cover.sock"
|
||||
self.fb = root / "fb1"
|
||||
self.backlight = root / "backlight"
|
||||
self.fb.write_bytes(b"\x00" * FRAME_SIZE)
|
||||
self.backlight.write_text("0")
|
||||
self.env = dict(os.environ)
|
||||
self.env.update({
|
||||
"BANANARCHY_COVER_LOCK": str(root / "daemon.lock"),
|
||||
"BANANARCHY_COVER_FB_GEOM": "%d,%d,%d" % (FB_WIDTH, FB_HEIGHT, FB_BPP),
|
||||
"BANANARCHY_COVER_MAIN_BLANK_CFG": str(main_cfg),
|
||||
})
|
||||
self.proc = subprocess.Popen([str(exe), "--config", str(config)],
|
||||
env=self.env, stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL)
|
||||
self.client_path = root / "client.sock"
|
||||
if self.client_path.exists():
|
||||
self.client_path.unlink()
|
||||
self.client = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
self.client.bind(str(self.client_path))
|
||||
self.client.settimeout(2)
|
||||
deadline = time.time() + 3
|
||||
while time.time() < deadline and not self.sock_path.exists():
|
||||
time.sleep(0.05)
|
||||
|
||||
def send(self, command):
|
||||
self.client.sendto(command.encode(), str(self.sock_path))
|
||||
try:
|
||||
return self.client.recv(512).decode().strip()
|
||||
except socket.timeout:
|
||||
return ""
|
||||
|
||||
def frame(self):
|
||||
data = self.fb.read_bytes()
|
||||
return hashlib.sha256(data).hexdigest(), any(data)
|
||||
|
||||
def backlight_value(self):
|
||||
return self.backlight.read_text().strip()
|
||||
|
||||
def close(self):
|
||||
try:
|
||||
self.send("QUIT")
|
||||
except OSError:
|
||||
pass
|
||||
self.client.close()
|
||||
try:
|
||||
self.proc.wait(timeout=3)
|
||||
except subprocess.TimeoutExpired:
|
||||
self.proc.kill()
|
||||
self.proc.wait()
|
||||
if self.client_path.exists():
|
||||
self.client_path.unlink()
|
||||
|
||||
|
||||
def wait_for(predicate, timeout=3.0):
|
||||
end = time.time() + timeout
|
||||
while time.time() < end:
|
||||
if predicate():
|
||||
return True
|
||||
time.sleep(0.05)
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
if not SRC.is_file() or not VOL_SRC.is_file():
|
||||
sys.stderr.write("FAIL: missing daemon sources\n")
|
||||
return 1
|
||||
with tempfile.TemporaryDirectory(prefix="bananarchy-cover-") as tmp:
|
||||
root = pathlib.Path(tmp)
|
||||
exe = root / "cover-idle"
|
||||
build = subprocess.run(
|
||||
["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
|
||||
"-I" + str(SRC.parent), str(SRC), "-o", str(exe)],
|
||||
capture_output=True, text=True)
|
||||
if build.returncode:
|
||||
sys.stderr.write(build.stderr)
|
||||
return 1
|
||||
vbuild = subprocess.run(
|
||||
["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
|
||||
"-I" + str(VOL_SRC.parent), str(VOL_SRC), "-o", str(root / "volume-keys")],
|
||||
capture_output=True, text=True)
|
||||
if vbuild.returncode:
|
||||
sys.stderr.write(vbuild.stderr)
|
||||
return 1
|
||||
print("[ok] host build of the compiled cover and volume-key daemons")
|
||||
|
||||
main_cfg = root / "idle_blank_timeout"
|
||||
main_cfg.write_text("300\n")
|
||||
config = root / "cover.conf"
|
||||
config.write_text(
|
||||
"socket_path = %s\nfb_device = %s\nbacklight_path = %s\n"
|
||||
"brightness = 160\nblank_timeout = 2\n" %
|
||||
(root / "cover.sock", root / "fb1", root / "backlight"),
|
||||
encoding="utf-8")
|
||||
daemon = Cover(root, exe, config, main_cfg)
|
||||
try:
|
||||
if "pong" not in daemon.send("PING"):
|
||||
sys.stderr.write("FAIL: cover daemon did not answer PING\n")
|
||||
return 1
|
||||
_, lit = daemon.frame()
|
||||
if lit or daemon.backlight_value() != "0":
|
||||
sys.stderr.write("FAIL: a boot-open flip must leave the cover fully off\n")
|
||||
return 1
|
||||
print("[ok] open flip: cover is fully off")
|
||||
|
||||
daemon.send("LID CLOSED")
|
||||
if not wait_for(lambda: not daemon.frame()[1]):
|
||||
sys.stderr.write("FAIL: closing the flip did not blank the cover\n")
|
||||
return 1
|
||||
if "visible=1" in daemon.send("STATUS"):
|
||||
sys.stderr.write("FAIL: closing the flip lit the cover without a button\n")
|
||||
return 1
|
||||
print("[ok] closed flip: cover waits for an external button")
|
||||
|
||||
daemon.send("NETWORK 4G SIG75 WIFI")
|
||||
daemon.send("BATTERY 82")
|
||||
before, _ = daemon.frame()
|
||||
daemon.send("BUTTON")
|
||||
if not wait_for(lambda: daemon.frame()[1]):
|
||||
sys.stderr.write("FAIL: BUTTON did not show the clock/indicators\n")
|
||||
return 1
|
||||
if daemon.backlight_value() != "160" or "visible=1" not in daemon.send("STATUS"):
|
||||
sys.stderr.write("FAIL: BUTTON did not enable the backlight\n")
|
||||
return 1
|
||||
with_clock, _ = daemon.frame()
|
||||
if before == with_clock:
|
||||
sys.stderr.write("FAIL: no frame was drawn on BUTTON\n")
|
||||
return 1
|
||||
print("[ok] external button: clock, battery and backlight on")
|
||||
|
||||
daemon.send("NETWORK 3G SIG20")
|
||||
if not wait_for(lambda: daemon.frame()[0] != with_clock):
|
||||
sys.stderr.write("FAIL: network indicators are not rendered\n")
|
||||
return 1
|
||||
if "network=3G SIG20" not in daemon.send("STATUS"):
|
||||
sys.stderr.write("FAIL: NETWORK command was not stored\n")
|
||||
return 1
|
||||
print("[ok] network indicators are republished on the cover")
|
||||
|
||||
if not wait_for(lambda: not daemon.frame()[1], timeout=5):
|
||||
sys.stderr.write("FAIL: cover did not respect the blank timeout\n")
|
||||
return 1
|
||||
if daemon.backlight_value() != "0" or "visible=0" not in daemon.send("STATUS"):
|
||||
sys.stderr.write("FAIL: blank timeout did not switch the cover fully off "
|
||||
"(backlight=%r status=%r)\n" %
|
||||
(daemon.backlight_value(), daemon.send("STATUS")))
|
||||
return 1
|
||||
print("[ok] blank timeout: cover blanks with no further button")
|
||||
|
||||
daemon.send("BUTTON")
|
||||
wait_for(lambda: daemon.frame()[1])
|
||||
daemon.send("LID OPEN")
|
||||
if not wait_for(lambda: not daemon.frame()[1]):
|
||||
sys.stderr.write("FAIL: opening the flip did not switch the cover off\n")
|
||||
return 1
|
||||
daemon.send("BUTTON")
|
||||
time.sleep(0.3)
|
||||
if daemon.frame()[1] or "visible=1" in daemon.send("STATUS"):
|
||||
sys.stderr.write("FAIL: BUTTON was honoured while the flip was open\n")
|
||||
return 1
|
||||
print("[ok] open flip overrides BUTTON and keeps the cover off")
|
||||
finally:
|
||||
daemon.close()
|
||||
|
||||
# A second daemon follows Config -> Screen blank (auto); 0 = never blank.
|
||||
sub = root / "auto"
|
||||
sub.mkdir()
|
||||
config2 = root / "cover-auto.conf"
|
||||
config2.write_text(
|
||||
"socket_path = %s\nfb_device = %s\nbacklight_path = %s\n"
|
||||
"brightness = 160\nblank_timeout = auto\n" %
|
||||
(sub / "cover.sock", sub / "fb1", sub / "backlight"),
|
||||
encoding="utf-8")
|
||||
main_cfg.write_text("0\n")
|
||||
daemon2 = Cover(sub, exe, config2, main_cfg)
|
||||
try:
|
||||
daemon2.send("LID CLOSED")
|
||||
daemon2.send("BUTTON")
|
||||
if not wait_for(lambda: daemon2.frame()[1]):
|
||||
sys.stderr.write("FAIL: auto timeout daemon did not light the cover\n")
|
||||
return 1
|
||||
time.sleep(2.5)
|
||||
if not daemon2.frame()[1] or "visible=1" not in daemon2.send("STATUS"):
|
||||
sys.stderr.write("FAIL: Screen blank = 0 should keep the cover on\n")
|
||||
return 1
|
||||
if "blank_ms=0" not in daemon2.send("STATUS"):
|
||||
sys.stderr.write("FAIL: auto timeout did not read the main Screen blank config\n")
|
||||
return 1
|
||||
print("[ok] auto timeout follows Config -> Screen blank (0 = never)")
|
||||
finally:
|
||||
daemon2.close()
|
||||
print("cover display behaviour: all checks passed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user