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:
Ashin Walpola
2026-11-25 14:43:34 +01:00
parent ce18a393ea
commit 462e1898ff
20 changed files with 5938 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
"""What the bench stages share: the result log, the run context and a few helpers."""
import json
import os
import statistics
import time
PASS, FAIL, WARN, INFO, SKIP = "PASS", "FAIL", "WARN", "INFO", "SKIP"
class Results:
"""Collects every check of a run; written to results.json and report.txt by `write`."""
def __init__(self, outdir, echo=print):
self.outdir, self.echo = outdir, echo
self.checks = [] # dicts: t, stage, name, level, detail
self.metrics = {} # stage -> {name: value}
self.started = time.time()
os.makedirs(outdir, exist_ok=True)
def add(self, stage, name, level, detail=""):
self.checks.append(dict(t=round(time.time() - self.started, 1), stage=stage, name=name, level=level, detail=str(detail)))
if level in (FAIL, WARN):
self.echo(" [%s] %s: %s %s" % (level, stage, name, detail))
return level == PASS
def ok(self, stage, name, cond, detail="", level_if_false=FAIL):
return self.add(stage, name, PASS if cond else level_if_false, detail)
def metric(self, stage, name, value):
self.metrics.setdefault(stage, {})[name] = value
def count(self, level):
return sum(1 for c in self.checks if c["level"] == level)
def failures(self):
return [c for c in self.checks if c["level"] == FAIL]
def write(self, extra_text=""):
with open(os.path.join(self.outdir, "results.json"), "w", encoding="utf-8") as f:
json.dump(dict(checks=self.checks, metrics=self.metrics, seconds=round(time.time() - self.started)), f, indent=1)
lines = ["micrOBU bench run, %.1f h" % ((time.time() - self.started) / 3600),
"PASS %d FAIL %d WARN %d INFO %d SKIP %d" % tuple(self.count(l) for l in (PASS, FAIL, WARN, INFO, SKIP)), ""]
# Collapse repeats: one line per (stage, name, level) with a count and the first detail.
groups = {}
for c in self.checks:
g = groups.setdefault((c["stage"], c["name"], c["level"]), [0, c])
g[0] += 1
for level in (FAIL, WARN, INFO, SKIP, PASS):
rows = [(k, v) for k, v in groups.items() if k[2] == level]
if not rows:
continue
lines.append("== %s ==" % level)
for (stage, name, _), (n, first) in rows:
detail = "" if level == PASS else first["detail"][:230]
lines.append(" %-14s %s%s %s" % (stage, name, " (x%d)" % n if n > 1 else "", detail))
lines.append("")
if extra_text:
lines.append(extra_text)
text = "\n".join(lines)
with open(os.path.join(self.outdir, "report.txt"), "w", encoding="utf-8") as f:
f.write(text + "\n")
return text
class Ctx:
"""Everything a stage needs. `mac_n` makes every configure use a fresh locally administered MAC."""
def __init__(self, link, res, args, outdir):
self.link, self.res, self.args, self.outdir = link, res, args, outdir
self.run_id = int(time.time()) & 0xFFFFFFFF
self.tx_seq = 0
self.mac_n = 0
self.credentials = False # the station holds an authorization ticket (provisioned or already there)
self.tx_enabled = not args.no_tx
self.deadline = None
self.phase = "init"
self.rx_stats = {} # (port, flags&2, size bucket) -> count: everything heard on the air
self.heap = [] # (time, phase, heap_free, heap_min_free, heap_largest, uptime_ms) at quiet moments
def next_mac(self):
self.mac_n += 1
return bytes([0x02, 0xB3, 0x0A, 0xCE, (self.mac_n >> 8) & 0xFF, self.mac_n & 0xFF])
def time_left(self):
return float("inf") if self.deadline is None else self.deadline - time.time()
def sample_status(self, label=None):
s = self.link.status(1.5)
self.link.log_status(s, label or self.phase)
return s
def median(xs):
xs = list(xs)
return statistics.median(xs) if xs else None
def slope_per_hour(points):
"""Least-squares slope of (t_seconds, value) points, per hour; None for fewer than 3 points."""
if len(points) < 3:
return None
n = len(points)
mt = sum(t for t, _ in points) / n
mv = sum(v for _, v in points) / n
den = sum((t - mt) ** 2 for t, _ in points)
return None if den == 0 else 3600.0 * sum((t - mt) * (v - mv) for t, v in points) / den