#!/usr/bin/env python3 # SPDX-License-Identifier: Apache-2.0 """Smoke test of a running VisionPilot network server (standard library only; any Python 3.9+, no numpy). python3 code/tt_visionpilot/server/smoke_test.py --url http://127.0.0.1:20000 --wait 600 [--net autosteer] # a served container package (what tt-model's container smoke runs): python3 code/tt_visionpilot/server/smoke_test.py --url ... --manifest //tt_kernel_manifest.json Checks (all failures collected; prints ONE line ``PASS ...`` / ``FAIL ...``, exit code 0 / 1): * ``/health`` ``ok`` (waiting up to ``--wait`` s), ``/info`` and ``/v1/models`` answer; ``/info`` reports ETH dispatch and the 12x10 grid; with ``--manifest``, what the package pins for the serve profile; * ``POST /predict`` of the shipped synthetic sample (``samples/synthetic_road_*.png``) answers 200 and agrees with the stored fp32 CPU reference (``samples/synthetic_road..reference.json``) within :data:`GATES`; AutoDrive also in its stream form (one frame per call: frame 0 answers ``ready: false``, frame 1 agrees with the reference); * a malformed request answers 400. The network (``--net``) defaults to what ``/info`` reports (the model name). """ from __future__ import annotations import argparse import json import sys from pathlib import Path from typing import Any, Dict, List HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE.parent / "ttaw" / "server")) import client as ttaw_client # noqa: E402 (stdlib-only modules of the vendored ttaw) import smoke as ttaw_smoke # noqa: E402 SAMPLES = HERE.parent / "samples" NETS = {"auto_steer-p150": ("autosteer", "AUTOSTEER"), "auto_speed-p150": ("autospeed", "AUTOSPEED"), "auto_drive-p150": ("autodrive", "AUTODRIVE")} # agreement with the fp32 CPU reference on the synthetic sample: AutoSteer xp within 0.01 of the image width (10 px # of 1024) and h_vector within 0.25; AutoSpeed boxes by IoU >= 0.5, same class, score within 0.05; AutoDrive # distance within 1.5 m, curvature within 2e-4 1/m, presence probability within 0.05 GATES = {"xp": 0.01, "h_vector": 0.25, "distance_m": 1.5, "curvature_per_m": 2e-4, "flag_prob": 0.05} def build_request(net: str) -> Dict[str, Any]: imgs = [str(SAMPLES / "synthetic_road_1.png")] if net == "autodrive": req = ttaw_client.build_request(images=[f"prev={SAMPLES / 'synthetic_road_0.png'}", f"curr={SAMPLES / 'synthetic_road_1.png'}"]) ref = json.loads((SAMPLES / "synthetic_road.autodrive.reference.json").read_text()) req["homography"] = ref["homography"] return req return ttaw_client.build_request(images=[f"front={imgs[0]}"]) def compare(net: str, body: Dict[str, Any], ref: Dict[str, Any]) -> List[str]: fails = [] if net == "autosteer": for k in ("xp", "h_vector"): got, exp = body.get(k) or [], ref[k] if len(got) != len(exp): fails.append(f"{k}: {len(got)} values, expected {len(exp)}") continue err = max(abs(a - b) for a, b in zip(got, exp)) if err > GATES[k]: fails.append(f"{k}: max |diff| {err:.4f} > {GATES[k]}") elif net == "autospeed": rows = lambda b: [{"label": str(d["class_id"]), "label_id": d["class_id"], "score": d["score"], "box_xyxy": d["box_xyxy"]} for d in b.get("detections", [])] _, more = ttaw_smoke.compare_with_reference({"detections": rows(body)}, {"detections": rows(ref)}, gates={"min_iou": 0.5, "min_recall": 1.0, "min_precision": 1.0, "max_score_err": 0.05}) fails += more else: for k in ("distance_m", "curvature_per_m", "flag_prob"): err = abs(float(body.get(k, float("nan"))) - float(ref[k])) if not err <= GATES[k]: fails.append(f"{k}: |diff| {err:.4g} > {GATES[k]}") return fails def main(argv=None) -> int: ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) ap.add_argument("--url", default="http://127.0.0.1:20000") ap.add_argument("--wait", type=float, default=0) ap.add_argument("--net", choices=("autosteer", "autospeed", "autodrive"), default=None) ap.add_argument("--manifest", default=None) ap.add_argument("--profile", default=None) ap.add_argument("--out", default=None) args = ap.parse_args(argv) fails: List[str] = [] health = ttaw_client.wait_ready(args.url, wait_s=args.wait) if (health or {}).get("status") != "ok": print(ttaw_client.smoke_line("visionpilot", "not ready", [f"/health: {health}"])) return 1 info, more = ttaw_client.check_service(args.url, expect_dispatch="eth", expect_grid="12x10") fails += more model = (info or {}).get("model", "") net, prefix = NETS.get(model, (args.net or "autosteer", "AUTOSTEER")) if args.net and args.net != net: fails.append(f"--net {args.net} but the server runs {model}") if args.manifest: pinned = ttaw_smoke.pinned_config(args.manifest, args.profile) fails += ttaw_smoke.check_pinned(info, pinned, prefix) code, body = ttaw_client.post(args.url, build_request(net)) if code != 200: fails.append(f"/predict: HTTP {code}: {str(body)[:200]}") body = {} else: ref = json.loads((SAMPLES / f"synthetic_road.{net}.reference.json").read_text()) fails += compare(net, body, ref) if net == "autodrive" and code == 200: # the stream form: frame 0 primes (ready false), frame 1 equals the two-frame reference ref = json.loads((SAMPLES / "synthetic_road.autodrive.reference.json").read_text()) for k, reset in ((0, True), (1, False)): req = ttaw_client.build_request(images=[f"curr={SAMPLES / f'synthetic_road_{k}.png'}"], stream_id="smoke", reset=reset) req["homography"] = ref["homography"] c2, b2 = ttaw_client.post(args.url, req) if c2 != 200: fails.append(f"/predict stream frame {k}: HTTP {c2}: {str(b2)[:200]}") break if k == 0 and b2.get("ready") is not False: fails.append(f"stream frame 0: ready={b2.get('ready')}, expected false") if k == 1: fails += [f"stream: {m}" for m in compare(net, b2, ref)] f = ttaw_client.check_bad_request(args.url) if f: fails.append(f) if args.out: Path(args.out).write_text(json.dumps({"info": info, "body": body, "failures": fails}, indent=1)) summary = {"autosteer": lambda b: f"xp[32]={b.get('xp', [None] * 33)[32]}", "autospeed": lambda b: f"n={b.get('num_detections')}", "autodrive": lambda b: f"d={b.get('distance_m')}"}[net](body) print(ttaw_client.smoke_line(model or net, summary, fails)) return 1 if fails else 0 if __name__ == "__main__": raise SystemExit(main())