Files
bananarchy/scripts/test-idle-blank-lock.py
T
Luxferre 2857ef4374 Make 2720 Flip lid switching instant and route closed-flip events to the cover
The lid daemon re-derived "observed" from a stale EV_SW mask on every 100 ms
iteration and only read the raw hall lines every 200 ms, so the candidate
oscillated and the 80 ms debounce almost never completed. A controlled hall
transition on the live phone took over 2.2 s to blank and lock the main panel.
The hall reading is now sticky, every EV_SW edge forces an immediate hall
re-read, the loop and debounce are 20 ms, and the daemon writes the lid state,
lock flag, Sxmo state and both backlights synchronously in C before spawning
hooks. A direct xset DPMS off/on stops or resumes Xorg's SPI flushes at once.
bananarchy-lid-state.sh guards the asynchronous hooks by lid state and a
transition generation counter, so a late screenoff cannot re-lock a flip that
was just opened.

bananarchy-lid-gate.sh now gates sxmo_wm.sh display on, the screen-wake
helper, the backlight udev helper, sxmo_state.sh set unlock (dwm calls it
directly) and both input handler copies. While the flip is closed it blocks
the main panel and keypad backlight, forces brightness/kbd/DPMS off against
stray writes, and forwards a WAKE datagram to the cover display. Ring,
notification and call-state hooks publish to the cover, and the cover daemon
gained WAKE, event wakes, immunity to repeated LID CLOSED rebroadcasts and a
bounded retry for a DPMS-deferred draw.

Live verification with controlled hall transitions and uinput switch/key
injection: close blanks and locks in ~45-90 ms (hall-poll fallback
~100-220 ms), open restores brightness, keypad backlight, unlock and DPMS in
~10-130 ms with no stale-hook re-lock. All three external keys and an
incoming call leave brightness=0, kbd_backlight=0 and DPMS=Off while the
cover reports backend=spidev visible=1; opening returns mux=open.

Rebuilt the a1108/dejavu nokia-beatles image and pinned the verified hash
0f33aa6e9fc70022574b453aaafb9307c4d185431d3be272782c8403dd0fb291 in
check-rebuild.sh. e2fsck -fn passed on both partitions, debugfs confirms
twelve updated rootfs files byte-for-byte, and the bootfs sync, boot image
check, artifact sync, host tests and rebuild preflight all pass.

This is an intermediate checkpoint: eyes-on cover illumination and the
remaining polarity/CS fixes are still required.
2026-11-10 20:23:06 +02:00

193 lines
6.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""Host integration test for idle-blank -> screenlock daemon wiring.
Runs the real shell helpers against stubbed sxmo_wm.sh / sxmo_state.sh and a
temporary home, so the lock arming, cancellation and wake paths are verified
without an X session or a phone.
"""
import os
import pathlib
import subprocess
import sys
import tempfile
import time
BASE = pathlib.Path(__file__).resolve().parent.parent
BIN = BASE / "overlay/rootfs/usr/bin"
LOCK = BIN / "bananarchy-idle-lock.sh"
BLANK = BIN / "bananarchy-idle-blank.sh"
WAKE = BIN / "bananarchy-screen-wake.sh"
UNLOCK_HOOK = BASE / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_unlock.sh"
WM_STUB = '''#!/bin/sh
if [ "$1" = "display" ]; then
case "$2" in
off) printf 'off\\n' > "$FAKE_ROOT/display_state" ;;
on) printf 'on\\n' > "$FAKE_ROOT/display_state" ;;
"") cat "$FAKE_ROOT/display_state" ;;
esac
fi
exit 0
'''
STATE_STUB = '''#!/bin/sh
printf '%s\\n' "$*" >> "$FAKE_ROOT/state.log"
exit 0
'''
def failure(message):
sys.stderr.write("FAIL: %s\n" % message)
return 1
def main():
for path in (LOCK, BLANK, WAKE, UNLOCK_HOOK):
if not path.is_file():
return failure("missing %s" % path)
if subprocess.run(["sh", "-n", str(LOCK)]).returncode or \
subprocess.run(["sh", "-n", str(BLANK)]).returncode or \
subprocess.run(["sh", "-n", str(WAKE)]).returncode:
return failure("shell syntax")
with tempfile.TemporaryDirectory(prefix="bananarchy-idle-lock-") as tmp:
root = pathlib.Path(tmp)
bindir = root / "bin"
home = root / "home"
(home / ".config/sxmo").mkdir(parents=True)
bindir.mkdir()
for name, body in (("sxmo_wm.sh", WM_STUB), ("sxmo_state.sh", STATE_STUB)):
target = bindir / name
target.write_text(body, encoding="utf-8")
target.chmod(0o755)
display = root / "display_state"
state_log = root / "state.log"
lock_flag = root / "locked"
cfg = home / ".config/sxmo/idle_lock_delay"
env = dict(os.environ)
env.update({
"HOME": str(home),
"XDG_CONFIG_HOME": str(home / ".config"),
"FAKE_ROOT": str(root),
"BANANARCHY_WM_CMD": str(bindir / "sxmo_wm.sh"),
"BANANARCHY_LID_GATE": "/bin/true",
"BANANARCHY_STATE_CMD": str(bindir / "sxmo_state.sh"),
"BANANARCHY_IDLE_LOCK_HELPER": str(LOCK),
"BANANARCHY_IDLE_LOCK_PIDFILE": str(root / "lock.pid"),
"BANANARCHY_LOCK_FLAG": str(lock_flag),
"BANANARCHY_WAKE_TS": str(root / "wake.ts"),
"BANANARCHY_IDLE_BLANK_GRACE": "0",
})
def run(script, *args):
cmd = ["sh", str(script), *args]
if os.environ.get("BANANARCHY_TEST_DEBUG"):
cmd.insert(1, "-x")
res = subprocess.run(cmd, env=env, capture_output=True, text=True)
if os.environ.get("BANANARCHY_TEST_DEBUG"):
sys.stderr.write("%s %s: %s\n" % (script.name, args, res.stderr[-1200:]))
return res
def log():
return state_log.read_text() if state_log.exists() else ""
def clear():
if state_log.exists():
state_log.unlink()
if lock_flag.exists():
lock_flag.unlink()
def dark(value=True):
display.write_text("off\n" if value else "on\n", encoding="utf-8")
# Defaults and user configuration.
dark()
if run(LOCK, "get").stdout.strip() != "30":
return failure("default lock delay is not 30 s")
if run(LOCK, "label").stdout.strip() != "30s":
return failure("default lock delay label")
if run(LOCK, "set", "off").stdout.strip() != "off" or \
run(LOCK, "label").stdout.strip() != "Off":
return failure("lock delay cannot be disabled")
if run(LOCK, "set", "bogus").returncode == 0:
return failure("invalid lock delay accepted")
if run(LOCK, "set", "0").stdout.strip() != "0":
return failure("immediate lock delay cannot be configured")
print("[ok] config: default, off, immediate and invalid values")
# Immediate arm must call the trusted screenoff transition.
clear()
run(LOCK, "arm")
if "set screenoff" not in log():
return failure("immediate arm did not trigger the screenlock daemon")
print("[ok] arm: immediate screenoff transition")
# Delayed arm must fire while the panel is still dark.
clear()
cfg.write_text("1\n", encoding="utf-8")
run(LOCK, "arm")
if "set screenoff" in log():
return failure("delayed arm locked before the deadline")
time.sleep(1.4)
if "set screenoff" not in log():
return failure("delayed arm did not trigger the screenlock daemon")
print("[ok] arm: delayed screenoff transition")
# Cancel before the deadline must prevent the lock.
clear()
run(LOCK, "arm")
run(LOCK, "cancel")
time.sleep(1.4)
if log():
return failure("cancel did not stop the pending lock")
print("[ok] cancel: pending lock stopped")
# Waking the panel before the deadline must prevent the lock.
clear()
dark()
run(LOCK, "arm")
time.sleep(0.2)
dark(False)
time.sleep(1.3)
if log():
return failure("lock fired after the panel was already awake")
print("[ok] wake: no lock after the panel is on")
# The blank handler itself must arm (and its inverse must cancel) the lock.
clear()
cfg.write_text("0\n", encoding="utf-8")
dark(False)
run(BLANK, "off")
if display.read_text().strip() != "off" or "set screenoff" not in log():
return failure("bananarchy-idle-blank.sh off did not arm the lock: "
"display=%r log=%r" % (display.read_text().strip(), log()))
print("[ok] blank: off arms the screenlock daemon")
clear()
cfg.write_text("1\n", encoding="utf-8")
dark(False)
run(BLANK, "off")
run(BLANK, "on")
time.sleep(1.4)
if log():
return failure("bananarchy-idle-blank.sh on did not cancel the lock")
print("[ok] blank: on cancels the pending lock")
# An incoming call / SMS wake must cancel the pending lock too.
clear()
dark(False)
run(BLANK, "off")
run(WAKE)
time.sleep(1.4)
if log():
return failure("bananarchy-screen-wake.sh did not cancel the lock")
if "bananarchy-idle-lock.sh cancel" not in UNLOCK_HOOK.read_text():
return failure("sxmo_hook_unlock.sh does not cancel the pending lock")
print("[ok] wake: screen-wake and unlock hook cancel the pending lock")
run(LOCK, "cancel")
print("idle blank screenlock wiring: all checks passed")
return 0
if __name__ == "__main__":
sys.exit(main())