rb9704_cancel() and `rb9704 cancel` ask the modem to abandon the MO in flight; the modem's final status reaches mo_done as -ECANCELED. The library's async path has no timeout, so this is how an application frees a modem that has gone quiet mid-send. The status snapshot carries the in-flight message's id and start time for the application to decide with. rb9704_begin zeroes moQueuedMessages: rbBegin empties the queue but not the count, and a count above zero makes every later send queue without transmitting. The fake modem's mo-hold and mo-release stand in for a modem that has taken a message and said nothing more; a test drives cancel through it. Also: the shell's send buffer is a shell line, not a fourth message buffer; the bridge's TX-disable race has a comment; the CLI turns a Cloudloop error (a bad token's 200 reply included), an unopenable port and a one-word jspr line into one line and exit 1; conftest reads request.node; pyproject uses the current license spelling.
152 lines
4.2 KiB
Python
152 lines
4.2 KiB
Python
# SPDX-License-Identifier: MIT
|
|
# Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
|
"""
|
|
Zephyr, through the shell sample, against the fake modem: on native_sim
|
|
with --zephyr-exe, on a board with --board-console and --board-modem.
|
|
"""
|
|
|
|
import zlib
|
|
|
|
import pytest
|
|
|
|
|
|
def begin(z):
|
|
c, f = z
|
|
c.sh("rb9704 begin")
|
|
c.out.expect(r"begin: ok")
|
|
|
|
|
|
def test_begin_and_info(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
c.sh("rb9704 info")
|
|
c.out.expect(r"imei\s+300434030000000")
|
|
c.out.expect(r"firmware\s+v1\.2\.3")
|
|
c.out.expect(r"sim\s+card present, connected")
|
|
|
|
|
|
def test_begin_twice_is_already(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
c.sh("rb9704 begin")
|
|
c.out.expect(r"begin: -\d+ EALREADY")
|
|
|
|
|
|
def test_signal(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
f.cmd("signal 3")
|
|
c.out.expect(r"signal 3 bars")
|
|
c.sh("rb9704 signal")
|
|
c.out.expect(r"signal: 3 bars")
|
|
|
|
|
|
def test_send_reaches_the_network(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
c.sh("rb9704 send 244 hello-network")
|
|
c.out.expect(r"send: ok")
|
|
m = f.out.expect(r"^MO 244 (\d+) (\w+)")
|
|
assert bytes.fromhex(m.group(2)) == b"hello-network"
|
|
c.out.expect(r"mo done topic 244 id %s result 0" % m.group(1))
|
|
|
|
|
|
def test_send_in_many_segments(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
f.cmd("segment 16")
|
|
text = "".join(chr(ord("a") + i % 26) for i in range(150))
|
|
c.sh("rb9704 send 244 " + text)
|
|
m = f.out.expect(r"^MO 244 \d+ (\w+)")
|
|
assert bytes.fromhex(m.group(1)).decode() == text
|
|
c.out.expect(r"result 0")
|
|
|
|
|
|
def test_send_failure_reaches_the_callback(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
f.cmd("mo-fail network_error")
|
|
c.sh("rb9704 send 244 doomed")
|
|
c.out.expect(r"mo done topic 244 id \d+ result -\d+")
|
|
|
|
|
|
def test_send_refused_by_the_modem(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
f.cmd("mo-refuse")
|
|
c.sh("rb9704 send 244 refused")
|
|
c.out.expect(r"send: -\d+ EIO")
|
|
|
|
|
|
def test_cancel_a_send_the_modem_sits_on(zephyr):
|
|
"""The modem took the message and said nothing more, as one waiting for
|
|
a satellite does; cancel frees the module, and a send then goes."""
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
f.cmd("mo-hold")
|
|
c.sh("rb9704 send 244 stuck")
|
|
c.out.expect(r"send: ok")
|
|
m = f.out.expect(r"^MO 244 (\d+) ")
|
|
c.sh("rb9704 info")
|
|
c.out.expect(r"info: -\d+ EBUSY")
|
|
c.sh("rb9704 status")
|
|
c.out.expect(r"one in flight: topic 244 id %s" % m.group(1))
|
|
c.sh("rb9704 cancel")
|
|
c.out.expect(r"cancel: ok")
|
|
c.out.expect(r"mo done topic 244 id %s result -\d+" % m.group(1))
|
|
c.sh("rb9704 cancel")
|
|
c.out.expect(r"cancel: -\d+ ENOENT")
|
|
c.sh("rb9704 send 244 after-cancel")
|
|
c.out.expect(r"send: ok")
|
|
f.out.expect(r"^MO 244 \d+ ")
|
|
c.out.expect(r"result 0")
|
|
|
|
|
|
def test_topic_below_64_is_refused_here(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
c.sh("rb9704 send 10 nope")
|
|
c.out.expect(r"send: -\d+ EINVAL")
|
|
|
|
|
|
@pytest.mark.topics("")
|
|
def test_provisioning_that_arrives_later_is_seen(zephyr):
|
|
"""The library keeps the first answer for good; the module asks again."""
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
c.sh("rb9704 send 244 too-early")
|
|
# EACCES when the library asks first; EIO when it had 244 cached from an
|
|
# earlier test on the same boot and the modem refused the message.
|
|
c.out.expect(r"send: -\d+ (EACCES|EIO)")
|
|
f.cmd("topics 244")
|
|
c.sh("rb9704 send 244 now-provisioned")
|
|
c.out.expect(r"send: ok")
|
|
f.out.expect(r"^MO 244 ")
|
|
|
|
|
|
def test_message_from_the_network(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
f.cmd("mt 244 hello-buoy")
|
|
c.out.expect(r"mt topic 244 id \d+ len 10 crc %08x: hello-buoy$" % zlib.crc32(b"hello-buoy"))
|
|
c.sh("rb9704 status")
|
|
c.out.expect(r"mt\s+1 received")
|
|
|
|
|
|
def test_long_message_from_the_network(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
body = "".join(chr(ord("a") + i % 26) for i in range(1500)) # two MT segments
|
|
f.cmd("mt 244 " + body)
|
|
c.out.expect(r"mt topic 244 id \d+ len 1500 crc %08x: %s$"
|
|
% (zlib.crc32(body.encode()), body[:64]))
|
|
|
|
|
|
def test_end(zephyr):
|
|
c, f = zephyr
|
|
begin(zephyr)
|
|
c.sh("rb9704 end")
|
|
c.out.expect(r"end: ok")
|
|
c.sh("rb9704 send 244 after-end")
|
|
c.out.expect(r"send: -\d+ ENOTCONN")
|