feat(cellular, power): enable SDM660 IPA v2.6L 4G LTE, power-key status screen, and DVFS standby
Offline project checks / check (push) Canceled after 0s
Offline project checks / check (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "../project/cellular/ipa-v2/ipa_v2_cmd_format.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct ipa_v2_shared_mem_cmd command;
|
||||
struct ipa_v2_bam_desc descriptor;
|
||||
const unsigned char command_bytes[] = {
|
||||
0x00, 0x00, 0x40, 0x00, 0x40, 0x30, 0x20, 0x10,
|
||||
0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
const unsigned char descriptor_bytes[] = {
|
||||
0xa0, 0x90, 0x80, 0x70, 0x13, 0x00, 0x00, 0x41,
|
||||
};
|
||||
|
||||
assert(sizeof(command) == 16);
|
||||
assert(sizeof(descriptor) == 8);
|
||||
assert(!ipa_v2_shared_read_encode(&command, 0x10203040, 64, 0x80, 8192, 0));
|
||||
assert(!memcmp(&command, command_bytes, sizeof(command_bytes)));
|
||||
assert(!ipa_v2_shared_read_desc(&descriptor, 0x708090a0, sizeof(command)));
|
||||
assert(!memcmp(&descriptor, descriptor_bytes, sizeof(descriptor_bytes)));
|
||||
assert(ipa_v2_shared_read_desc(&descriptor, 0x708090a0, 19) == -ERANGE);
|
||||
assert(ipa_v2_shared_read_desc(&descriptor, 0xfffffff8ULL, 16) == -ERANGE);
|
||||
assert(ipa_v2_shared_read_encode(&command, 0x100000000ULL, 16, 0, 8192, 0) == -ERANGE);
|
||||
assert(ipa_v2_shared_read_encode(&command, 0xfffffffcULL, 16, 0, 8192, 0) == -ERANGE);
|
||||
assert(ipa_v2_shared_read_encode(&command, 0x1000, 0, 0, 8192, 0) == -ERANGE);
|
||||
assert(ipa_v2_shared_read_encode(&command, 0x1000, 16, 8180, 8192, 0) == -ERANGE);
|
||||
assert(ipa_v2_shared_read_encode(&command, 0x1000, 16, 0, 8192, 128) == -ERANGE);
|
||||
assert(ipa_v2_shared_read_encode(&command, 0x1000, 16, 0x10000, 0x20000, 0) == -ERANGE);
|
||||
assert(!ipa_v2_shared_read_encode(&command, 0xfffffff0ULL, 16, 8176, 8192, 0));
|
||||
assert(ipa_v2_dma_range_valid(0xffffffffULL, 1));
|
||||
assert(!ipa_v2_dma_range_valid(0xffffffffULL, 2));
|
||||
assert(!ipa_v2_dma_range_valid(0, 0));
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
"""Compile the actual command encoder and check its wire bytes and bounds."""
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
class BamCommandFormatTest(unittest.TestCase):
|
||||
def test_command_encoding(self):
|
||||
compiler = shutil.which("cc")
|
||||
if not compiler:
|
||||
self.skipTest("native C compiler not available")
|
||||
source = Path(__file__).with_name("ipa_v2_cmd_format.c")
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
executable = Path(directory) / "ipa-v2-format-test"
|
||||
subprocess.run([compiler, "-std=c11", "-Wall", "-Wextra", "-Werror",
|
||||
str(source), "-o", str(executable)], check=True)
|
||||
subprocess.run([str(executable)], check=True)
|
||||
@@ -0,0 +1,119 @@
|
||||
"""Fail-closed live-DT validation for the temporary IPA DMA test overlay."""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
SPEC = importlib.util.spec_from_file_location(
|
||||
"cellular_bam_overlay",
|
||||
Path(__file__).resolve().parents[1] / "scripts/phone-cellular-bam-overlay.py",
|
||||
)
|
||||
OVERLAY = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(OVERLAY)
|
||||
|
||||
|
||||
class BamOverlayTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
self.root = Path(self.temp.name)
|
||||
self.put("compatible", b"xiaomi,platina\0qcom,sdm660\0")
|
||||
self.put_cells("soc@0/#address-cells", 1)
|
||||
self.put_cells("soc@0/#size-cells", 1)
|
||||
self.put("soc@0/iommu@16c0000/compatible", b"qcom,sdm630-smmu-v2\0qcom,smmu-v2\0")
|
||||
self.put_cells("soc@0/iommu@16c0000/phandle", 0x9C)
|
||||
self.put_cells("soc@0/iommu@16c0000/#iommu-cells", 1)
|
||||
self.put_cells("soc@0/rpm-cc/phandle", 0x29)
|
||||
self.put_cells("soc@0/rpm-cc/#clock-cells", 1)
|
||||
self.put("soc@0/ipa@14780000/compatible", b"qcom,sdm660-ipa\0qcom,ipa-v2.6\0")
|
||||
self.put("soc@0/ipa@14780000/clock-names", b"core\0")
|
||||
self.put_cells("soc@0/ipa@14780000/clocks", 0x29, 0x44)
|
||||
|
||||
def put(self, name, data):
|
||||
path = self.root / name
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(data)
|
||||
|
||||
def put_cells(self, name, *values):
|
||||
self.put(name, struct.pack(f">{len(values)}I", *values))
|
||||
|
||||
def generate(self):
|
||||
return OVERLAY.generate(self.root)
|
||||
|
||||
def test_live_phandles_are_used_without_modifying_parent(self):
|
||||
self.put_cells("soc@0/iommu@16c0000/phandle", 0x17)
|
||||
self.put_cells("soc@0/rpm-cc/phandle", 0x81)
|
||||
self.put_cells("soc@0/ipa@14780000/clocks", 0x81, 0x44)
|
||||
result = self.generate()
|
||||
self.assertIn("iommus = <0x17 0x19c0>", result)
|
||||
self.assertIn("clocks = <0x81 0x44>", result)
|
||||
self.assertIn("reg = <0x147c0000 0x1000>, <0x14784000 0x26934>", result)
|
||||
self.assertNotIn("#address-cells", result)
|
||||
self.assertNotIn("#size-cells", result)
|
||||
self.assertNotIn("ipa@14780000", result)
|
||||
|
||||
def test_other_machine_rejected(self):
|
||||
self.put("compatible", b"other,phone\0")
|
||||
with self.assertRaisesRegex(ValueError, "not xiaomi,platina"):
|
||||
self.generate()
|
||||
|
||||
def test_other_address_layout_rejected(self):
|
||||
self.put_cells("soc@0/#address-cells", 2)
|
||||
with self.assertRaisesRegex(ValueError, "address/size"):
|
||||
self.generate()
|
||||
|
||||
def test_existing_ap_stream_rejected(self):
|
||||
self.put_cells("soc@0/ipa@14780000/iommus", 0x9C, 0x19C0)
|
||||
with self.assertRaisesRegex(ValueError, "already declared"):
|
||||
self.generate()
|
||||
|
||||
def test_non_ap_stream_allowed(self):
|
||||
self.put_cells("soc@0/some-device/iommus", 0x9C, 0x19C1, 0x9C, 0x19C2)
|
||||
self.assertIn("0x19c0", self.generate())
|
||||
|
||||
def test_unknown_iommu_provider_rejected(self):
|
||||
self.put_cells("soc@0/some-device/iommus", 0xFF, 0x19C0)
|
||||
with self.assertRaisesRegex(ValueError, "unresolved IOMMU"):
|
||||
self.generate()
|
||||
|
||||
def test_truncated_iommu_spec_rejected(self):
|
||||
self.put_cells("soc@0/some-device/iommus", 0x9C)
|
||||
with self.assertRaisesRegex(ValueError, "invalid IOMMU arguments"):
|
||||
self.generate()
|
||||
|
||||
def test_unexpected_iommu_cells_rejected(self):
|
||||
self.put_cells("soc@0/iommu@16c0000/#iommu-cells", 2)
|
||||
with self.assertRaisesRegex(ValueError, "IOMMU argument"):
|
||||
self.generate()
|
||||
|
||||
def test_duplicate_phandle_rejected(self):
|
||||
self.put_cells("soc@0/another-device/phandle", 0x29)
|
||||
with self.assertRaisesRegex(ValueError, "duplicate phandle"):
|
||||
self.generate()
|
||||
|
||||
def test_wrong_clock_rejected(self):
|
||||
self.put_cells("soc@0/ipa@14780000/clocks", 0x29, 0x45)
|
||||
with self.assertRaisesRegex(ValueError, "RPM IPA core clock"):
|
||||
self.generate()
|
||||
|
||||
def test_clock_provider_cells_rejected(self):
|
||||
self.put_cells("soc@0/rpm-cc/#clock-cells", 2)
|
||||
with self.assertRaisesRegex(ValueError, "clock provider"):
|
||||
self.generate()
|
||||
|
||||
def test_existing_test_device_rejected(self):
|
||||
(self.root / "soc@0/platina-ipa-dma-test@147c0000").mkdir()
|
||||
with self.assertRaisesRegex(ValueError, "test node already exists"):
|
||||
self.generate()
|
||||
|
||||
def test_malformed_cells_rejected(self):
|
||||
self.put("soc@0/ipa@14780000/clocks", b"\x00")
|
||||
with self.assertRaisesRegex(ValueError, "invalid cells"):
|
||||
self.generate()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,53 @@
|
||||
"""Exercise the opt-in early-IPA boot gate against fake remoteproc devices."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
DSP = ROOT / "scripts/phone-dsp.openrc"
|
||||
RMTFS = ROOT / "project/cellular/ipa-v2/rmtfs-early.conf"
|
||||
|
||||
|
||||
class EarlyIpaBootTest(unittest.TestCase):
|
||||
def test_exact_cmdline_token_required(self):
|
||||
for cmdline, enabled in (("quiet platina.ipa_bringup=1 panic=10", True),
|
||||
("quiet platina.ipa_bringup=0", False),
|
||||
("xplatina.ipa_bringup=1", False),
|
||||
("platina.ipa_bringup=10", False),
|
||||
("quiet", False)):
|
||||
with self.subTest(cmdline=cmdline), tempfile.TemporaryDirectory() as directory:
|
||||
path = Path(directory) / "cmdline"
|
||||
path.write_text(cmdline + "\n")
|
||||
result = subprocess.run(["sh", "-c", '. "$1"; ipa_bringup_mode "$2"',
|
||||
"sh", str(DSP), str(path)])
|
||||
self.assertEqual(result.returncode == 0, enabled)
|
||||
|
||||
def test_only_modem_is_held_offline(self):
|
||||
for mode in ("0", "1"):
|
||||
with self.subTest(mode=mode), tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
for index, name in enumerate(("adsp", "cdsp", "4080000.remoteproc")):
|
||||
node = root / f"remoteproc{index}"
|
||||
node.mkdir()
|
||||
(node / "name").write_text(name + "\n")
|
||||
(node / "state").write_text("offline\n")
|
||||
subprocess.run(["sh", "-c", '. "$1"; start_remoteprocs "$2" "$3"',
|
||||
"sh", str(DSP), str(root), mode], check=True)
|
||||
self.assertEqual((root / "remoteproc0/state").read_text(), "start\n")
|
||||
self.assertEqual((root / "remoteproc1/state").read_text(), "start\n")
|
||||
self.assertEqual((root / "remoteproc2/state").read_text(),
|
||||
"offline\n" if mode == "1" else "start\n")
|
||||
|
||||
def test_rmtfs_sync_option_only_removed_in_test_boot(self):
|
||||
for cmdline, expected in (("quiet", "-s -P -r -v"),
|
||||
("quiet platina.ipa_bringup=1", "-P -r -v")):
|
||||
with self.subTest(cmdline=cmdline):
|
||||
script = ('cat() { printf "%s\\n" "$TEST_CMDLINE"; }; '
|
||||
'command_args="-s -P -r -v"; . "$1"; '
|
||||
'printf "%s" "$command_args"')
|
||||
result = subprocess.run(["sh", "-c", script, "sh", str(RMTFS)],
|
||||
env={"TEST_CMDLINE": cmdline}, capture_output=True,
|
||||
text=True, check=True)
|
||||
self.assertEqual(result.stdout, expected)
|
||||
@@ -16,6 +16,48 @@ rpmsg = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(rpmsg)
|
||||
|
||||
|
||||
class FrameStatsTests(unittest.TestCase):
|
||||
@staticmethod
|
||||
def encode(payload):
|
||||
fcs = rpmsg.PPPFrameStats.fcs(payload) ^ 0xffff
|
||||
frame = payload + fcs.to_bytes(2, 'little')
|
||||
escaped = bytearray(b'\x7e')
|
||||
for byte in frame:
|
||||
if byte < 0x20 or byte in (0x7d, 0x7e):
|
||||
escaped.extend((0x7d, byte ^ 0x20))
|
||||
else:
|
||||
escaped.append(byte)
|
||||
return bytes(escaped) + b'\x7e'
|
||||
|
||||
def test_fcs_matches_captured_modem_lcp_frame(self):
|
||||
stats = rpmsg.PPPFrameStats()
|
||||
stats.feed(bytes.fromhex('7e80210100000467c37e'))
|
||||
self.assertEqual(stats.protocols, {'ipcp': 1})
|
||||
self.assertEqual(stats.invalid_fcs, 0)
|
||||
|
||||
def test_stream_splits_and_compression_do_not_change_ip_counts(self):
|
||||
stats = rpmsg.PPPFrameStats()
|
||||
payload = bytes(range(40)) + b'\x7d\x7e'
|
||||
data = self.encode(b'\xff\x03\x00\x21' + payload)
|
||||
data += self.encode(b'\x21' + payload)
|
||||
# Includes every split position, including the middle of escapes/FCS.
|
||||
for byte in b'CONNECT\r\n' + data:
|
||||
stats.feed(bytes([byte]))
|
||||
self.assertEqual(stats.protocols, {'ipv4': 2})
|
||||
self.assertEqual(stats.ipv4_bytes, len(payload) * 2)
|
||||
self.assertEqual(stats.invalid_fcs, 0)
|
||||
|
||||
def test_corrupt_and_oversized_frames_are_not_received_ip(self):
|
||||
stats = rpmsg.PPPFrameStats()
|
||||
stats.feed(b'\x7e\x21\x45\x01\x02\x03\x7e')
|
||||
stats.feed(b'\x7e' + b'x' * 65537 + b'\x7e')
|
||||
stats.feed(self.encode(b'\xc0\x21\x09\x00\x00\x04'))
|
||||
self.assertEqual(stats.invalid_fcs, 1)
|
||||
self.assertEqual(stats.oversized, 1)
|
||||
self.assertEqual(stats.protocols, {'lcp': 1})
|
||||
self.assertEqual(stats.ipv4_bytes, 0)
|
||||
|
||||
|
||||
class ATTests(unittest.TestCase):
|
||||
def exchange(self, chunks, command='AT', timeout=1):
|
||||
host, modem = socket.socketpair(type=socket.SOCK_DGRAM)
|
||||
@@ -108,6 +150,57 @@ class EndpointTests(unittest.TestCase):
|
||||
|
||||
|
||||
class PPPTests(unittest.TestCase):
|
||||
def test_shutdown_forwards_termination_and_peer_ack(self):
|
||||
host, modem = socket.socketpair(type=socket.SOCK_DGRAM)
|
||||
self.addCleanup(host.close)
|
||||
self.addCleanup(modem.close)
|
||||
host.setblocking(False)
|
||||
modem.settimeout(2)
|
||||
master, slave = rpmsg.pty.openpty()
|
||||
self.addCleanup(os.close, master)
|
||||
self.addCleanup(os.close, slave)
|
||||
rpmsg.tty.setraw(slave)
|
||||
os.set_blocking(master, False)
|
||||
os.set_blocking(slave, False)
|
||||
termination = b'\x7e\xff\x03\xc0\x21\x05\x01\x00\x04\x7e'
|
||||
ack = b'\x7e\xff\x03\xc0\x21\x06\x01\x00\x04\x7e'
|
||||
observed = []
|
||||
|
||||
def peer():
|
||||
observed.append(modem.recv(1024))
|
||||
modem.send(ack)
|
||||
|
||||
thread = threading.Thread(target=peer, daemon=True)
|
||||
thread.start()
|
||||
|
||||
class Process:
|
||||
killed = False
|
||||
returncode = None
|
||||
|
||||
def terminate(self):
|
||||
os.write(slave, termination)
|
||||
|
||||
def poll(self):
|
||||
if select.select([slave], [], [], 0)[0]:
|
||||
if os.read(slave, 1024) == ack:
|
||||
self.returncode = 0
|
||||
return self.returncode
|
||||
|
||||
def kill(self):
|
||||
self.killed = True
|
||||
self.returncode = -9
|
||||
|
||||
def wait(self, timeout=None):
|
||||
return self.returncode
|
||||
|
||||
process = Process()
|
||||
rpmsg.stop_ppp(process, host.fileno(), master, timeout=1)
|
||||
thread.join(timeout=2)
|
||||
self.assertFalse(thread.is_alive())
|
||||
self.assertEqual(observed, [termination])
|
||||
self.assertEqual(process.returncode, 0)
|
||||
self.assertFalse(process.killed)
|
||||
|
||||
def test_manager_is_restored_when_modem_preparation_fails(self):
|
||||
calls = []
|
||||
|
||||
|
||||
@@ -78,6 +78,9 @@ class CellularSetupTests(unittest.TestCase):
|
||||
self.assertIn('connection.autoconnect', cmds[0])
|
||||
idx = cmds[0].index('connection.autoconnect')
|
||||
self.assertEqual(cmds[0][idx + 1], 'no')
|
||||
self.assertIn('ipv4.route-metric', cmds[0])
|
||||
m_idx = cmds[0].index('ipv4.route-metric')
|
||||
self.assertEqual(cmds[0][m_idx + 1], '700')
|
||||
|
||||
def test_build_nmcli_setup_commands_existing(self):
|
||||
cmds = cellular.build_nmcli_setup_commands(
|
||||
@@ -93,6 +96,9 @@ class CellularSetupTests(unittest.TestCase):
|
||||
self.assertIn('connection.autoconnect', cmds[0])
|
||||
idx = cmds[0].index('connection.autoconnect')
|
||||
self.assertEqual(cmds[0][idx + 1], 'no')
|
||||
self.assertIn('ipv4.route-metric', cmds[0])
|
||||
m_idx = cmds[0].index('ipv4.route-metric')
|
||||
self.assertEqual(cmds[0][m_idx + 1], '700')
|
||||
|
||||
def test_configure_cellular_invokes_executor(self):
|
||||
recorded_calls = []
|
||||
@@ -364,6 +370,70 @@ class CellularSetupTests(unittest.TestCase):
|
||||
self.assertEqual(recorded[0], ['modprobe', '--ignore-install', 'qcom_q6v5_mss'])
|
||||
self.assertEqual(recorded[1], ['modprobe', '--ignore-install', 'ipa'])
|
||||
|
||||
def test_daemon_waits_for_datapath_and_plmn_registration(self):
|
||||
checks = [False, True, True]
|
||||
mm_outputs = [
|
||||
"General | path: /org/freedesktop/ModemManager1/Modem/0\nStatus | state: searching\n",
|
||||
SAMPLE_MMCLI_OUTPUT.replace('46000', '46001').replace('CMCC', 'CHN-UNICOM'),
|
||||
]
|
||||
mm_idx = [0]
|
||||
recorded = []
|
||||
active_state = [False]
|
||||
logs = []
|
||||
|
||||
def mock_datapath():
|
||||
return checks.pop(0) if checks else True
|
||||
|
||||
def mock_executor(cmd, **kwargs):
|
||||
recorded.append(cmd)
|
||||
cmd_str = ' '.join(cmd)
|
||||
if 'mmcli -L' in cmd_str:
|
||||
return subprocess.CompletedProcess(cmd, 0,
|
||||
stdout='/org/freedesktop/ModemManager1/Modem/0 [QUALCOMM] SDM660\n', stderr='')
|
||||
if 'mmcli -m 0' in cmd_str:
|
||||
out = mm_outputs[min(mm_idx[0], len(mm_outputs) - 1)]
|
||||
mm_idx[0] += 1
|
||||
return subprocess.CompletedProcess(cmd, 0, stdout=out, stderr='')
|
||||
if 'connection show --active' in cmd_str:
|
||||
out = 'platina-cellular\n' if active_state[0] else 'platina-usb\n'
|
||||
return subprocess.CompletedProcess(cmd, 0, stdout=out, stderr='')
|
||||
if 'connection show' in cmd_str:
|
||||
return subprocess.CompletedProcess(cmd, 0, stdout='platina-usb\n', stderr='')
|
||||
if 'connection up' in cmd_str:
|
||||
active_state[0] = True
|
||||
return subprocess.CompletedProcess(cmd, 0, stdout='', stderr='')
|
||||
return subprocess.CompletedProcess(cmd, 0, stdout='', stderr='')
|
||||
|
||||
res = cellular.run_auto_connect(
|
||||
daemon=True,
|
||||
poll_interval=1,
|
||||
max_attempts=3,
|
||||
executor=mock_executor,
|
||||
sleeper=lambda s: None,
|
||||
logger=logs.append,
|
||||
datapath_checker=mock_datapath,
|
||||
)
|
||||
self.assertFalse(res) # exits cleanly on max_attempts=3 in daemon loop
|
||||
self.assertTrue(active_state[0])
|
||||
add_calls = [c for c in recorded if 'add' in c]
|
||||
self.assertEqual(len(add_calls), 1)
|
||||
self.assertIn('3gnet', add_calls[0])
|
||||
self.assertNotIn('cmnet', add_calls[0])
|
||||
self.assertIn('700', add_calls[0])
|
||||
self.assertTrue(any('dialing skipped' in log for log in logs))
|
||||
self.assertTrue(any('waiting for registration' in log for log in logs))
|
||||
|
||||
def test_usb_profile_metric_yields_to_cellular_and_wifi(self):
|
||||
usb_profile = (ROOT / 'ports/candidate/device-xiaomi-platina/platina-usb.nmconnection').read_text()
|
||||
metric = None
|
||||
for line in usb_profile.splitlines():
|
||||
if line.strip().startswith('route-metric='):
|
||||
metric = int(line.split('=', 1)[1].strip())
|
||||
break
|
||||
self.assertIsNotNone(metric)
|
||||
self.assertEqual(metric, 2000)
|
||||
self.assertGreater(metric, 700)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -104,5 +104,119 @@ class ChordTests(unittest.TestCase):
|
||||
self.assertEqual(chord.find_devices(base), {P: Path('/dev/input/event7'), U: Path('/dev/input/event9')})
|
||||
|
||||
|
||||
class PowerButtonAndStandbyTests(unittest.TestCase):
|
||||
def test_short_power_tap_toggles_screen_and_ignores_glitches(self):
|
||||
policy = chord.PowerButtonPolicy(hold_seconds=3.0)
|
||||
# Sub-20ms bounce does nothing
|
||||
self.assertIsNone(policy.event(P, 1, 10.0))
|
||||
self.assertIsNone(policy.event(P, 0, 10.01))
|
||||
# Normal 120ms tap toggles screen
|
||||
self.assertIsNone(policy.event(P, 1, 20.0))
|
||||
self.assertIsNone(policy.check_timeout(20.1))
|
||||
self.assertEqual(policy.event(P, 0, 20.12), 'toggle_screen')
|
||||
|
||||
def test_long_power_fires_at_timeout_and_suppresses_release(self):
|
||||
policy = chord.PowerButtonPolicy(hold_seconds=3.0)
|
||||
self.assertIsNone(policy.event(P, 1, 100.0))
|
||||
self.assertIsNone(policy.check_timeout(102.9))
|
||||
self.assertEqual(policy.check_timeout(103.0), 'long_power')
|
||||
self.assertIsNone(policy.check_timeout(103.5))
|
||||
self.assertIsNone(policy.event(P, 0, 103.6))
|
||||
|
||||
def test_chord_compatible_and_volume_up_prevents_screen_toggle(self):
|
||||
policy = chord.PowerButtonPolicy(hold_seconds=3.0)
|
||||
self.assertIsNone(policy.event(U, 1, 50.0))
|
||||
self.assertIsNone(policy.event(P, 1, 50.1))
|
||||
self.assertIsNone(policy.event(P, 0, 50.5))
|
||||
self.assertIsNone(policy.event(U, 0, 50.6))
|
||||
# Full 3s hold with Power + Volume Up triggers long_power
|
||||
self.assertIsNone(policy.event(P, 1, 60.0))
|
||||
self.assertIsNone(policy.event(U, 1, 60.1))
|
||||
self.assertEqual(policy.check_timeout(63.0), 'long_power')
|
||||
self.assertIsNone(policy.event(U, 0, 63.1))
|
||||
self.assertIsNone(policy.event(P, 0, 63.2))
|
||||
|
||||
def test_boot_charger_cmdline_detection(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
cmd = Path(tmp) / 'cmdline'
|
||||
cmd.write_text('quiet pmos_root_uuid=abc\n')
|
||||
self.assertFalse(chord.is_boot_charger_mode(cmd))
|
||||
cmd.write_text('quiet androidboot.mode=charger androidboot.serialno=63c36adb\n')
|
||||
self.assertTrue(chord.is_boot_charger_mode(cmd))
|
||||
cmd.write_text('quiet androidboot.bootreason=usb_chg\n')
|
||||
self.assertTrue(chord.is_boot_charger_mode(cmd))
|
||||
|
||||
def test_can_auto_suspend_protects_screen_usb_host_ssh_and_inhibit(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
base = Path(tmp)
|
||||
sys_root = base / 'sys'
|
||||
proc_net = base / 'proc_net'
|
||||
inhibit = base / 'inhibit'
|
||||
(sys_root / 'class/net/usb0').mkdir(parents=True)
|
||||
(sys_root / 'class/power_supply/pm660-charger').mkdir(parents=True)
|
||||
proc_net.mkdir()
|
||||
|
||||
(sys_root / 'class/net/usb0/carrier').write_text('0\n')
|
||||
(sys_root / 'class/power_supply/pm660-charger/usb_type').write_text('Unknown SDP [DCP] CDP\n')
|
||||
(proc_net / 'tcp').write_text(' sl local_address rem_address st\n')
|
||||
(proc_net / 'tcp6').write_text(
|
||||
' sl local_address rem_address st\n'
|
||||
' 0: 00000000000000000000000000000000:0016 00000000000000000000000000000000:0000 0A\n')
|
||||
|
||||
# Idle battery/DCP with listening sshd only -> safe to suspend
|
||||
self.assertEqual(chord.can_auto_suspend(False, sys_root, proc_net, inhibit)[0], True)
|
||||
# Screen ON blocks
|
||||
self.assertEqual(chord.can_auto_suspend(True, sys_root, proc_net, inhibit), (False, 'screen on'))
|
||||
# Inhibit file blocks
|
||||
inhibit.write_text('1')
|
||||
self.assertEqual(chord.can_auto_suspend(False, sys_root, proc_net, inhibit), (False, 'inhibit file'))
|
||||
inhibit.unlink()
|
||||
# Active USB NCM SDP host blocks
|
||||
(sys_root / 'class/net/usb0/carrier').write_text('1\n')
|
||||
(sys_root / 'class/power_supply/pm660-charger/usb_type').write_text('Unknown [SDP] DCP CDP\n')
|
||||
self.assertEqual(chord.can_auto_suspend(False, sys_root, proc_net, inhibit), (False, 'usb data host'))
|
||||
(sys_root / 'class/net/usb0/carrier').write_text('0\n')
|
||||
# Established SSH session on :0016 blocks
|
||||
(proc_net / 'tcp').write_text(
|
||||
' sl local_address rem_address st\n'
|
||||
' 5: 012A10AC:0016 022A10AC:ED34 01\n')
|
||||
self.assertEqual(chord.can_auto_suspend(False, sys_root, proc_net, inhibit), (False, 'active ssh session'))
|
||||
|
||||
def test_set_cpu_standby_clamps_and_restores_clusters(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp) / 'cpufreq'
|
||||
p0 = root / 'policy0'
|
||||
p1 = root / 'policy1'
|
||||
p0.mkdir(parents=True)
|
||||
p1.mkdir(parents=True)
|
||||
|
||||
(p0 / 'cpuinfo_max_freq').write_text('2208000\n')
|
||||
(p0 / 'scaling_min_freq').write_text('300000\n')
|
||||
(p0 / 'scaling_available_frequencies').write_text('300000 1113600 2208000\n')
|
||||
(p0 / 'scaling_max_freq').write_text('2208000\n')
|
||||
|
||||
(p1 / 'cpuinfo_max_freq').write_text('1843200\n')
|
||||
(p1 / 'scaling_min_freq').write_text('300000\n')
|
||||
(p1 / 'scaling_available_frequencies').write_text('300000 633600 902400 1843200\n')
|
||||
(p1 / 'scaling_max_freq').write_text('1843200\n')
|
||||
|
||||
res_std = chord.set_cpu_standby('standby', cpufreq_root=root)
|
||||
self.assertEqual(res_std, {'policy0': 300000, 'policy1': 633600})
|
||||
self.assertEqual((p0 / 'scaling_max_freq').read_text().strip(), '300000')
|
||||
self.assertEqual((p1 / 'scaling_max_freq').read_text().strip(), '633600')
|
||||
|
||||
res_chg = chord.set_cpu_standby('charger', cpufreq_root=root)
|
||||
self.assertEqual(res_chg, {'policy0': 300000, 'policy1': 300000})
|
||||
self.assertEqual((p1 / 'scaling_max_freq').read_text().strip(), '300000')
|
||||
|
||||
res_act = chord.set_cpu_standby('active', cpufreq_root=root)
|
||||
self.assertEqual(res_act, {'policy0': 2208000, 'policy1': 1843200})
|
||||
self.assertEqual((p0 / 'scaling_max_freq').read_text().strip(), '2208000')
|
||||
self.assertEqual((p1 / 'scaling_max_freq').read_text().strip(), '1843200')
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
chord.set_cpu_standby('invalid', cpufreq_root=root)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
"""Verify telemetry collection and BGRX framebuffer rendering for platina-status-screen."""
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
spec = importlib.util.spec_from_file_location('status_screen', ROOT / 'scripts/phone-status-screen.py')
|
||||
screen = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(screen)
|
||||
|
||||
|
||||
class StatusScreenTests(unittest.TestCase):
|
||||
def _build_fixtures(self, base):
|
||||
sys_dir = base / 'sys'
|
||||
proc_dir = base / 'proc'
|
||||
bat = sys_dir / 'class/power_supply/qcom-battery'
|
||||
chg = sys_dir / 'class/power_supply/pm660-charger'
|
||||
ipa = sys_dir / 'devices/platform/soc@0/147c0000.ipa/modem'
|
||||
usb0 = sys_dir / 'class/net/usb0'
|
||||
for d in (bat, chg, ipa, usb0, proc_dir):
|
||||
d.mkdir(parents=True, exist_ok=True)
|
||||
(bat / 'capacity').write_text('78\n')
|
||||
(bat / 'status').write_text('Not charging\n')
|
||||
(bat / 'voltage_now').write_text('4050000\n')
|
||||
(bat / 'temp').write_text('315\n')
|
||||
(chg / 'online').write_text('1\n')
|
||||
(chg / 'usb_type').write_text('Unknown [SDP] DCP CDP\n')
|
||||
(chg / 'charge_behaviour').write_text('auto [inhibit-charge] force-discharge\n')
|
||||
(ipa / 'datapath_ready').write_text('1\n')
|
||||
(usb0 / 'carrier').write_text('1\n')
|
||||
(proc_dir / 'uptime').write_text('3661.2 14000.0\n')
|
||||
(proc_dir / 'loadavg').write_text('0.12 0.08 0.05 1/180 42\n')
|
||||
(proc_dir / 'meminfo').write_text('MemTotal: 4000000 kB\nMemAvailable: 3000000 kB\n')
|
||||
return sys_dir, proc_dir
|
||||
|
||||
def test_collect_telemetry_reads_fixtures_and_commands(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
sys_dir, proc_dir = self._build_fixtures(Path(tmp))
|
||||
|
||||
def fake_run(cmd, **kwargs):
|
||||
if cmd[:4] == ['ip', '-4', 'route', 'show']:
|
||||
return subprocess.CompletedProcess(
|
||||
cmd, 0, 'default via 10.75.105.57 dev qmapmux0.0 metric 700\n', '')
|
||||
if cmd[:4] == ['ip', '-4', '-o', 'addr']:
|
||||
return subprocess.CompletedProcess(
|
||||
cmd, 0,
|
||||
'2: usb0 inet 172.16.42.1/24 brd 172.16.42.255\n'
|
||||
'5: tun0 inet 192.168.20.10/24\n'
|
||||
'6: qmapmux0.0 inet 10.75.105.56/28\n', '')
|
||||
if cmd[:2] == ['mmcli', '-m']:
|
||||
return subprocess.CompletedProcess(
|
||||
cmd, 0,
|
||||
'modem.generic.state : connected\n'
|
||||
'modem.3gpp.operator-name : CHN-UNICOM\n'
|
||||
'modem.generic.access-technologies.value[1] : lte\n'
|
||||
'modem.generic.signal-quality.value : 97\n', '')
|
||||
return subprocess.CompletedProcess(cmd, 1, '', '')
|
||||
|
||||
data = screen.collect_telemetry(sys_path=sys_dir, proc_path=proc_dir, run=fake_run)
|
||||
self.assertEqual(data['battery']['capacity'], 78)
|
||||
self.assertTrue(data['battery']['inhibited'])
|
||||
self.assertEqual(data['battery']['power_state'], 'Paused (80% Guard)')
|
||||
self.assertEqual(data['battery']['voltage_v'], 4.05)
|
||||
self.assertEqual(data['battery']['temp_c'], 31.5)
|
||||
self.assertEqual(data['cellular']['operator'], 'CHN-UNICOM')
|
||||
self.assertEqual(data['cellular']['signal_percent'], 97)
|
||||
self.assertTrue(data['cellular']['is_default'])
|
||||
self.assertEqual(data['network']['tun0_ip'], '192.168.20.10')
|
||||
|
||||
def test_render_status_and_charger_bgrx_format_and_speed(self):
|
||||
telemetry = {
|
||||
'timestamp': '2026-11-17 22:30:00',
|
||||
'clock': '22:30:00',
|
||||
'date': '2026-11-17',
|
||||
'uptime_s': 1234.0,
|
||||
'uptime_str': '00h 20m 34s',
|
||||
'load_avg': '0.10 0.08 0.05',
|
||||
'mem_used_mb': 950,
|
||||
'mem_total_mb': 3800,
|
||||
'battery': {
|
||||
'capacity': 78,
|
||||
'status': 'Charging',
|
||||
'power_state': 'Charging',
|
||||
'voltage_v': 4.05,
|
||||
'temp_c': 31.3,
|
||||
'charger_online': True,
|
||||
'usb_type': 'DCP',
|
||||
'inhibited': False,
|
||||
},
|
||||
'cellular': {
|
||||
'datapath_ready': True,
|
||||
'state': 'connected',
|
||||
'operator': 'CHN-UNICOM',
|
||||
'access_tech': 'lte',
|
||||
'signal_percent': 97,
|
||||
'ip': '10.75.105.56',
|
||||
'is_default': True,
|
||||
},
|
||||
'network': {
|
||||
'default_dev': 'qmapmux0.0',
|
||||
'wlan0_ip': None,
|
||||
'usb0_ip': '172.16.42.1',
|
||||
'usb0_carrier': False,
|
||||
'tun0_ip': '192.168.20.10',
|
||||
},
|
||||
}
|
||||
expected_len = 1080 * 2280 * 4
|
||||
for mode in ('status', 'charger'):
|
||||
t0 = time.monotonic()
|
||||
raw = screen.render_dashboard_bgrx(telemetry, mode=mode)
|
||||
elapsed = time.monotonic() - t0
|
||||
self.assertEqual(len(raw), expected_len)
|
||||
self.assertLess(elapsed, 0.5)
|
||||
# Every BGRX pixel keeps byte 3 (X padding) as 0 and includes non-background pixels
|
||||
self.assertEqual(set(raw[3::4]), {0})
|
||||
self.assertNotEqual(bytes(raw), screen.COL_BG * (1080 * 2280))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user