- Default CPU_RPM_SLEEP=0, CPU_L2_SLEEP=0, and MODEM_DRX_MODE=0 across bananarchy-power-policy.conf, bananarchy-power-policy.sh, bananarchy-display-power-sync, and kernel patch 0010 so closed-flip incoming calls wake APSS promptly via smd-edge without AT port contention. - Serialize sxmo_modem.sh incoming/finished call checks, expire stale /tmp/sxmo_hangup_requested flags, re-verify live ModemManager call state before ringing/raising callscreen, guard idle/flip-open HANGUP_CLOSE paths in locker.so, callscreen.so, bananarchy-idle-lock.sh, and bananarchy-lid, preserve calls on flip-open (UNGRAB/RAISE), and add closed-flip cover call controls (bananarchy-cover-idle, bananarchy-cover-event.sh, bananarchy-volume-keys). - Propagate live network/manual timezone updates across statusbar, locker.so, bananarchy-cover-idle, bananarchy-dsds, callscreen.so, and bananarchy-run-aligned without reboot (scripts/test-time-timezone-sync.py), remove non-functional Logout from the Power menu, ignore post-call sxmo_calls markers, add scripts/build-dwm-plugins.sh, and update a1114 (carbonara) hashes and docs.
295 lines
10 KiB
Python
Executable File
295 lines
10 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import os
|
|
import pathlib
|
|
import shutil
|
|
import signal
|
|
import subprocess
|
|
import tempfile
|
|
import time
|
|
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parent.parent
|
|
COMMON_H = ROOT / "src" / "bananarchy-daemons" / "common.h"
|
|
RUN_ALIGNED_C = ROOT / "src" / "bananarchy-daemons" / "bananarchy-run-aligned.c"
|
|
TIME_SYNC_SH = ROOT / "overlay" / "rootfs" / "usr" / "bin" / "bananarchy-time-sync.sh"
|
|
|
|
|
|
def test_ba_refresh_tz(tmp: pathlib.Path) -> None:
|
|
src = tmp / "tz_probe.c"
|
|
bin_path = tmp / "tz_probe"
|
|
src.write_text(
|
|
'#include "common.h"\n'
|
|
'int main(void) {\n'
|
|
' char cmd[16];\n'
|
|
' time_t sample = (time_t)1700000000;\n'
|
|
' while (fgets(cmd, sizeof(cmd), stdin)) {\n'
|
|
' struct tm tm_now;\n'
|
|
' ba_refresh_tz();\n'
|
|
' localtime_r(&sample, &tm_now);\n'
|
|
' printf("%02d\\n", tm_now.tm_hour);\n'
|
|
' fflush(stdout);\n'
|
|
' }\n'
|
|
' return 0;\n'
|
|
'}\n',
|
|
encoding="utf-8",
|
|
)
|
|
subprocess.run(
|
|
[
|
|
"gcc",
|
|
"-std=c11",
|
|
"-O2",
|
|
"-Wall",
|
|
"-Wextra",
|
|
"-Werror",
|
|
f"-I{COMMON_H.parent}",
|
|
str(src),
|
|
"-o",
|
|
str(bin_path),
|
|
],
|
|
check=True,
|
|
)
|
|
|
|
lt = tmp / "localtime"
|
|
tzf = tmp / "timezone"
|
|
utc = pathlib.Path("/usr/share/zoneinfo/UTC")
|
|
ny = pathlib.Path("/usr/share/zoneinfo/America/New_York")
|
|
kyiv = pathlib.Path("/usr/share/zoneinfo/Europe/Kyiv")
|
|
assert utc.exists() and ny.exists() and kyiv.exists(), "host zoneinfo missing"
|
|
|
|
# 1) Symlink repointing including A -> B -> C -> A cycle
|
|
lt.symlink_to(utc)
|
|
tzf.write_text("UTC\n", encoding="utf-8")
|
|
env = os.environ.copy()
|
|
env["BANANARCHY_TZ_LOCALTIME"] = str(lt)
|
|
env["BANANARCHY_TZ_FILE"] = str(tzf)
|
|
env.pop("TZ", None)
|
|
|
|
proc = subprocess.Popen(
|
|
[str(bin_path)],
|
|
stdin=subprocess.PIPE,
|
|
stdout=subprocess.PIPE,
|
|
text=True,
|
|
env=env,
|
|
)
|
|
try:
|
|
def query(step_zone: pathlib.Path, label: str, symlink_mode: bool = True) -> str:
|
|
lt.unlink()
|
|
if symlink_mode:
|
|
lt.symlink_to(step_zone)
|
|
else:
|
|
shutil.copyfile(step_zone, lt)
|
|
tzf.write_text(f"{label}\n", encoding="utf-8")
|
|
assert proc.stdin is not None and proc.stdout is not None
|
|
proc.stdin.write("q\n")
|
|
proc.stdin.flush()
|
|
return proc.stdout.readline().strip()
|
|
|
|
assert proc.stdin is not None and proc.stdout is not None
|
|
proc.stdin.write("q\n")
|
|
proc.stdin.flush()
|
|
assert proc.stdout.readline().strip() == "22", "expected initial UTC hour 22"
|
|
assert query(ny, "America/New_York", True) == "17", "expected New York hour 17"
|
|
assert query(kyiv, "Europe/Kyiv", True) == "00", "expected Kyiv hour 00"
|
|
assert query(utc, "UTC", True) == "22", "expected return to UTC hour 22"
|
|
# 2) In-place file overwrite (no symlink change)
|
|
assert query(ny, "America/New_York", False) == "17", "expected copy NY hour 17"
|
|
assert query(kyiv, "Europe/Kyiv", False) == "00", "expected copy Kyiv hour 00"
|
|
finally:
|
|
proc.terminate()
|
|
proc.wait(timeout=5)
|
|
|
|
|
|
def test_run_aligned_sigusr1(tmp: pathlib.Path) -> None:
|
|
bin_path = tmp / "run_aligned"
|
|
out_file = tmp / "aligned_ticks"
|
|
subprocess.run(
|
|
[
|
|
"gcc",
|
|
"-std=c11",
|
|
"-O2",
|
|
"-Wall",
|
|
"-Wextra",
|
|
"-Werror",
|
|
str(RUN_ALIGNED_C),
|
|
"-o",
|
|
str(bin_path),
|
|
],
|
|
check=True,
|
|
)
|
|
proc = subprocess.Popen(
|
|
[str(bin_path), "300", "sh", "-c", f'echo tick >> "{out_file}"'],
|
|
stdout=subprocess.DEVNULL,
|
|
stderr=subprocess.DEVNULL,
|
|
)
|
|
try:
|
|
deadline = time.monotonic() + 3.0
|
|
while time.monotonic() < deadline:
|
|
if out_file.exists() and len(out_file.read_text().splitlines()) >= 1:
|
|
break
|
|
time.sleep(0.05)
|
|
assert out_file.exists() and len(out_file.read_text().splitlines()) == 1
|
|
time.sleep(0.15)
|
|
proc.send_signal(signal.SIGUSR1)
|
|
deadline = time.monotonic() + 2.0
|
|
while time.monotonic() < deadline:
|
|
if len(out_file.read_text().splitlines()) >= 2:
|
|
break
|
|
time.sleep(0.05)
|
|
lines = out_file.read_text().splitlines()
|
|
assert len(lines) >= 2, f"SIGUSR1 did not wake bananarchy-run-aligned: {lines}"
|
|
finally:
|
|
proc.terminate()
|
|
proc.wait(timeout=5)
|
|
|
|
|
|
def test_time_sync_waits_and_refreshes(tmp: pathlib.Path) -> None:
|
|
fake_bin = tmp / "bin"
|
|
fake_bin.mkdir()
|
|
run_dir = tmp / "run"
|
|
run_dir.mkdir()
|
|
trace = tmp / "trace.log"
|
|
chronyc_calls = tmp / "chronyc_calls"
|
|
locker_fifo = tmp / "locker.fifo"
|
|
os.mkfifo(locker_fifo)
|
|
|
|
chronyc = fake_bin / "chronyc"
|
|
chronyc.write_text(
|
|
"#!/bin/sh\n"
|
|
f'trace="{trace}"\n'
|
|
f'calls="{chronyc_calls}"\n'
|
|
'sock="$2"; shift 2\n'
|
|
'cmd="${1:-}"\n'
|
|
'n=0; [ -r "$calls" ] && read -r n < "$calls" || true\n'
|
|
'n=$((n + 1))\n'
|
|
'if [ "$cmd" = "tracking" ] || [ "$cmd" = "activity" ]; then\n'
|
|
' printf "%s\\n" "$n" > "$calls"\n'
|
|
'fi\n'
|
|
'echo "chronyc $cmd $n" >> "$trace"\n'
|
|
'if [ "$cmd" = "activity" ]; then\n'
|
|
' echo "1 sources online"\n'
|
|
' echo "0 sources offline"\n'
|
|
' if [ "$n" -le 5 ]; then\n'
|
|
' echo "1 sources doing burst"\n'
|
|
' else\n'
|
|
' echo "0 sources doing burst"\n'
|
|
' fi\n'
|
|
' echo "0 sources with unknown address"\n'
|
|
'elif [ "$cmd" = "tracking" ]; then\n'
|
|
' if [ "$n" -le 4 ]; then\n'
|
|
' echo "Reference ID : 00000000 ()"\n'
|
|
' else\n'
|
|
' echo "Reference ID : C0A80101 (ntp)"\n'
|
|
' fi\n'
|
|
'fi\n',
|
|
encoding="utf-8",
|
|
)
|
|
chronyc.chmod(0o755)
|
|
|
|
for name in ("su", "bananarchy-coverctl", "killall", "sxmo_hook_statusbar.sh"):
|
|
tool = fake_bin / name
|
|
tool.write_text(
|
|
f'#!/bin/sh\necho "{name} $*" >> "{trace}"\nexit 0\n',
|
|
encoding="utf-8",
|
|
)
|
|
tool.chmod(0o755)
|
|
|
|
test_script = tmp / "time-sync-under-test.sh"
|
|
content = TIME_SYNC_SH.read_text(encoding="utf-8")
|
|
sock_file = tmp / "chronyd.sock"
|
|
sock_file.touch()
|
|
content = (
|
|
content
|
|
.replace("SOCKET=/run/chrony/chronyd.sock", f"SOCKET={sock_file}")
|
|
.replace("CHRONYC=/usr/bin/chronyc", f"CHRONYC={chronyc}")
|
|
.replace("RUNDIR=/run/bananarchy-time-sync", f"RUNDIR={run_dir}")
|
|
.replace("[ -S \"$SOCKET\" ]", "[ -e \"$SOCKET\" ]")
|
|
)
|
|
test_script.write_text(content, encoding="utf-8")
|
|
test_script.chmod(0o755)
|
|
|
|
fifo_reader = subprocess.Popen(
|
|
["sh", "-c", f'cat "{locker_fifo}" > "{tmp / "locker.out"}"'],
|
|
)
|
|
try:
|
|
env = os.environ.copy()
|
|
env["PATH"] = f"{fake_bin}:{env['PATH']}"
|
|
env["BANANARCHY_TIME_SYNC_NO_ESCALATION"] = "1"
|
|
env["BANANARCHY_TIME_SOURCE_FILE"] = str(tmp / "missing_source")
|
|
env["BANANARCHY_STATUS_REFRESH_CMD"] = str(fake_bin / "su")
|
|
env["BANANARCHY_LOCKER_FIFO"] = str(locker_fifo)
|
|
env["BANANARCHY_COVERCTL"] = str(fake_bin / "bananarchy-coverctl")
|
|
env["BANANARCHY_SYNC_WAIT"] = "6"
|
|
env["BANANARCHY_TIME_SYNC_SLEEP"] = "0.02"
|
|
|
|
res = subprocess.run([str(test_script), "network-up"], env=env, capture_output=True, text=True)
|
|
assert res.returncode == 0, res.stderr
|
|
finally:
|
|
fifo_reader.wait(timeout=5)
|
|
|
|
events = trace.read_text(encoding="utf-8").splitlines()
|
|
burst_idx = max(i for i, l in enumerate(events) if l.startswith("chronyc burst"))
|
|
refresh_idx = next(i for i, l in enumerate(events) if "sxmo_hook_statusbar.sh" in l)
|
|
tracking_after_burst = [i for i, l in enumerate(events) if i > burst_idx and l.startswith("chronyc tracking")]
|
|
assert tracking_after_burst, f"missing post-burst tracking check: {events}"
|
|
assert refresh_idx > tracking_after_burst[-1], (
|
|
f"UI refresh happened before sync confirmed: {events}"
|
|
)
|
|
assert any("bananarchy-coverctl REFRESH" in l for l in events), events
|
|
assert any("killall -q -USR1 bananarchy-run-aligned" in l for l in events), events
|
|
assert "REFRESH_TIME" in (tmp / "locker.out").read_text(encoding="utf-8")
|
|
|
|
|
|
def test_shell_syntax_and_no_pkill() -> None:
|
|
scripts = [
|
|
ROOT / "overlay/rootfs/usr/bin/bananarchy-time-sync.sh",
|
|
ROOT / "overlay/rootfs/usr/bin/bananarchy-gps-time-sync.sh",
|
|
ROOT / "overlay/rootfs/usr/bin/sxmo_timezonechange.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_statusbar.sh",
|
|
ROOT / "overlay/rootfs/usr/sbin/setup-timezone",
|
|
ROOT / "overlay/rootfs/usr/bin/bananarchy-cover-event.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_lock.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_ring.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_mute_ring.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_discard.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_pickup.sh",
|
|
ROOT / "overlay/rootfs/usr/bin/sxmo_modem.sh",
|
|
ROOT / "overlay/rootfs/usr/bin/sxmo_modemcall.sh",
|
|
ROOT / "overlay/rootfs/usr/bin/sxmo_appmenu.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_contextmenu.sh",
|
|
ROOT / "overlay/rootfs/usr/bin/sxmo_power.sh",
|
|
ROOT / "scripts/build-dwm-plugins.sh",
|
|
]
|
|
for path in scripts:
|
|
res = subprocess.run(["sh", "-n", str(path)], capture_output=True, text=True)
|
|
assert res.returncode == 0, f"syntax error in {path}: {res.stderr}"
|
|
|
|
no_pkill = [
|
|
ROOT / "src/dwm-plugins/callscreen_plugin.cpp",
|
|
ROOT / "overlay/rootfs/usr/bin/bananarchy-cover-event.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_ring.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_mute_ring.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_discard.sh",
|
|
ROOT / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_pickup.sh",
|
|
ROOT / "overlay/rootfs/usr/bin/sxmo_modem.sh",
|
|
ROOT / "overlay/rootfs/usr/bin/sxmo_modemcall.sh",
|
|
ROOT / "overlay/rootfs/usr/bin/sxmo_power.sh",
|
|
]
|
|
for path in no_pkill:
|
|
txt = path.read_text(encoding="utf-8")
|
|
assert "pkill" not in txt, f"unexpected pkill in {path}"
|
|
|
|
|
|
def main() -> int:
|
|
with tempfile.TemporaryDirectory() as td:
|
|
tmp = pathlib.Path(td)
|
|
test_ba_refresh_tz(tmp)
|
|
test_run_aligned_sigusr1(tmp)
|
|
test_time_sync_waits_and_refreshes(tmp)
|
|
test_shell_syntax_and_no_pkill()
|
|
print("test-time-timezone-sync: PASS")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|