Run the overnight bench test on the spare board, and document it
Track the bench scripts (run_overnight.py and its stages, the link and ITS client libraries, the phone-vs-node comparison) with the first reports. Changes for the spare XIAO (no cell): - run_overnight.py picks the single Espressif board by default and refuses to test a build that is not this checkout's HEAD. - The unsigned soak stops as "transmit path wedged" after 40 resource_limit refusals in a row and tries whether a repeated STATION_CONFIGURE clears it. - "Refused requests put nothing on the radio" counts only own transmissions; frames heard from other stations are copied by RAW_CAPTURE too. - start_overnight.ps1: optional build and flash, host C tests in the background, Windows kept awake. setup_workstation.ps1 checks and installs git, Python 3.11, pyserial, asn1tools, MSYS2 gcc and make, ESP-IDF 6.0.2. - obu-firmware/docs/overnight-bench-test.tex (and PDF) describe the test, the workstation set-up and the findings of the 2026-11-25 runs.
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
# Bench tests for obu-firmware
|
||||
|
||||
Scripts for testing the firmware on a real board (one micrOBU on a USB port) and for comparing a phone log with a
|
||||
second receiver's capture. The board tests are Python 3.11 with `pyserial` only (`asn1tools` is for the host replay check
|
||||
in [`../host`](../host/README.md), where the PC-side C tests live).
|
||||
|
||||
**Which board:** the overnight run is for the **spare** XIAO ESP32-C5 (no cell), never the production OBU. It resets the board
|
||||
every time it opens the port, reconfigures it for hours and writes the demo ticket to its NVS. On the lab bench (2026-11-25):
|
||||
COM10 production OBU with the cell, **COM6 spare**, COM4 V2X node, COM8 simulated car (CH343). Plug only the spare into the
|
||||
home workstation; its port number there will differ, and `auto` finds it. A board without a cell still reports
|
||||
`battery_mv` of about 4000 (the USB charger node), so the battery reading cannot tell the boards apart.
|
||||
|
||||
| Script | What it does |
|
||||
|---|---|
|
||||
| `start_overnight.ps1` | **the one command**: optionally builds and flashes this checkout (`-Flash`), starts the host C tests in the background, runs the board tests, keeps Windows awake |
|
||||
| `setup_workstation.ps1` | checks, and installs what is missing, for a PC that has to do all of the above (see "Setting up a workstation") |
|
||||
| `run_overnight.py` | the overnight run: schedules the stages below, watches for resets and heap leaks, writes the report. Refuses a board whose firmware is not this checkout's HEAD (`--allow-stale-firmware`) |
|
||||
| `bench_conformance.py` | stage 1: the link protocol against the spec and the firmware source, ~100 checks |
|
||||
| `bench_soak.py` | stage 2: transmit soak (unsigned, signed), capture-mode toggling, reconfiguration, idle listening, resets |
|
||||
| `bench_fuzz.py` | stage 3: seeded garbage on the link while the station is unconfigured (never on air) |
|
||||
| `linklib.py`, `itslib.py`, `bench_common.py` | the station-link client, a port of `gn_unwrap.c` and pcap reader, the result log |
|
||||
| `compare_phone_vs_node.py` | what the phone's V2X log missed against a pcap recorded at the same time |
|
||||
| `run_host_tests_overnight.ps1` | `make check` of `../host`, then the gn_unwrap fuzzer with new seeds until the time is up (needs MSYS2) |
|
||||
|
||||
## Overnight run on a board
|
||||
|
||||
Close everything that holds the port first (phone app over USB, `station_status_watch.py`, a serial monitor): opening
|
||||
the port resets the board.
|
||||
|
||||
```powershell
|
||||
git pull
|
||||
powershell -ExecutionPolicy Bypass -File obu-firmware\test\bench\start_overnight.ps1 -Flash -Quick # about 8 minutes: does it all work?
|
||||
powershell -ExecutionPolicy Bypass -File obu-firmware\test\bench\start_overnight.ps1 -Flash -Hours 8 # the overnight run
|
||||
```
|
||||
|
||||
`-Flash` builds this checkout and writes it to the board, so the run tests the code you are looking at (the first build
|
||||
downloads components and takes about 20 minutes). Add `-Port COM6` when more than one Espressif board is plugged in. Without
|
||||
`start_overnight.ps1`, the board part alone is
|
||||
`py -3.11 obu-firmware\test\bench\run_overnight.py COM6 --hours 8 --provision-demo`.
|
||||
|
||||
Results go to `obu-firmware/test/results/overnight-<time>/`: `report.txt` (read this), `results.json`, `status.csv`
|
||||
(STATUS once every few seconds: heap, counters), `device.log` (the board's log lines), `boot.log` (ROM and bootloader
|
||||
text, panics), `run.log`.
|
||||
|
||||
### What a cycle (about 45 minutes) does
|
||||
|
||||
1. **soak-unsigned**: BTP requests at 4 Hz, payload sizes 24 to 1480 octets in turn (494 and 495 are the V2X_RX edge).
|
||||
If 40 requests in a row are refused with `resource_limit` the phase stops as "transmit path wedged" (seen 4 times in 11
|
||||
cycles on 2026-11-25 with the Nov 10 build) and a repeated `STATION_CONFIGURE` is tried to see whether it clears.
|
||||
2. **soak-signed** (needs a ticket): the same at 3 Hz, sizes up to 1398, signed with the demo chain.
|
||||
3. **raw-toggle**: `RAW_CAPTURE` modes 0x00/0x01/0x03/0x05/0x07 in turn while transmitting: copies of the station's own frames
|
||||
must appear exactly in the modes with the own-TX bit.
|
||||
4. **reconfigure**: `STATION_CONFIGURE` every second or two with a new MAC, security on/off, radio TX+RX or RX only.
|
||||
5. **fuzz**: reset the board, then random frames for a few minutes.
|
||||
6. **resets**: reopen the port five times; each time the board must boot, configure and transmit.
|
||||
7. **idle-listen**: radio receive-only, STATUS once a second; counts whatever else is on the air.
|
||||
|
||||
The run starts and ends with the conformance stage (which also resets the board), so a drift shows as a different result.
|
||||
|
||||
### How a transmitted frame is proven
|
||||
|
||||
On one board there is no second receiver, so the test uses the station's own `RAW_CAPTURE` mode 0x05: every frame the
|
||||
station submits to the radio is copied back over the link (`RAW_FRAME`). The test unwraps the copy with `itslib.unwrap` (a Python
|
||||
port of `gn_unwrap.c`, written separately from the firmware), and compares the ITS payload with what it sent. The payload
|
||||
carries its own size and CRC-32, so truncation or a bit error in fragmentation or TX is caught. This does not prove that
|
||||
another station can hear it; the compare script covers that when a second receiver records alongside.
|
||||
|
||||
### On the air
|
||||
|
||||
- Transmit phases send frames at 4 Hz at most, 5 dBm (`--power`), channel 180. The payload is a made-up ItsPduHeader
|
||||
(protocolVersion 2, **messageID 0xF1**, stationId 0x7E57B0A7): not an assigned ETSI message, so a receiving stack refuses
|
||||
it. MACs are locally administered, `02:b3:0a:ce:xx:xx`.
|
||||
- `--no-tx` keeps the radio silent: only the protocol, fuzz, reset and idle stages run, and the checks that need a frame on
|
||||
the radio are skipped.
|
||||
- The fuzz stage starts on a freshly reset, unconfigured station and sends no `STATION_CONFIGURE` that decodes, so the radio never
|
||||
starts. It never sends `CREDENTIALS_*`, the PKI requests or the trust bootstrap/update.
|
||||
- `--provision-demo` writes `app/src/main/assets/demo-chain.vcr` (the throwaway chain the app provisions on its first
|
||||
connect) to the board's NVS if it holds no ticket. `CREDENTIALS_ERASE` removes it again.
|
||||
|
||||
### Reading the report
|
||||
|
||||
`FAIL` is a check that contradicts the spec, the firmware source or what the radio did. `WARN` is a counter that disagrees,
|
||||
a heap trend, a version mismatch. `INFO` is something the source leaves open, reported with the observed value. The first
|
||||
lines say which firmware the board runs (`app_init` log) against this checkout's HEAD: a board that runs an older build tests
|
||||
that build.
|
||||
|
||||
A fuzz failure prints the seed and the last frames as hex; replay with `--fuzz-seed N` (the fuzz stage of the first cycle uses it).
|
||||
|
||||
## Phone log against a node's pcap
|
||||
|
||||
```powershell
|
||||
& $py obu-firmware\test\bench\compare_phone_vs_node.py "databases\<phone log>.db" "databases\<capture>.pcap" --csv misses.csv
|
||||
```
|
||||
|
||||
Unwraps the pcap, aligns the clocks through the CAMs both saw byte for byte, matches the rest one to one (±0.5 s, identical
|
||||
bytes), and prints per type and size, per station, when the misses fall, what the board's counters say, and what only the phone
|
||||
heard. Two receivers at different places lose different frames, so compare runs with each other, not with 100 %.
|
||||
Reports of the 2026-11-23 runs are in `../results/`.
|
||||
|
||||
## Setting up a workstation
|
||||
|
||||
`setup_workstation.ps1 -CheckOnly` reports what is missing; without `-CheckOnly` it installs it (about 3 GB, 20 to 40
|
||||
minutes, needs internet; run it again after a failure). It was written after the first home run (2026-11-25) found no
|
||||
ESP-IDF on the workstation, so the board there ran a stale build.
|
||||
|
||||
| Needed | Why | Installed by the script as |
|
||||
|---|---|---|
|
||||
| Git, `core.longpaths true` | `git pull` of this repo; ESP-IDF's tree has paths over 260 characters | `winget install Git.Git` |
|
||||
| Python 3.11 (`py -3.11`) | the board tests and `check_replay.py` | `winget install Python.Python.3.11` |
|
||||
| `pyserial` | the station link to the board | `py -3.11 -m pip install --user pyserial` |
|
||||
| `asn1tools` | `check_replay.py` in the host tests (not the board tests) | `py -3.11 -m pip install --user asn1tools` |
|
||||
| MSYS2 UCRT64 `gcc` and `make` | the PC-side C tests (`make check`) | `winget install MSYS2.MSYS2`, then `pacman -S mingw-w64-ucrt-x86_64-gcc make` |
|
||||
| **ESP-IDF 6.0.2**, target esp32c5, in `C:\Espressif` | build and flash the firmware (**exactly 6.0.2**: `components/microbu_v2x` pins the radio driver ABI to it) | `git clone --branch v6.0.2 --recursive` into `C:\Espressif\frameworks\esp-idf-v6.0.2`, then `install.ps1 esp32c5` |
|
||||
|
||||
Also needed, but nothing to install: internet on the first build (`idf.py` downloads `espressif/esp-boost` into
|
||||
`managed_components/`, about 125 MB), and a USB-C cable into the spare's single port (the native USB Serial/JTAG appears as a
|
||||
COM port with the Windows built-in driver; no CH343 driver is needed for the spare). Not needed at home: Android Studio,
|
||||
Java, a phone.
|
||||
|
||||
Before leaving it overnight: `setup_workstation.ps1 -PreventSleep` turns off sleep, hibernate, display-off and USB selective
|
||||
suspend on mains power (`start_overnight.ps1` also holds Windows awake while it runs, but a USB port that suspends still drops
|
||||
the board). Pause Windows Update, and plug the PC into mains.
|
||||
|
||||
Not in git, so absent on a fresh checkout: `its-g5-receiver-firmware/recordings/*.pcap` (the host replay test skips itself with
|
||||
a message without them), `vanetza/` (`check_replay.py` then does not decode the 1609.2 envelopes independently),
|
||||
`firmware-backups/`. Copy the recordings over if the home run should replay them.
|
||||
|
||||
**Flashing trouble:** if the build works but the flash says "No serial data received", unplug the board, hold BOOT, plug in,
|
||||
release, flash again, then unplug and replug without BOOT. If the stub flasher will not start, use the `--no-stub` recipe in
|
||||
[`../../FLASHING.md`](../../FLASHING.md).
|
||||
|
||||
## Python
|
||||
|
||||
`py -3.11` works once a new terminal has opened after the install; the full path in `$py` always does. Packages:
|
||||
`py -3.11 -m pip install --user pyserial asn1tools`.
|
||||
Reference in New Issue
Block a user