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,240 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Overnight firmware test of one micrOBU board on a USB port (station-link, revision 3).
|
||||
|
||||
py -3.11 obu-firmware/test/bench/run_overnight.py COM6 --hours 8 --provision-demo # COM6 = the spare board; 'auto' if only one is plugged in
|
||||
py -3.11 obu-firmware/test/bench/run_overnight.py COM6 --quick # about 8 minutes, to see that it works
|
||||
py -3.11 obu-firmware/test/bench/run_overnight.py COM6 --hours 8 --no-tx # nothing on the air: protocol, fuzz, idle
|
||||
(start_overnight.ps1 wraps this with flashing, the host C tests and keep-awake.) It refuses a board whose firmware is not this
|
||||
checkout's HEAD, because the results would describe another build.
|
||||
|
||||
What it does, in order (details in README.md):
|
||||
1. conformance the link protocol against the spec and the source, on a freshly reset board
|
||||
2. cycles repeated until the time is up: transmit soak unsigned -> transmit soak signed (needs a ticket) ->
|
||||
capture-mode toggling -> reconfigure churn -> link fuzz (unconfigured board, never on air) ->
|
||||
resets -> idle listening
|
||||
3. conformance again, to see that nothing drifted
|
||||
4. report results/overnight-<time>/report.txt, results.json, status.csv, device.log
|
||||
|
||||
The board is reset every time the port is opened (USB Serial/JTAG), so run it with no other program holding the port
|
||||
(close Android Studio's serial monitor, tools/station_status_watch.py, the phone app's USB link).
|
||||
|
||||
On the air: transmit phases send unsecured or signed frames at a few Hz and 5 dBm (--power) on channel 180 whose
|
||||
payload is not a valid ITS message (ItsPduHeader messageID 0xF1). --no-tx keeps the radio silent. --provision-demo
|
||||
writes the throwaway demo certificate chain from app/src/main/assets/demo-chain.vcr to the board's NVS, which is what
|
||||
the phone app does on its first connection; without it the signed phases are skipped.
|
||||
Exit status: 0 if no check failed, 1 otherwise, 2 if the board does not speak the station link.
|
||||
"""
|
||||
import argparse
|
||||
import datetime
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
import bench_conformance
|
||||
import bench_fuzz
|
||||
import bench_soak
|
||||
import linklib as ll
|
||||
from bench_common import Ctx, FAIL, INFO, PASS, Results, WARN, slope_per_hour
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
RESULTS = os.path.normpath(os.path.join(HERE, "..", "results"))
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("port", nargs="?", default="auto",
|
||||
help="serial port of the spare board, e.g. COM6; default 'auto' = the one Espressif native-USB board that is plugged in")
|
||||
ap.add_argument("--allow-stale-firmware", action="store_true",
|
||||
help="run even if the board's firmware is not this checkout's HEAD (default: refuse, the results would describe another build)")
|
||||
ap.add_argument("--hours", type=float, default=8.0, help="total run time (default 8)")
|
||||
ap.add_argument("--quick", action="store_true", help="about 6 minutes in all: one short pass of every phase")
|
||||
ap.add_argument("--no-tx", action="store_true", help="never transmit: skips every phase that needs the radio to emit")
|
||||
ap.add_argument("--provision-demo", action="store_true", help="write the demo certificate chain to the board if it has no ticket")
|
||||
ap.add_argument("--power", type=int, default=5, help="transmit power in dBm (default 5)")
|
||||
ap.add_argument("--rate", type=float, default=4.0, help="frames per second in the soak phases (default 4)")
|
||||
ap.add_argument("--phase-minutes", type=float, default=10.0, help="length of each soak phase (default 10)")
|
||||
ap.add_argument("--fuzz-seed", type=int, help="replay a fuzz run")
|
||||
ap.add_argument("--out", help="result folder (default obu-firmware/test/results/overnight-<time>)")
|
||||
args = ap.parse_args()
|
||||
|
||||
stamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
outdir = args.out or os.path.join(RESULTS, "overnight-" + stamp)
|
||||
os.makedirs(outdir, exist_ok=True)
|
||||
logf = open(os.path.join(outdir, "run.log"), "a", encoding="utf-8", buffering=1)
|
||||
|
||||
def echo(msg):
|
||||
line = "%s %s" % (datetime.datetime.now().strftime("%H:%M:%S"), msg)
|
||||
print(line, flush=True)
|
||||
logf.write(line + "\n")
|
||||
|
||||
args.port = resolve_port(args.port, echo)
|
||||
if args.port is None:
|
||||
return 2
|
||||
link = ll.Link(args.port, outdir, echo=echo)
|
||||
res = Results(outdir, echo=echo)
|
||||
ctx = Ctx(link, res, args, outdir)
|
||||
total_s = (8 * 60 if args.quick else args.hours * 3600)
|
||||
ctx.deadline = time.time() + total_s
|
||||
phase_s = 20 if args.quick else args.phase_minutes * 60
|
||||
echo("results in %s" % outdir)
|
||||
echo("run for %.1f h, port %s, tx %s, power %d dBm" % (total_s / 3600, args.port, "off" if args.no_tx else "on", args.power))
|
||||
|
||||
try:
|
||||
link.open()
|
||||
except Exception as e:
|
||||
echo("cannot open %s: %s" % (args.port, e))
|
||||
return 2
|
||||
first = link.wait_status(20)
|
||||
if first is None:
|
||||
echo("no STATUS reply from the board: is it running obu-firmware, and is nothing else holding the port?")
|
||||
echo("device said: %s" % (list(link.log_lines)[-5:] or bytes(link.noise[-300:])))
|
||||
return 2
|
||||
echo("board answers: uptime %d ms, heap_free %d, tickets %d, battery %d mV" % (first["uptime_ms"], first["heap_free"], first["tickets"], first["battery_mv"]))
|
||||
if not check_firmware_version(ctx, echo) and not args.allow_stale_firmware:
|
||||
echo("refusing to test a stale build: flash this checkout first (start_overnight.ps1 -Flash, or obu-firmware/FLASHING.md), "
|
||||
"or pass --allow-stale-firmware")
|
||||
return 2
|
||||
|
||||
def guarded(name, fn, *a, **kw):
|
||||
"""Run one phase; a serial error or a bug in it is recorded, the port is reopened and the run goes on."""
|
||||
if ctx.time_left() < 5:
|
||||
return
|
||||
echo("-- %s" % name)
|
||||
ctx.phase = name
|
||||
t0 = time.time()
|
||||
try:
|
||||
fn(*a, **kw)
|
||||
except Exception as e:
|
||||
res.add(name, "phase aborted by an exception", FAIL, "%r\n%s" % (e, traceback.format_exc()[-600:]))
|
||||
echo(" exception: %r" % e)
|
||||
try:
|
||||
link.close()
|
||||
time.sleep(1.0)
|
||||
link.open()
|
||||
except Exception as e2:
|
||||
echo(" cannot reopen the port: %r" % e2)
|
||||
if link.panics:
|
||||
for t, line in link.panics:
|
||||
res.add(name, "panic/error text on the console", FAIL, line[:200])
|
||||
link.panics.clear()
|
||||
res.write()
|
||||
echo(" %s took %.0f s; PASS %d FAIL %d WARN %d" % (name, time.time() - t0, res.count(PASS), res.count(FAIL), res.count(WARN)))
|
||||
|
||||
guarded("conformance", bench_conformance.run, ctx) # also finds out whether the board holds a ticket
|
||||
echo("board holds a ticket: %s" % ctx.credentials)
|
||||
if args.provision_demo and not ctx.credentials and not args.no_tx:
|
||||
guarded("provision", bench_soak.provision_demo, ctx)
|
||||
|
||||
cycle = 0
|
||||
while ctx.time_left() > 30:
|
||||
cycle += 1
|
||||
echo("== cycle %d, %.1f h left" % (cycle, ctx.time_left() / 3600))
|
||||
guarded("soak-unsigned", bench_soak.tx_phase, ctx, "soak-unsigned", phase_s, False, rate_hz=args.rate, power=args.power)
|
||||
if ctx.credentials:
|
||||
guarded("soak-signed", bench_soak.tx_phase, ctx, "soak-signed", phase_s, True, rate_hz=min(args.rate, 3.0), power=args.power, sizes=bench_soak.SIGNED_SIZES)
|
||||
guarded("raw-toggle", bench_soak.raw_toggle_phase, ctx, "raw-toggle", (phase_s if args.quick else max(60, phase_s * 0.3)), power=args.power)
|
||||
guarded("reconfigure", bench_soak.reconfigure_phase, ctx, "reconfigure", (phase_s if args.quick else max(45, phase_s * 0.3)), power=args.power)
|
||||
guarded("fuzz", bench_fuzz.run, ctx, (phase_s if args.quick else max(30, phase_s * 0.3)), seed=(args.fuzz_seed if args.fuzz_seed is not None and cycle == 1 else None))
|
||||
guarded("resets", bench_soak.reset_cycles, ctx, "resets", 2 if args.quick else 5)
|
||||
guarded("idle-listen", bench_soak.idle_listen_phase, ctx, "idle-listen", (phase_s if args.quick else max(60, phase_s * 0.5)))
|
||||
if args.quick:
|
||||
break
|
||||
|
||||
ctx.deadline = None
|
||||
guarded("conformance-final", bench_conformance.run, ctx)
|
||||
analyse_heap(ctx)
|
||||
summarise_rx(ctx)
|
||||
text = res.write()
|
||||
link.close()
|
||||
echo("")
|
||||
echo(text)
|
||||
echo("report: %s" % os.path.join(outdir, "report.txt"))
|
||||
return 1 if res.failures() else 0
|
||||
|
||||
|
||||
def resolve_port(port, echo):
|
||||
"""'auto' picks the single Espressif native-USB serial port (VID 303A) that is plugged in; anything else is used as given."""
|
||||
if port.lower() != "auto":
|
||||
return port
|
||||
from serial.tools import list_ports
|
||||
found = [p for p in list_ports.comports() if p.vid == 0x303A]
|
||||
if len(found) == 1:
|
||||
echo("port: %s (%s)" % (found[0].device, found[0].description))
|
||||
return found[0].device
|
||||
if not found:
|
||||
echo("no Espressif USB serial port (VID 303A) found: plug in the spare board, or name the port")
|
||||
else:
|
||||
echo("several Espressif boards are plugged in (%s): name the spare one, e.g. COM6" % ", ".join(p.device for p in found))
|
||||
return None
|
||||
|
||||
|
||||
def check_firmware_version(ctx, echo):
|
||||
"""Record which firmware the board runs and whether it is the one in this checkout. True if it is (or HEAD is unknown)."""
|
||||
import subprocess
|
||||
L, R = ctx.link, ctx.res
|
||||
board = L.app_version or "unknown"
|
||||
try:
|
||||
head = subprocess.run(["git", "rev-parse", "--short", "HEAD"], cwd=HERE, capture_output=True, text=True, timeout=10).stdout.strip()
|
||||
except Exception:
|
||||
head = ""
|
||||
echo("firmware on the board: %s, built %s (%s); this checkout is at %s" % (board, L.app_compile_time, L.app_project, head or "?"))
|
||||
R.add("firmware", "board runs", INFO, "version %s, compiled %s, project %s; checkout HEAD %s" % (board, L.app_compile_time, L.app_project, head or "?"))
|
||||
if head and board.split("-")[0] != head:
|
||||
R.add("firmware", "the board does not run this checkout's firmware", WARN,
|
||||
"board %s, checkout %s: results describe the board's build, not the source here (flash it: obu-firmware/FLASHING.md)" % (board, head))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def analyse_heap(ctx):
|
||||
"""Leak check on the quiet-moment heap readings: per phase kind, and the lowest the heap ever got."""
|
||||
R = ctx.res
|
||||
S = "heap"
|
||||
if not ctx.heap:
|
||||
return
|
||||
by_phase = {}
|
||||
for t, phase, free, minimum, largest, uptime in ctx.heap:
|
||||
by_phase.setdefault(phase, []).append((t, free, minimum, largest, uptime))
|
||||
lowest = min(p[2] for pts in by_phase.values() for p in pts)
|
||||
R.add(S, "lowest free heap ever seen by the station (heap_min_free)", INFO, "%d octets" % lowest)
|
||||
R.ok(S, "heap_min_free stays above 16 KB", lowest > 16384, "%d" % lowest, WARN)
|
||||
for phase, pts in sorted(by_phase.items()):
|
||||
# compare like with like: a reading taken after a phase's work, from reset to reset the heap legitimately starts over,
|
||||
# so only readings of one uptime lineage (monotonic uptime) go into a slope
|
||||
lineage, prev = [], None
|
||||
for t, free, minimum, largest, uptime in pts:
|
||||
if prev is not None and uptime < prev:
|
||||
lineage = []
|
||||
lineage.append((t, free, largest))
|
||||
prev = uptime
|
||||
if len(lineage) >= 4:
|
||||
sl = slope_per_hour([(t, f) for t, f, _ in lineage])
|
||||
sl_big = slope_per_hour([(t, l) for t, _, l in lineage])
|
||||
level = PASS
|
||||
if sl is not None and sl < -2048:
|
||||
level = WARN
|
||||
if sl is not None and sl < -20480:
|
||||
level = FAIL
|
||||
R.add(S, "%s: free heap trend over %d readings (no reset in between)" % (phase, len(lineage)), level,
|
||||
"%+.0f octets/hour free, %+.0f octets/hour largest block; first %d, last %d" %
|
||||
(sl or 0, sl_big or 0, lineage[0][1], lineage[-1][1]))
|
||||
ctx.link.statuslog.flush()
|
||||
|
||||
|
||||
def summarise_rx(ctx):
|
||||
R = ctx.res
|
||||
if ctx.rx_stats:
|
||||
R.add("rx", "everything the radio heard on the air during the run (V2X_RX)", INFO,
|
||||
"; ".join("%s%s %s x%d" % (p, " signed" if sg else "", b, v) for (p, sg, b), v in sorted(ctx.rx_stats.items(), key=str)))
|
||||
else:
|
||||
R.add("rx", "nothing was heard on the air during the run", INFO, "no other ITS station in range of this board, or the radio was never on")
|
||||
c = ctx.link.counts
|
||||
R.add("link", "host-side counters", INFO, ", ".join("%s %d" % kv for kv in sorted(c.items()) if not kv[0].startswith("op_") and kv[0] != "confirm_unmatched"))
|
||||
if c["frames_bad_crc"]:
|
||||
R.add("link", "frames from the board with a bad CRC", WARN, "%d (USB corruption or a board-side write cut short)" % c["frames_bad_crc"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user