- Add Qualcomm MCFG .mbn parser and profile store (bananarchy-imsctl), QMI_PDC/QMI_IMSDCM VoLTE daemon (bananarchy-imsd), and SWu IKEv2/EAP-AKA/ESP/SIP/AMR VoWiFi engine (bananarchy-vowifi) with disabled-by-default (auto) 4G-only activation and xmodem/xfiles/xcallscreen UI support. - Add libmm-wds-bind.so QMI_SERVICE_WDS PRIMARY subscription binding (including serialized post-mux/data-port binding), msm-modem-uim-selection DSDS PS-domain handoff, cs-only dial pause/restore (10-bananarchy-dpm.sh), cold-boot mmcli -K recovery, and networks.so connection.autoconnect no race fix. - Add offline test suites (test-ims-mbn.py, test-imsd-volte.py, test-vowifi-swu-ims.py, test-lte-mobile-data.py), update docs (CHANGELOG.md Unreleased, README.md, MANUAL.md, AGENTS.md), and pin rebuilt 4-target image SHA-256 hashes in scripts/check-rebuild.sh.
419 lines
16 KiB
Python
Executable File
419 lines
16 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Host regression tests for the 72-hour standby battery optimizations."""
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
from pathlib import Path
|
|
|
|
BASE = Path(__file__).resolve().parent.parent
|
|
RUN_ALIGNED_SRC = BASE / "src/bananarchy-daemons/bananarchy-run-aligned.c"
|
|
POWER_POLICY_SH = BASE / "overlay/rootfs/usr/bin/bananarchy-power-policy.sh"
|
|
DISPLAY_SYNC_SH = BASE / "overlay/rootfs/usr/bin/bananarchy-display-power-sync"
|
|
|
|
|
|
def fail(msg):
|
|
sys.stderr.write(f"[fail] {msg}\n")
|
|
return 1
|
|
|
|
|
|
def write_text(path, text):
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(text)
|
|
|
|
|
|
def read_lines(path):
|
|
if not path.exists():
|
|
return []
|
|
return [line.rstrip("\n") for line in path.read_text().splitlines() if line.strip()]
|
|
|
|
|
|
def test_run_aligned(tmp):
|
|
if not shutil.which("gcc"):
|
|
print("[skip] gcc not present; skipping bananarchy-run-aligned host build")
|
|
return 0
|
|
|
|
bin_path = tmp / "bananarchy-run-aligned"
|
|
comp = subprocess.run(
|
|
["gcc", "-O2", "-Wall", "-Wextra", "-Werror",
|
|
str(RUN_ALIGNED_SRC), "-o", str(bin_path)],
|
|
capture_output=True, text=True
|
|
)
|
|
if comp.returncode != 0:
|
|
return fail(f"failed to compile bananarchy-run-aligned.c:\n{comp.stderr}")
|
|
|
|
tick_log = tmp / "ticks.log"
|
|
helper = tmp / "tick_helper.sh"
|
|
write_text(helper, f"#!/bin/sh\necho tick >> '{tick_log}'\n")
|
|
helper.chmod(0o755)
|
|
|
|
lid_file = tmp / "lid-state"
|
|
bl_power = tmp / "bl_power"
|
|
bl_bright = tmp / "brightness"
|
|
|
|
# 1) Initial tick always runs even if dark; subsequent tick while closed skips.
|
|
write_text(lid_file, "closed\n")
|
|
write_text(bl_power, "4\n")
|
|
write_text(bl_bright, "0\n")
|
|
env = os.environ.copy()
|
|
env["BANANARCHY_LID_STATE_PATH"] = str(lid_file)
|
|
env["BANANARCHY_BL_POWER_PATH"] = str(bl_power)
|
|
env["BANANARCHY_BL_BRIGHTNESS_PATH"] = str(bl_bright)
|
|
env.pop("BANANARCHY_RUN_ALIGNED_ALWAYS", None)
|
|
|
|
proc = subprocess.Popen([str(bin_path), "1", str(helper)], env=env)
|
|
try:
|
|
deadline = time.monotonic() + 2.5
|
|
while time.monotonic() < deadline and not tick_log.exists():
|
|
time.sleep(0.05)
|
|
# Wait past at least two 1s wall-clock boundaries while closed/dark.
|
|
time.sleep(2.2)
|
|
finally:
|
|
proc.terminate()
|
|
proc.wait(timeout=5)
|
|
|
|
closed_ticks = read_lines(tick_log)
|
|
if len(closed_ticks) != 1:
|
|
return fail(f"expected exactly 1 startup tick while closed/dark, got {len(closed_ticks)}: {closed_ticks}")
|
|
|
|
# 2) While open and lit, periodic ticks execute normally.
|
|
tick_log.unlink()
|
|
write_text(lid_file, "open\n")
|
|
write_text(bl_power, "0\n")
|
|
write_text(bl_bright, "80\n")
|
|
proc = subprocess.Popen([str(bin_path), "1", str(helper)], env=env)
|
|
try:
|
|
deadline = time.monotonic() + 4.5
|
|
while time.monotonic() < deadline and len(read_lines(tick_log)) < 2:
|
|
time.sleep(0.05)
|
|
finally:
|
|
proc.terminate()
|
|
proc.wait(timeout=5)
|
|
|
|
open_ticks = read_lines(tick_log)
|
|
if len(open_ticks) < 2:
|
|
return fail(f"expected >= 2 ticks while open/lit, got {len(open_ticks)}")
|
|
|
|
# 3) Even with lid open, bl_power=4 skips periodic ticks after initial run.
|
|
tick_log.unlink()
|
|
write_text(bl_power, "4\n")
|
|
write_text(bl_bright, "0\n")
|
|
proc = subprocess.Popen([str(bin_path), "1", str(helper)], env=env)
|
|
try:
|
|
deadline = time.monotonic() + 2.5
|
|
while time.monotonic() < deadline and not tick_log.exists():
|
|
time.sleep(0.05)
|
|
time.sleep(1.5)
|
|
finally:
|
|
proc.terminate()
|
|
proc.wait(timeout=5)
|
|
|
|
dim_ticks = read_lines(tick_log)
|
|
if len(dim_ticks) != 1:
|
|
return fail(f"expected exactly 1 startup tick when bl_power=4/brightness=0, got {len(dim_ticks)}")
|
|
|
|
print("[ok] bananarchy-run-aligned skips dark periodic ticks while running startup tick")
|
|
return 0
|
|
|
|
|
|
def make_mock_qmicli(tmp, reg_state_file):
|
|
qmi_log = tmp / "qmi.log"
|
|
pref_file = tmp / "pref.state"
|
|
write_text(pref_file, "gsm|umts|lte\n")
|
|
mock = tmp / "mock_qmicli"
|
|
write_text(mock, f"""#!/bin/sh
|
|
echo "$*" >> '{qmi_log}'
|
|
case "$1" in
|
|
--nas-get-system-selection-preference)
|
|
pref="$(cat '{pref_file}' 2>/dev/null || echo 'gsm|umts|lte')"
|
|
echo "Mode preference: '$pref'"
|
|
;;
|
|
--nas-set-system-selection-preference=*)
|
|
val="${{1#--nas-set-system-selection-preference=}}"
|
|
printf '%s\n' "$val" > '{pref_file}'
|
|
;;
|
|
--nas-get-serving-system)
|
|
st="$(cat '{reg_state_file}' 2>/dev/null || echo 'registered')"
|
|
echo "Registration state: '$st'"
|
|
;;
|
|
esac
|
|
exit 0
|
|
""")
|
|
mock.chmod(0o755)
|
|
return mock, qmi_log, pref_file
|
|
|
|
|
|
def run_policy(env, arg):
|
|
return subprocess.run(
|
|
[str(POWER_POLICY_SH), arg],
|
|
env=env, capture_output=True, text=True, timeout=15
|
|
)
|
|
|
|
|
|
def test_power_policy_rat(tmp):
|
|
reg_file = tmp / "reg.state"
|
|
mock_qmi, qmi_log, pref_file = make_mock_qmicli(tmp, reg_file)
|
|
conf = tmp / "power-policy.conf"
|
|
rundir = tmp / "rundir"
|
|
calls_dir = tmp / "sxmo_calls"
|
|
calls_dir.mkdir(parents=True, exist_ok=True)
|
|
oper = tmp / "wlan0.operstate"
|
|
offload = tmp / "screen_off_offload"
|
|
listen_sysfs = tmp / "listen_interval"
|
|
fake_dsds = tmp / "fake-dsds"
|
|
dsds_log = tmp / "dsds.log"
|
|
write_text(fake_dsds, f"#!/bin/sh\necho \"$*\" >> '{dsds_log}'\n")
|
|
fake_dsds.chmod(0o755)
|
|
|
|
write_text(conf, "WIFI_STANDBY_RAT=gsm\nWIFI_LISTEN_INTERVAL=8\nCPU_RPM_SLEEP=0\nCPU_L2_SLEEP=0\n")
|
|
write_text(oper, "up\n")
|
|
write_text(offload, "Y\n")
|
|
write_text(listen_sysfs, "1\n")
|
|
|
|
env = os.environ.copy()
|
|
env.update({
|
|
"BANANARCHY_POWER_NO_ROOT": "1",
|
|
"BANANARCHY_POWER_CONF": str(conf),
|
|
"BANANARCHY_POWER_RUNDIR": str(rundir),
|
|
"BANANARCHY_QMICLI_BIN": str(mock_qmi),
|
|
"BANANARCHY_CALLS_DIR": str(calls_dir),
|
|
"BANANARCHY_WLAN_OPERSTATE_PATH": str(oper),
|
|
"BANANARCHY_WIFI_OFFLOAD_PATH": str(offload),
|
|
"BANANARCHY_WIFI_LISTEN_SYSFS": str(listen_sysfs),
|
|
"BANANARCHY_RAT_REG_POLL_SEC": "0",
|
|
"BANANARCHY_RAT_SETTLE_SEC": "0",
|
|
"BANANARCHY_DSDS_BIN": str(fake_dsds),
|
|
"BANANARCHY_ACCEPT_RA_PATH": str(tmp / "nonexistent_ra"),
|
|
"BANANARCHY_SPM_PARAM_DIR": str(tmp / "nonexistent_spm"),
|
|
"BANANARCHY_MODPROBE_CONF": str(tmp / "modprobe.conf"),
|
|
})
|
|
|
|
# 1) GSM registered -> parks to gsm and unpark-rat restores gsm|umts|lte.
|
|
write_text(reg_file, "registered\n")
|
|
res = run_policy(env, "_park_rat")
|
|
if res.returncode != 0:
|
|
return fail(f"_park_rat failed: {res.stderr}")
|
|
if not (rundir / "rat_parked").exists():
|
|
return fail("expected rat_parked marker when GSM registered")
|
|
if pref_file.read_text().strip() != "gsm":
|
|
return fail(f"expected pref gsm while parked, got {pref_file.read_text().strip()}")
|
|
|
|
res = run_policy(env, "unpark-rat")
|
|
if res.returncode != 0:
|
|
return fail(f"unpark-rat failed: {res.stderr}")
|
|
if (rundir / "rat_parked").exists():
|
|
return fail("expected rat_parked cleared after unpark-rat")
|
|
if pref_file.read_text().strip() != "gsm|umts|lte":
|
|
return fail(f"expected pref restored to gsm|umts|lte, got {pref_file.read_text().strip()}")
|
|
|
|
# 2) Active call guard blocks parking; incoming_ended does not.
|
|
active_call = calls_dir / "voice_1.active"
|
|
write_text(active_call, "")
|
|
res = run_policy(env, "_park_rat")
|
|
if res.returncode != 0 or (rundir / "rat_parked").exists():
|
|
return fail("active call must block GSM RAT parking")
|
|
active_call.unlink()
|
|
write_text(calls_dir / "voice_1.incoming_ended", "")
|
|
res = run_policy(env, "_park_rat")
|
|
if res.returncode != 0 or not (rundir / "rat_parked").exists():
|
|
return fail("incoming_ended post-call marker must not block GSM RAT parking")
|
|
run_policy(env, "unpark-rat")
|
|
|
|
# 3) 2G-sunset carrier (not-registered-searching) auto-restores & sets gsm_unsupported.
|
|
write_text(reg_file, "not-registered-searching\n")
|
|
res = run_policy(env, "_park_rat")
|
|
if res.returncode != 0:
|
|
return fail(f"_park_rat fallback failed: {res.stderr}")
|
|
if (rundir / "rat_parked").exists():
|
|
return fail("rat_parked must not remain when GSM registration fails")
|
|
if not (rundir / "gsm_unsupported").exists():
|
|
return fail("gsm_unsupported must be touched when GSM registration fails")
|
|
if pref_file.read_text().strip() != "gsm|umts|lte":
|
|
return fail(f"expected fallback restore to gsm|umts|lte, got {pref_file.read_text().strip()}")
|
|
|
|
# Subsequent _park_rat must skip QMI immediately because gsm_unsupported exists.
|
|
qmi_log.unlink()
|
|
write_text(reg_file, "registered\n")
|
|
res = run_policy(env, "_park_rat")
|
|
if res.returncode != 0 or qmi_log.exists():
|
|
return fail("expected no QMI calls once gsm_unsupported exists")
|
|
|
|
# 4) screenoff / screenon invoke bananarchy-dsds --sig-hysteresis dark / wake.
|
|
res = run_policy(env, "screenoff")
|
|
if res.returncode != 0:
|
|
return fail(f"screenoff failed: {res.stderr}")
|
|
res = run_policy(env, "screenon")
|
|
if res.returncode != 0:
|
|
return fail(f"screenon failed: {res.stderr}")
|
|
dsds_calls = read_lines(dsds_log)
|
|
if dsds_calls != ["--sig-hysteresis dark", "--sig-hysteresis wake"]:
|
|
return fail(f"unexpected DSDS hysteresis calls: {dsds_calls}")
|
|
|
|
# boot clears gsm_unsupported so reboot/policy reset can re-test 2G and syncs listen_interval sysfs.
|
|
write_text(offload, "N\n")
|
|
res = run_policy(env, "boot")
|
|
if res.returncode != 0 or (rundir / "gsm_unsupported").exists():
|
|
return fail("boot must clear gsm_unsupported")
|
|
if listen_sysfs.read_text().strip() != "8":
|
|
return fail(f"expected listen_interval sysfs=8 after boot, got {listen_sysfs.read_text().strip()}")
|
|
|
|
# 5) wifi-up while lit does nothing; while dark it arms and parks RAT.
|
|
res = run_policy(env, "wifi-up")
|
|
if res.returncode != 0 or (rundir / "rat.token").exists() or (rundir / "rat_parked").exists():
|
|
return fail("wifi-up must not arm RAT parking while screen is lit")
|
|
write_text(offload, "Y\n")
|
|
write_text(reg_file, "registered\n")
|
|
res = run_policy(env, "wifi-up")
|
|
if res.returncode != 0:
|
|
return fail(f"wifi-up dark failed: {res.stderr}")
|
|
deadline = time.monotonic() + 2.0
|
|
while time.monotonic() < deadline and not (rundir / "rat_parked").exists():
|
|
time.sleep(0.05)
|
|
time.sleep(0.05)
|
|
if not (rundir / "rat_parked").exists():
|
|
return fail("wifi-up dark did not park RAT")
|
|
res = run_policy(env, "unpark-rat")
|
|
if res.returncode != 0 or (rundir / "rat_parked").exists():
|
|
return fail("unpark-rat failed after wifi-up")
|
|
|
|
# 6) IMS coexistence guards:
|
|
# 6a) Active VoLTE (without VoWiFi) skips GSM RAT parking when keep_lte_on_screen_off=1.
|
|
ims_state = tmp / "ims_state.env"
|
|
ims_conf = tmp / "ims.conf"
|
|
accept_ra = tmp / "accept_ra"
|
|
write_text(ims_conf, "keep_lte_on_screen_off=1\n")
|
|
write_text(ims_state, "VOLTE_ACTIVE=1\nVOWIFI_ACTIVE=0\nVOWIFI_IPV6_EPDG=0\n")
|
|
write_text(accept_ra, "1\n")
|
|
env["BANANARCHY_IMS_STATE_PATH"] = str(ims_state)
|
|
env["BANANARCHY_IMS_CONF_PATH"] = str(ims_conf)
|
|
env["BANANARCHY_ACCEPT_RA_PATH"] = str(accept_ra)
|
|
res = run_policy(env, "_park_rat")
|
|
if res.returncode != 0 or (rundir / "rat_parked").exists():
|
|
return fail("active VoLTE (without VoWiFi) must skip GSM RAT parking")
|
|
|
|
# 6b) Active VoWiFi allows GSM RAT parking; VOWIFI_IPV6_EPDG=0 mutes accept_ra,
|
|
# while VOWIFI_IPV6_EPDG=1 preserves wlan0 accept_ra across screenoff/screenon.
|
|
mock_bin = tmp / "bin"
|
|
mock_ip = mock_bin / "ip"
|
|
write_text(mock_ip, """#!/bin/sh
|
|
if [ "$1" = "-4" ] && [ "$2" = "addr" ]; then
|
|
echo "2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500"
|
|
echo " inet 192.168.1.10/24 brd 192.168.1.255 scope global wlan0"
|
|
fi
|
|
exit 0
|
|
""")
|
|
mock_ip.chmod(0o755)
|
|
env["PATH"] = f"{mock_bin}:{env.get('PATH', '')}"
|
|
|
|
write_text(ims_state, "VOLTE_ACTIVE=1\nVOWIFI_ACTIVE=1\nVOWIFI_IPV6_EPDG=0\n")
|
|
write_text(accept_ra, "1\n")
|
|
res = run_policy(env, "screenoff")
|
|
if res.returncode != 0 or accept_ra.read_text().strip() != "0":
|
|
return fail("VOWIFI_IPV6_EPDG=0 must mute wlan0 accept_ra on screenoff")
|
|
deadline = time.monotonic() + 3.0
|
|
while time.monotonic() < deadline and not (rundir / "rat_parked").exists():
|
|
time.sleep(0.05)
|
|
time.sleep(0.1)
|
|
if not (rundir / "rat_parked").exists():
|
|
return fail("active VoWiFi screenoff should allow cellular GSM standby parking")
|
|
res = run_policy(env, "screenon")
|
|
if res.returncode != 0 or accept_ra.read_text().strip() != "1":
|
|
return fail("screenon must restore wlan0 accept_ra to 1")
|
|
|
|
write_text(ims_state, "VOLTE_ACTIVE=1\nVOWIFI_ACTIVE=1\nVOWIFI_IPV6_EPDG=1\n")
|
|
res = run_policy(env, "screenoff")
|
|
if res.returncode != 0 or accept_ra.read_text().strip() != "1":
|
|
return fail("VOWIFI_IPV6_EPDG=1 must keep wlan0 accept_ra unmuted")
|
|
deadline = time.monotonic() + 3.0
|
|
while time.monotonic() < deadline and not (rundir / "rat_parked").exists():
|
|
time.sleep(0.05)
|
|
time.sleep(0.1)
|
|
if not (rundir / "rat_parked").exists():
|
|
return fail("active VoWiFi (IPv6 ePDG) should allow cellular GSM standby parking")
|
|
res = run_policy(env, "screenon")
|
|
if res.returncode != 0:
|
|
return fail(f"screenon after VoWiFi failed: {res.stderr}")
|
|
|
|
print("[ok] bananarchy-power-policy.sh GSM verification, fallback, call guard, IMS VoLTE/VoWiFi coexistence, wifi-up, unpark-rat, and DSDS hysteresis")
|
|
return 0
|
|
|
|
|
|
def test_bms_screen_off_sync(tmp):
|
|
br = tmp / "brightness"
|
|
blp = tmp / "bl_power"
|
|
dpms = tmp / "dpms"
|
|
offload = tmp / "screen_off_offload"
|
|
bms = tmp / "bms_screen_off"
|
|
spm_off = tmp / "spm_screen_off"
|
|
spm_rpm = tmp / "spm_rpm_sleep"
|
|
lid_profile = tmp / "lid-profile"
|
|
lid_state = tmp / "lid-state"
|
|
cover_marker = tmp / "cover-backlight"
|
|
|
|
write_text(lid_profile, "flip\n")
|
|
write_text(lid_state, "closed\n")
|
|
write_text(br, "0\n")
|
|
write_text(blp, "4\n")
|
|
write_text(dpms, "Off\n")
|
|
write_text(offload, "N\n")
|
|
write_text(bms, "N\n")
|
|
write_text(spm_off, "N\n")
|
|
write_text(spm_rpm, "N\n")
|
|
|
|
env = os.environ.copy()
|
|
env.update({
|
|
"BANANARCHY_LID_PROFILE": str(lid_profile),
|
|
"BANANARCHY_LID_STATE": str(lid_state),
|
|
"BANANARCHY_BR_PATH": str(br),
|
|
"BANANARCHY_BL_POWER_PATH": str(blp),
|
|
"BANANARCHY_DPMS_PATH": str(dpms),
|
|
"BANANARCHY_WIFI_OFFLOAD_PATH": str(offload),
|
|
"BANANARCHY_BMS_SCREEN_OFF_PATH": str(bms),
|
|
"BANANARCHY_SPM_SCREEN_OFF_PATH": str(spm_off),
|
|
"BANANARCHY_SPM_RPM_SLEEP_PATH": str(spm_rpm),
|
|
"BANANARCHY_COVER_MARKER": str(cover_marker),
|
|
"BANANARCHY_FORCE_MARKER": str(tmp / "cover-bl-force"),
|
|
"BANANARCHY_STATE_CACHE": str(tmp / "cover-power-state"),
|
|
"BANANARCHY_KBD_PATH": str(tmp / "kbd"),
|
|
"BANANARCHY_RL_PATH": str(tmp / "rl"),
|
|
"BANANARCHY_GPU_GOV_PATH": str(tmp / "gpu_gov"),
|
|
})
|
|
|
|
# Dark closed-flip -> both Wi-Fi offload and pm8916_bms_vm screen_off = Y.
|
|
res = subprocess.run([str(DISPLAY_SYNC_SH)], env=env, capture_output=True, text=True)
|
|
if res.returncode != 0:
|
|
return fail(f"display-power-sync dark failed: {res.stderr}")
|
|
if offload.read_text().strip() != "Y" or bms.read_text().strip() != "Y":
|
|
return fail(f"expected offload=Y and bms=Y, got offload={offload.read_text().strip()} bms={bms.read_text().strip()}")
|
|
|
|
# Open flip with lit panel -> both revert to N.
|
|
write_text(lid_state, "open\n")
|
|
write_text(br, "80\n")
|
|
write_text(blp, "0\n")
|
|
write_text(dpms, "On\n")
|
|
res = subprocess.run([str(DISPLAY_SYNC_SH)], env=env, capture_output=True, text=True)
|
|
if res.returncode != 0:
|
|
return fail(f"display-power-sync wake failed: {res.stderr}")
|
|
if offload.read_text().strip() != "N" or bms.read_text().strip() != "N":
|
|
return fail(f"expected offload=N and bms=N on wake, got offload={offload.read_text().strip()} bms={bms.read_text().strip()}")
|
|
|
|
print("[ok] bananarchy-display-power-sync toggles pm8916_bms_vm screen_off alongside Wi-Fi offload")
|
|
return 0
|
|
|
|
|
|
def main():
|
|
with tempfile.TemporaryDirectory(prefix="bananarchy-standby-test-") as td:
|
|
tmp = Path(td)
|
|
for fn in (test_run_aligned, test_power_policy_rat, test_bms_screen_off_sync):
|
|
rc = fn(tmp)
|
|
if rc != 0:
|
|
return rc
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|