Files
rockblock9704-zephyr/docs/TESTING.md
T
scottp d08364ce58 Sample: the M5Stamp-C3, the shell over WiFi, and the control lines wired
overlay-wifi.conf puts the shell on telnet on any ESP32. At boot it joins
the network stored in flash with `wifi cred add`, and rejoins it after a
drop, for a board out under the sky with no USB.

The M5Stamp-C3 (ESP32-C3, RISC-V) has an overlay: the modem on uart1,
GPIO4 and GPIO5, with P_EN, I_EN and I_BTD on GPIO10, 6 and 7. Its RGB
LED, driven by spi2 on GPIO2, shows the modem's state, and its button
begins, asks for the signal and ends. docs/boards/stamp_c3.md has the
pins, the WiFi commands and the LED's colours. So far it has run WiFi
and telnet, not yet the modem.

The ESP32-S3-DevKitC, ESP32 DevKitC and NUCLEO-U575ZI-Q overlays now
wire the three control lines as well; the table is in docs/TESTING.md.

The README gives the Gitea home and the GitHub mirror, and the boards
as a table of CPU and what each has run.
2026-10-25 13:54:09 +11:00

164 lines
6.6 KiB
Markdown

# Testing
One fake modem, three places to run the code against it, and a few free
checks against a real modem.
| Level | What runs | Against | Needs |
| --- | --- | --- | --- |
| Python | Ground Control's Python binding, the `rb9704` command line, the fake itself | the fake on a pty | Python 3.10 to 3.14 |
| Host Zephyr | this module in the shell sample on `native_sim` | the fake on a pty, or a real modem on USB | a Zephyr workspace |
| Board | the same sample on an ESP32-S3, STM32U5 or any board | the fake on a USB-serial port wired to the board's modem pins | a board and a wire |
The native_sim and board runs are the same tests (`python/tests/test_zephyr.py`)
through a different console, so a behaviour seen on one is checked on the
other.
## The fake modem
`python/rb9704tools/fakemodem.py`, `rb9704-fake` on the command line. It
implements JSPR as `JSPR.md` describes it: the three exchanges `rbBegin`
needs, the identity and signal getters, provisioning, MO in segments of
any size with the CRC checked, MT in segments the library can take, and
on command a refusal, a failed MO, a signal change or a change of
provisioning. It writes every whole MO it receives as an event line, so a
test checks the bytes that reached "the network".
What it cannot tell you is what a real modem does that the library's
source does not show: unsolicited lines at odd moments, timing, MT
segment sizes. That is what `test_real.py` and the hardware are for.
## Running them
```sh
python/install.sh
# Python level: the fake, the command line, Ground Control's binding
python/.venv/bin/pytest -q python/tests
# Host Zephyr: build the sample for native_sim, then
west build -b native_sim/native/64 samples/shell -d build/native
python/.venv/bin/pytest -q python/tests --zephyr-exe build/native/zephyr/zephyr.exe
# Board: flash the sample with its modem UART wired to a USB-serial
# adapter (3.3 V), then the board's shell port and the adapter's port
python/.venv/bin/pytest -q python/tests/test_zephyr.py \
--board-console /dev/ttyACM0 --board-modem /dev/ttyUSB0
# A real modem, free checks only (identity and signal, never a message)
python/.venv/bin/pytest -q python/tests/test_real.py --real-modem /dev/ttyUSB0 \
[--zephyr-exe build/native/zephyr/zephyr.exe]
```
Every option has an environment variable as well: `RB9704_ZEPHYR_EXE`,
`RB9704_BOARD_CONSOLE`, `RB9704_BOARD_MODEM`, `RB9704_REAL_MODEM`.
On native_sim the modem UART is a `zephyr,native-tty-uart` node
(`samples/shell/boards/native_sim.overlay`); the tests give it the fake's
pty with `-modem_uart_port=`. The same option takes a real modem's
`/dev/ttyUSB0`, which is how host Zephyr talks to real hardware.
## The rig: two boards, one wire
No USB-serial adapter to hand? Two boards with a UART wired between them
will do: one runs the sample, the other runs `tests/rig/bridge`, which
copies bytes between that UART and its own USB serial port, where the
fake answers.
```
host --USB-- bridge board --UART-- board under test --USB-- host
(tests/rig/bridge) (samples/shell)
fake modem on this port pytest drives this shell
```
The overlays in `tests/rig/` are for a NUCLEO-U575ZI-Q (USART2 on PD5 and
PD6) and a Seeed XIAO ESP32S3 (D8 and D9) wired to each other, either way
round:
| Under test | Bridge | `--board-console` | `--board-modem` |
| --- | --- | --- | --- |
| XIAO ESP32S3, `-DDTC_OVERLAY_FILE=tests/rig/xiao_esp32s3_rig.overlay` | Nucleo, `tests/rig/bridge` | the XIAO's USB | the Nucleo's ST-LINK port |
| Nucleo, `-DDTC_OVERLAY_FILE=tests/rig/nucleo_u575zi_q_rig.overlay` | XIAO, `tests/rig/bridge` | the Nucleo's ST-LINK port | the XIAO's USB |
The ESP32-S3 sits in its ROM loader after `west flash` until it is reset;
toggle RTS on its USB port, or press reset, before the tests.
## Out of doors: the shell over WiFi
A real modem needs the sky, and the sky is rarely where the USB cable
reaches. `samples/shell/overlay-wifi.conf` puts the same shell on telnet,
on any ESP32 board, so the board needs only power:
```sh
west build -b stamp_c3 samples/shell -- -DEXTRA_CONF_FILE=overlay-wifi.conf
west flash
```
Once, on the USB console, store the network; it is kept in flash:
```
wifi cred add -s "<SSID>" -k 1 -p "<password>"
```
At every boot after, the board joins it, logs `address 192.168.1.50:
telnet 192.168.1.50`, and rejoins after a drop. A network added after boot
is joined within 30 s. `wifi cred list` and `wifi cred delete <SSID>` look
after the stored list; `net iface` shows the address again.
```sh
telnet 192.168.1.50
rb9704 begin
rb9704 spy on
rb9704 info
```
Telnet has no password and no encryption, and `rb9704 send` costs
airtime: use it on a network you trust.
The Linux `telnet` client stays in line mode, where the up arrow and line
editing do nothing: `Ctrl-]` then `mode character` fixes it, or connect
with `socat -,rawer,escape=0x1d TCP:<address>:23`.
On the M5Stamp-C3 the board's RGB LED shows the modem's state and its
button begins and ends it; `boards/stamp_c3.md` has the table, the pins
and the WiFi commands.
### Wiring
The board overlays for the M5Stamp-C3, ESP32-S3-DevKitC, ESP32 DevKitC
and NUCLEO-U575ZI-Q wire all three control lines, so `rb9704 begin`
powers the modem up in order and waits for it to say it has booted.
| 9704 | M5Stamp-C3 | ESP32-S3-DevKitC | ESP32 DevKitC | NUCLEO-U575ZI-Q |
| --- | --- | --- | --- | --- |
| RX (board TX) | GPIO4 | GPIO17 | GPIO17 | PD8 |
| TX (board RX) | GPIO5 | GPIO18 | GPIO16 | PD9 |
| P_EN | GPIO10 | GPIO6 | GPIO27 | PF15 (D2) |
| I_EN | GPIO6 | GPIO4 | GPIO25 | PF14 (D4) |
| I_BTD | GPIO7 | GPIO5 | GPIO26 | PF13 (D7) |
| GND | GND | GND | GND | GND |
The modem's supply is its own, at the voltage and peak current Ground
Control's manual gives, not the board's 3.3 V regulator. With `booted-gpios` in the overlay,
`rb9704 begin` waits up to 30 s for I_BTD. A fake modem on a USB-serial
adapter in place of the 9704 has no I_BTD, so tie the board's I_BTD pin
to 3.3 V for those runs, or build with the rig overlays, which have no
control lines.
## What has passed
On 2026-10-09, Zephyr v4.4.0, Ground Control's library v1.0.1, the
binding 1.0.2:
| Level | Tests | Result |
| --- | --- | --- |
| Python: fake, command line, binding | 16 | all pass |
| `native_sim/native/64` against the fake | 12 | all pass |
| XIAO ESP32S3 through the rig | 12 | all pass |
| NUCLEO-U575ZI-Q through the rig | 12 | all pass |
| a real 9704 (firmware v1.5.14), binding and native_sim, free checks | 2 | all pass |
Not yet: a message through a real modem and satellite, which costs
airtime and needs the sky (`CLOUDLOOP.md`, "The order to test in"), the
power pins on a board that has them wired, and the shell over WiFi on a
board.