Implement 0012 72h standby battery optimizations and initramfs depmod hook
- Add patches/kernel/0012-msm8909-standby-wifi-wcd-panel-ldo-bms.patch, rebuild affected kernel/module artifacts and all six device DTS/DTB files (msm8916-wcd-analog s2/bias gating, wcn36xx offload_sync_work and healthy-RSSI screen_off_offload scan short-circuit, pm8916_bms_vm screen_off FORCE_S3 OCV mode, panel-mipi-dbi dc/reset low on blank, spi-qup runtime PM sleep pinctrl, PM8909 l1/l4 LDO seeding, and sdhci-msm vmmc/vqmmc set_load with regulator-allow-set-load on l8/l12), and switch msm8905-cam from direct APSS SPMI LDO6/LDO17 writes to RPM regulator consumer voting.
- Update standby power policy and compiled C daemons (WIFI_LISTEN_INTERVAL=8, WIFI_STANDBY_RAT=gsm with CS verification and fallback, 10-bananarchy-dpm.sh wifi-up/unpark-rat dispatch, 25 s boot QRTR wait and QMI DMS online recovery, pm8916_bms_vm screen_off sync, bananarchy-run-aligned dark-screen skip, bananarchy-dsds --sig-hysteresis, bananarchy-cover-idle wake_blank_timeout = 8, and scripts/test-standby-power-policy.py).
- Add overlay/rootfs/etc/boot-deploy/hooks/10-initramfs-depmod.sh to run depmod -b per staged initramfs cpio archive and eliminate Stage 2 udevd missing-module boot console errors, enforce .ko.zst-only module installs in apply-bananarchy-overlay.sh, stage Alpine 3.24 /usr/lib/{libz,libcrypto}.so* in rebuild-image.sh chroot with failure cleanup, and add initramfs cpio guards plus verified image hashes in scripts/check-rebuild.sh.
- Document all changes under Unreleased in CHANGELOG.md and synchronize AGENTS.md, MANUAL.md, and BATTERY-OPTIMIZATION-ANALYSIS.md.
This commit is contained in:
1 parent
9700949b28
commit
fc5c4282f5
67 files changed
+67482
-65598
No files matched your search
Executable
+357
@@ -0,0 +1,357 @@
|
||||
#!/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:
|
||||
time.sleep(2.2)
|
||||
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")
|
||||
|
||||
print("[ok] bananarchy-power-policy.sh GSM verification, fallback, call guard, 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())
|
||||
Reference in new issue
Block a user