Files

144 lines
17 KiB
TeX
Raw Permalink Normal View History

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[a4paper,left=18mm,right=18mm,top=18mm,bottom=18mm,headheight=13pt]{geometry}
\usepackage{xcolor}
\usepackage{array,longtable,booktabs}
\usepackage{fancyhdr,lastpage,needspace}
\usepackage[hidelinks]{hyperref}
\definecolor{ink}{HTML}{193447}
\setlength{\parindent}{0pt}
\setlength{\parskip}{4pt}
\setlength{\tabcolsep}{1.5mm}
\renewcommand{\arraystretch}{1.12}
\setlength{\emergencystretch}{3em}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[L]{\footnotesize Overnight bench test of the micrOBU firmware}
\fancyfoot[R]{\footnotesize\thepage\ / \pageref{LastPage}}
\renewcommand{\headrulewidth}{0pt}
\hypersetup{pdftitle={Overnight bench test of the micrOBU firmware}}
\newcommand{\cmd}[1]{\texttt{\small #1}}
\begin{document}
{\Large\bfseries\color{ink} Overnight bench test of the micrOBU firmware}\par
\smallskip
Revision 2, status 2026-11-27. Scripts: \cmd{obu-firmware/test/bench}.\newline Companion documents: \cmd{obu-firmware/test/bench/README.md}, \cmd{obu-firmware/test/host/README.md},\newline\cmd{obu-firmware/FLASHING.md}.\par
\section*{1\quad Purpose}
The test checks the integrity and function of \cmd{obu-firmware} on a real board over many hours, without a phone. A PC plays the phone over the USB station link, drives every kind of request, resets and reconfigures the board, listens to the air, and watches the board's own counters and heap. A second, board-free part runs the PC-side C tests and a long fuzz of the receive parser.
\section*{2\quad Boards}
\begin{longtable}{@{}P{22mm}P{32mm}P{108mm}@{}}
\toprule\textbf{Port (lab)} & \textbf{Board} & \textbf{Role}\\\midrule\endhead
COM10 & XIAO ESP32-C5 with cell & production OBU. Never used for this test.\\
\textbf{COM6} & XIAO ESP32-C5, no cell & \textbf{spare board: the board under test}, also taken home.\\
COM4 & ESP32-C5 & V2X node (a second station on the air).\\
COM8 & CH343 board & simulated car (CAM beacon).\\\bottomrule
\end{longtable}
The spare's single USB-C port is the chip's native USB Serial/JTAG (VID 303A, PID 1001). \textbf{Opening the port resets the board}, so nothing else may hold it (phone app, \cmd{station\_status\_watch.py}, serial monitor). A board without a cell still reports about 4000\,mV in \cmd{battery\_mv} (the USB charger node), so the battery value cannot tell the spare from the production board: plug in only the spare. The run writes the demo ticket to the board's NVS.
\section*{3\quad What a run does}
Every run starts and ends with the conformance stage, so drift shows as a different result. In between, cycles of about 45 minutes repeat until the time is up.
\begin{longtable}{@{}P{30mm}P{132mm}@{}}
\toprule\textbf{Stage} & \textbf{What it checks}\\\midrule\endhead
conformance & about 100 checks of the link protocol against the specification and the firmware source: opcodes, malformed lengths, fragment reassembly (1536-octet requests, gaps, 2\,s timeout, 8 pending), CRC and resynchronisation, configure and POTI, BTP requests, stale requests, counter wrap.\\
soak-unsigned & BTP requests at 4\,Hz, payload 24 to 1480 octets in turn (494 and 495 are the V2X\_RX edge). Every accepted request must reach the radio driver byte for byte, with the MAC the phone named. 40 refusals (\cmd{resource\_limit}) in a row end the phase as ``transmit path wedged'', and a repeated configure is tried.\\
soak-signed & the same at 3\,Hz up to 1200 octets, signed with the demo chain; \cmd{sign\_failed} must stay 0.\\
raw-toggle & \cmd{RAW\_CAPTURE} modes 0x00, 0x01, 0x03, 0x05, 0x07 in turn: copies of the station's own frames must appear exactly in the modes with the own-TX bit.\\
reconfigure & \cmd{STATION\_CONFIGURE} every second or two with a new MAC, security on or off, radio TX+RX or RX only; the next frame must carry the new MAC and security.\\
fuzz & the board is reset, then seeded random frames are sent while it is unconfigured, so nothing reaches the radio. Heap afterwards must be within 8\,KB.\\
resets & the port is reopened five times; each time the board must boot, come back unconfigured, configure and transmit.\\
idle-listen & radio receive-only, STATUS once a second; counts what else is on the air and checks the receive queue never overflows.\\\bottomrule
\end{longtable}
\textbf{How a transmitted frame is checked.} One board has no second receiver, so the test uses \cmd{RAW\_CAPTURE} mode 0x05: every frame the station submits to the radio is copied back over the link. The copy is unwrapped by a Python port of \cmd{gn\_unwrap.c} written separately from the firmware, and its ITS payload is compared with what was sent. The payload carries its own size and CRC-32. The copy is made when the radio driver \emph{accepts} the frame, not when it reports the transmission complete, so it proves neither that the frame went on the air nor that another station can hear it (section 7). The driver's completion count is in \cmd{device.log} (\cmd{TX observation: submitted= completed=}); the test does not check it yet.
\textbf{On the air.} Transmit phases send at most 4 frames per second at 5\,dBm on channel 180. The payload is a made-up ItsPduHeader with messageID \cmd{0xF1}, which is not an assigned ETSI message, so receivers refuse it. MACs are locally administered, \cmd{02:b3:0a:ce:xx:xx}. \cmd{--no-tx} keeps the radio silent.
\textbf{PC-side tests} (\cmd{run\_host\_tests\_overnight.ps1}, no board): \cmd{make check} of \cmd{test/host} (chain test, replay of recorded captures, fuzz, battery policy, firmware unit tests, fragments), then the \cmd{gn\_unwrap} fuzzer with new seeds until the time is up. A \cmd{CRASH} line or a non-zero exit is a failure. The script's search for that line currently also matches ``no crash'' (section 7).
\section*{4\quad Running it}
Close everything that holds the port, run \cmd{git pull}, then from the repository root:
\begin{center}\small\texttt{powershell -ExecutionPolicy Bypass -File obu-firmware\textbackslash test\textbackslash bench\textbackslash start\_overnight.ps1 -Flash -Hours 8}\end{center}
\begin{longtable}{@{}P{34mm}P{128mm}@{}}
\toprule\textbf{Option} & \textbf{Effect}\\\midrule\endhead
\cmd{-Flash} & builds this checkout with ESP-IDF 6.0.2 and writes it to the board first (first build about 20 minutes: components are downloaded).\\
\cmd{-Quick} & about 8 minutes on the board, no host fuzz: does it all work?\\
\cmd{-Port COMx} & names the board; the default finds the one Espressif USB board plugged in and refuses if there are several.\\
\cmd{-NoTx} & the radio stays silent: protocol, fuzz, resets and idle only.\\
\cmd{-NoHostTests} & skips the PC-side C tests.\\\bottomrule
\end{longtable}
The script keeps Windows awake while it runs. \cmd{run\_overnight.py} refuses a board whose firmware is not this checkout's HEAD (\cmd{--allow-stale-firmware} overrides), because the results would then describe another build. Exit status: 0 if no check failed, 1 otherwise, 2 if the board does not speak the station link.
\section*{5\quad Setting up the workstation}
\cmd{setup\_workstation.ps1 -CheckOnly} reports what is missing; without \cmd{-CheckOnly} it installs it (about 3\,GB, 20 to 40 minutes, internet needed). It can be run again after a failure.
\begin{longtable}{@{}P{44mm}P{62mm}P{56mm}@{}}
\toprule\textbf{Needed} & \textbf{Why} & \textbf{Installed as}\\\midrule\endhead
Git, \cmd{core.longpaths true} & \cmd{git pull}; ESP-IDF paths exceed 260 characters & winget \cmd{Git.Git}\\
Python 3.11 (\cmd{py -3.11}) & board tests, \cmd{check\_replay.py} & winget \cmd{Python.Python.3.11}\\
\cmd{pyserial} & the station link & \cmd{pip install --user}\\
\cmd{asn1tools} & host replay check only & \cmd{pip install --user}\\
MSYS2 UCRT64 \cmd{gcc}, \cmd{make} & PC-side C tests & winget \cmd{MSYS2.MSYS2}, then pacman\\
\textbf{ESP-IDF 6.0.2}, esp32c5, in \cmd{C:\textbackslash Espressif} & build and flash; exactly this version, because \cmd{components/microbu\_v2x} pins the radio driver ABI to it & \cmd{git clone --branch v6.0.2 --recursive}, then \cmd{install.ps1 esp32c5}\\\bottomrule
\end{longtable}
Nothing to install for the board itself: the native USB port uses the Windows built-in driver. Internet is needed on the first build (\cmd{espressif/esp-boost}, about 125\,MB, into \cmd{managed\_components/}). \cmd{setup\_workstation.ps1 -PreventSleep} turns off sleep, hibernate, display-off and USB selective suspend on mains power; a suspended USB port drops the board. Pause Windows Update and use mains power.
Not in git, so absent on a fresh checkout: \cmd{its-g5-receiver-firmware/recordings/*.pcap} (the host replay test then skips itself), \cmd{vanetza/} (\cmd{check\_replay.py} then does not decode the 1609.2 envelopes independently) and \cmd{firmware-backups/}.
\textbf{Flashing trouble.} If the flash reports ``No serial data received'': unplug the board, hold BOOT, plug in, release, flash again, then unplug and replug without BOOT. If the flasher stub does not start, use the \cmd{--no-stub} recipe in \cmd{FLASHING.md}.
\section*{6\quad Reading the result}
Results go to \cmd{obu-firmware/test/results/overnight-<time>/}: \cmd{report.txt} (read this), \cmd{results.json}, \cmd{status.csv} (STATUS every few seconds), \cmd{device.log}, \cmd{boot.log} (ROM text and panics), \cmd{run.log}. \textbf{FAIL} contradicts the specification, the source or what the radio did. \textbf{WARN} is a disagreeing counter, a heap trend or a version mismatch. \textbf{INFO} is something the source leaves open, with the observed value. A fuzz failure prints its seed; replay it with \cmd{--fuzz-seed N}. Heap leaks are judged per phase over readings without a reset in between (warning below $-2$\,KB per hour, failure below $-20$\,KB per hour), and the lowest heap ever seen must stay above 16\,KB.
\section*{7\quad Findings so far}
\subsection*{7.1\quad Overnight run 2026-11-26 (6.0\,h, current build)}
Spare board on COM3 of the home workstation, firmware \cmd{aef6539-dirty} (built 2026-11-26 01:47; the uncommitted changes were in the bench scripts), transmitting at 5\,dBm, 02:39 to 08:40: 11 full cycles and the transmit phases of a twelfth. Results: \cmd{test/results/overnight-20261126-023952} and \cmd{host-20261126-023952}. An 8\,h run started before it was cancelled by mistake and is not evaluated here.
\textbf{Board checks: 2113 passed, 16 failed, 8 warnings, 70 information.} All 16 failures and all 8 warnings come from one fault, the transmit stall below, in 4 of the 12 cycles.
\begin{longtable}{@{}P{34mm}P{128mm}@{}}
\toprule\textbf{Area} & \textbf{Result}\\\midrule\endhead
conformance & start and end of the run: 74 checks each, none failed.\\
transmitted content & no corrupted or duplicated copy and no wrong source MAC in any soak phase; 1175 frames sent right after a reconfigure carried the new MAC and security. The MAC failures of the stale build are gone. \cmd{sign\_failed} stayed 0.\\
resets and boots & 55 reset cycles passed. 80 boots in \cmd{boot.log}, all with reset reason ``USB peripheral'', no panic or watchdog text. The boot panic of 2026-11-25 did not recur.\\
link fuzz & 11 passes, no failed check, heap within 8\,KB each time.\\
heap & lowest ever 39\,712 octets (limit 16\,KB), reached during a stall. Reconfigure trend $+196$\,octets per hour over 4 readings: no sign of a leak.\\
receive & \textbf{not exercised}: no other station was heard (\cmd{radio\_received} 0), so the receive-queue check passed without any load.\\\bottomrule
\end{longtable}
\needspace{50mm}
\textbf{Transmit stall (open).} The radio driver accepted 16 frames, reported none of them complete, and refused every further frame with \cmd{ESP\_ERR\_NO\_MEM}.
\begin{longtable}{@{}P{16mm}P{34mm}P{48mm}P{60mm}@{}}
\toprule\textbf{Cycle} & \textbf{Unsigned soak began} & \textbf{First refusal to first completion} & \textbf{Signed requests accepted but never sent}\\\midrule\endhead
3 & 03:50:19 & 155\,s & 423 of 1801\\
5 & 04:50:27 & 151\,s & 413 of 1800\\
10 & 07:35:23 & 186\,s & 516 of 1800\\
12 & 08:35:28 & 159\,s & 436 of 740 (phase cut short by the end of the run)\\\bottomrule
\end{longtable}
\begin{itemize}
\item \textbf{When:} always at the start of the first transmit phase after the 300\,s receive-only idle stage, where the station restarts the radio for transmit and receive: 4 of the 11 such starts (cycles 2 to 12). Cycle 1, which follows the conformance stage, did not stall.
\item \textbf{What the phone is told:} unsigned requests are refused with \cmd{resource\_limit} (164 here, then the test stops the phase). Signed requests are \textbf{answered accepted and then dropped}, 1788 in total; only \cmd{radio\_failed} in STATUS shows it.
\item \textbf{Configure does not clear it.} A repeated \cmd{STATION\_CONFIGURE}, and the signed phase's configure, left the stall in place. The station keeps the running Wi-Fi driver unless radio mode, channel or power change (\cmd{main/station.cpp}, \cmd{radio\_changed}).
\item \textbf{It clears by itself} after about 2.5 to 3 minutes. The driver then reports the 16 waiting frames as sent successfully (one further frame per stall is reported failed). If they did go on the air, they were that old; a second receiver is needed to tell.
\item \textbf{Heap:} about 13\,KB stay allocated during the stall and are released when it ends. The 1952 \cmd{ESP\_ERR\_NO\_MEM} warnings in \cmd{device.log} equal the sum of \cmd{radio\_failed}.
\end{itemize}
The cause is not known. The same pattern (about 17 requests accepted, 4 of 11 cycles) appeared on 2026-11-25 with the build of 10 November, so it predates the changes since then. The note of that day that a later configure cleared it is not confirmed: passing time or a radio restart would explain it too.
\textbf{Also open.} Signed payloads of 1398 to 1400 octets are answered accepted but not transmitted (\cmd{requests\_refused} $+1$, \cmd{sign\_failed} unchanged).
\textbf{PC-side tests: passed.} \cmd{make check}: chain test 4627 checks, fuzz 2\,000\,000 inputs, battery policy, 46 firmware unit tests, fragments (27\,367 records, 0 failures); the capture replay was skipped (no recordings on this PC). Then 273 fuzz runs of 200 million inputs each (seeds 101 to 373, $5.46\times10^{10}$ inputs): no crash. \cmd{summary.txt} nevertheless lists all 273 as \cmd{FUZZ FAILURE (exit 0)} and the script exits 1. This is a \textbf{false alarm}: \cmd{Select-String} ignores case, so the pattern \cmd{CRASH} matches ``no crash'' in every log. Not fixed yet (\cmd{run\_host\_tests\_overnight.ps1}; \cmd{-CaseSensitive} is needed).
\textbf{Next steps.} (1) A short reproducer: receive-only for 300\,s, then transmit, repeated. (2) Check whether restarting the radio ends a stall; if so, have the firmware do it when no frame completes for a few seconds. (3) Make the bench test compare completed with submitted frames. (4) Do not answer a signed request ``accepted'' without a way to report that the radio refused it. (5) Repeat with a second station on the air, to test reception and to see what happens to the waiting frames.
\subsection*{7.2\quad Earlier runs of 2026-11-25}
\textbf{Overnight run 2026-11-25 (6.3\,h, home workstation, stale build).} The board ran \cmd{1c3a66e-dirty} of 10 November, which predates the pseudonym MAC commit \cmd{3770754}, because the workstation had no ESP-IDF to flash a current build. 1278 checks passed and 802 failed. About 790 failures are the frame source MAC not being the one named in \cmd{STATION\_CONFIGURE}, explained by the stale build. Two things stand out: in 4 of 11 cycles the unsigned soak accepted about 17 requests and then refused all 2383 others with \cmd{resource\_limit} while \cmd{radio\_failed} rose by the same number (heap stayed healthy; a later configure cleared it), and one of 50 resets ended in a boot panic (illegal instruction in \cmd{app\_main}, 0.39\,s after boot). The heap showed no leak (lowest 49\,736 octets). Nothing else was heard on the air.
\textbf{Quick run 2026-11-25 on the spare, current build \cmd{ce18a39}.} 217 passed, 0 failed, 1 warning (one frame from the board with a bad CRC). The MAC failures are gone. One test bug was fixed on the way: the check ``refused requests put nothing on the radio'' counted frames heard from other stations; it now counts only the station's own transmissions. The wedge and the boot panic were not reproduced in 8 minutes and need the full overnight run.
\section*{Revision history}
Revision 2, 2026-11-27: results of the 6\,h run of 2026-11-26 (section 7.1). Corrected what the own-TX copy proves (section 3). Two script fixes for Windows PowerShell 5.1: \cmd{setup\_workstation.ps1} now installs a missing Python package instead of stopping on the failed import, and \cmd{start\_overnight.ps1} no longer fails on the keep-awake call before doing anything.\par
Revision 1, 2026-11-25: first version, written with the move of the overnight test to the spare board.
\end{document}