Files
rockblock9704-zephyr/python/tests/test_library.py
T
scottp 917522d1f4 Python: the rb9704 command line, a fake modem, and the tests
rb9704 drives a 9704 on USB and the Cloudloop account behind it, moved
from WII6's host/rockblock with its project names taken out. rb9704-fake
speaks JSPR on a pty or a serial port: everything the library asks, MO in
segments with the CRC checked, MT, signal, provisioning, refusals and
failures on command.

The tests run against the fake at every level: the fake itself, the
command line, Ground Control's Python binding, the shell sample on
native_sim, and the sample on a board (test_zephyr.py, one suite through
two consoles). test_real.py makes free checks against a real modem.
2026-10-09 12:48:16 +11:00

57 lines
1.5 KiB
Python

"""
Ground Control's own Python binding (the rockblock9704 package, the same C
library this repository builds into Zephyr) against the fake modem on a pty.
The fake runs in a process of its own: the binding holds the GIL through
every blocking call.
"""
import time
import pytest
rb = pytest.importorskip("rockblock9704")
@pytest.fixture
def modem(fake):
m = rb.RockBlock9704()
assert m.begin(fake.port)
yield m
m.end()
def poll_until(m, cond, secs=10):
end = time.monotonic() + secs
while time.monotonic() < end:
m.poll()
if cond():
return True
time.sleep(0.01)
return False
def test_identity(modem):
assert modem.get_imei() == "300434030000000"
assert modem.get_iccid() == "8988169712345678901"
assert modem.get_firmware_version() == "v1.2.3"
assert modem.get_signal() == 5
def test_send_async(modem, fake):
done = []
modem.set_mo_message_complete_callback(lambda mid, status: done.append(status))
assert modem.send_message_async(b"from-python", 244)
assert poll_until(modem, lambda: done)
assert done == [1]
m = fake.out.expect(r"^MO 244 \d+ (\w+)")
assert bytes.fromhex(m.group(1)) == b"from-python"
def test_receive_async(modem, fake):
got = []
modem.set_mt_message_complete_callback(lambda mid, status: got.append(status))
fake.cmd("mt 244 to-python")
assert poll_until(modem, lambda: got)
assert modem.receive_message_async() == b"to-python"
assert modem.acknowledge_receive_head_async()