run_verification_matrix.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. """Run the Prod2U CPLD offline verification matrix with bounded concurrency.
  2. Each lane uses an independent work root and receipt. A failed lane does not
  3. cancel unrelated lanes. Missing toolchains produce `blocked` or `not_run`, never
  4. a fabricated pass. Long tasks use tools/run_visible.py for live heartbeat.
  5. Resource classes (light / medium / heavy / exclusive) come from
  6. tools/resource_scheduler.py (nproc, MemAvailable, free disk). Formal
  7. concurrency is memory-capped. TD is always exclusive (serialized after
  8. open-source lanes, with a lock file). Per-lane TEMP/cocotb builds stay under
  9. the task work root — never a shared sim_build.
  10. """
  11. from __future__ import annotations
  12. import argparse
  13. import json
  14. import os
  15. import sys
  16. import time
  17. import uuid
  18. from concurrent.futures import ThreadPoolExecutor, as_completed
  19. from datetime import datetime, timezone
  20. from pathlib import Path
  21. from typing import Any, Callable
  22. _repo_root = Path(__file__).resolve().parents[1]
  23. if str(_repo_root) not in sys.path:
  24. sys.path.insert(0, str(_repo_root))
  25. from tools import prod2u_p4_harness # noqa: E402
  26. from tools.tool_env import ( # noqa: E402
  27. ensure_safe_sys_executable,
  28. safe_python as _safe_python,
  29. strip_poison_env,
  30. )
  31. from tools.resource_scheduler import ( # noqa: E402
  32. TASK_RESOURCE_CLASS,
  33. TD_EXCLUSIVE,
  34. allocate_task_dirs,
  35. assert_not_shared_sim_build,
  36. classify_task,
  37. host_resources,
  38. lane_isolation_env,
  39. plan_concurrency,
  40. schedule_waves,
  41. )
  42. from tools.run_visible import run_visible # noqa: E402
  43. from tools.board_viewer_lane_mode import ( # noqa: E402
  44. MODE_DETACHED,
  45. MODE_FULL,
  46. select_board_viewer_lane_mode,
  47. )
  48. from tools.verilator_perl_preflight import run_verilator_perl_preflight # noqa: E402
  49. # Back-compat alias used by receipts / external importers.
  50. LANE_RESOURCE_CLASS = TASK_RESOURCE_CLASS
  51. DEFAULT_LANES = [
  52. "python",
  53. "board_viewer",
  54. "icarus",
  55. "verilator",
  56. "cocotb",
  57. "formal",
  58. "td",
  59. ]
  60. def _utc_now() -> str:
  61. return datetime.now(timezone.utc).isoformat()
  62. def _sha256_file(path: Path) -> str:
  63. return prod2u_p4_harness.sha256_file(path)
  64. def _write_json(path: Path, payload: dict[str, Any]) -> None:
  65. path.parent.mkdir(parents=True, exist_ok=True)
  66. path.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
  67. def _prefer_oss_cad_on_path() -> None:
  68. override = os.environ.get("PRODU2_TOOLCHAIN_BASE", "").strip()
  69. if override:
  70. cache = Path(override)
  71. elif Path("/data/prod2u").is_dir() or os.access("/data", os.W_OK):
  72. cache = Path("/data/prod2u")
  73. else:
  74. cache = Path(os.environ.get("XDG_CACHE_HOME", str(Path.home() / ".cache"))) / "prod2u"
  75. root = Path(os.environ.get("OSS_CAD_SUITE_ROOT", str(cache / "oss-cad-suite" / "latest")))
  76. oss_bin = root / "bin"
  77. if not oss_bin.is_dir():
  78. return
  79. prefix = str(oss_bin)
  80. current = os.environ.get("PATH", "")
  81. parts = current.split(os.pathsep) if current else []
  82. if prefix not in parts:
  83. os.environ["PATH"] = prefix + (os.pathsep + current if current else "")
  84. def _run_visible_cmd(
  85. cmd: list[str],
  86. *,
  87. cwd: Path,
  88. log_path: Path,
  89. status_path: Path,
  90. name: str,
  91. timeout_s: float | None,
  92. env: dict[str, str] | None = None,
  93. ) -> int:
  94. # Strip Anlogic libs for non-TD lanes so apt/python stay healthy.
  95. clean = os.environ.copy()
  96. keep_td = name == "td"
  97. if not keep_td:
  98. for key in (
  99. "LD_LIBRARY_PATH",
  100. "LD_PRELOAD",
  101. "QT_PLUGIN_PATH",
  102. "PYTHONHOME",
  103. "PYTHONPATH",
  104. "PYTHONEXECUTABLE",
  105. "PERL5LIB",
  106. "PERL_LOCAL_LIB_ROOT",
  107. "PERL_MB_OPT",
  108. "PERL_MM_OPT",
  109. ):
  110. clean.pop(key, None)
  111. if env:
  112. clean.update(env)
  113. return run_visible(
  114. cmd,
  115. cwd=cwd,
  116. env=clean,
  117. log_path=log_path,
  118. status_path=status_path,
  119. name=name,
  120. timeout_s=timeout_s,
  121. heartbeat_s=5.0,
  122. keep_td_libs=keep_td,
  123. )
  124. def _lane_paths(
  125. *,
  126. lane: str,
  127. run_id: str,
  128. run_root: Path | None,
  129. work_root_prefix: str | None,
  130. ) -> dict[str, Path]:
  131. if run_root is not None:
  132. dirs = allocate_task_dirs(run_root, lane, run_id=run_id, create=True)
  133. assert_not_shared_sim_build(dirs["work_root"])
  134. return dirs
  135. if not work_root_prefix:
  136. raise ValueError("either --run-root or --work-root-prefix is required")
  137. work_root = Path(f"{work_root_prefix}-{lane}-{run_id[:8]}")
  138. assert_not_shared_sim_build(work_root)
  139. work_root.mkdir(parents=True, exist_ok=True)
  140. log_dir = work_root
  141. return {
  142. "run_root": work_root.parent,
  143. "task": lane,
  144. "build_dir": work_root,
  145. "log_dir": log_dir,
  146. "work_root": work_root,
  147. }
  148. def run_python_unit(repo: Path, work_root: Path, run_id: str, *, log_dir: Path | None = None) -> dict[str, Any]:
  149. log_root = log_dir or work_root
  150. receipt_path = work_root / "python-unit-receipt.json"
  151. log_path = log_root / "python-unit.log"
  152. status_path = log_root / "python-unit.status.json"
  153. work_root.mkdir(parents=True, exist_ok=True)
  154. log_root.mkdir(parents=True, exist_ok=True)
  155. isolation = lane_isolation_env(work_root, task="python")
  156. isolation["PRODU2_VERIFY_PYTHON"] = _safe_python()
  157. isolation.setdefault(
  158. "PRODU2_VERIFY_VENV",
  159. os.environ.get("PRODU2_VERIFY_VENV", "/data/prod2u/venvs/verify"),
  160. )
  161. cmd = [
  162. _safe_python(),
  163. "-B",
  164. "-m",
  165. "pytest",
  166. "-q",
  167. "-p",
  168. "no:cacheprovider",
  169. f"--basetemp={work_root / 'tmp' / 'pytest'}",
  170. "tests/unit",
  171. "tests/test_project_structure.py",
  172. ]
  173. code = _run_visible_cmd(
  174. cmd,
  175. cwd=repo,
  176. log_path=log_path,
  177. status_path=status_path,
  178. name="python",
  179. timeout_s=600,
  180. env=isolation,
  181. )
  182. status = "pass" if code == 0 else "fail"
  183. full_commit = prod2u_p4_harness.current_commit()
  184. receipt = {
  185. "schema": "prod2u-p4-normal-v3-python-unit-receipt-v1",
  186. "status": status,
  187. "verification_run_id": run_id,
  188. "commit": full_commit,
  189. "commit_full": full_commit,
  190. "project_config_sha256": _sha256_file(repo / "projects" / "prod2u-door-temp" / "project.json"),
  191. "td_source_manifest_sha256": _sha256_file(repo / "src" / "generated" / "td-source-manifest.json"),
  192. "command": " ".join(cmd),
  193. "tool_version": f"Python {sys.version.split()[0]}",
  194. "returncode": code,
  195. "log_path": str(log_path),
  196. "status_path": str(status_path),
  197. "report_path": str(receipt_path),
  198. "work_root": str(work_root),
  199. "resource_class": classify_task("python"),
  200. }
  201. _write_json(receipt_path, receipt)
  202. return receipt
  203. def run_board_viewer(repo: Path, work_root: Path, run_id: str, *, log_dir: Path | None = None) -> dict[str, Any]:
  204. log_root = log_dir or work_root
  205. receipt_path = work_root / "board-viewer-receipt.json"
  206. log_path = log_root / "board-viewer.log"
  207. status_path = log_root / "board-viewer.status.json"
  208. derived_report_path = log_root / "detached-derived-report.json"
  209. work_root.mkdir(parents=True, exist_ok=True)
  210. log_root.mkdir(parents=True, exist_ok=True)
  211. isolation = lane_isolation_env(work_root, task="board_viewer")
  212. decision = select_board_viewer_lane_mode(repo)
  213. mode = decision["mode"]
  214. if mode == MODE_DETACHED:
  215. isolation["BOARDVIEW_LOG_DIR"] = str(log_root)
  216. cmd = ["bash", str(repo / "tools" / "validate-board-viewer-detached.sh"), "--json"]
  217. code = _run_visible_cmd(
  218. cmd,
  219. cwd=repo,
  220. log_path=log_path,
  221. status_path=status_path,
  222. name="board_viewer",
  223. timeout_s=300,
  224. env=isolation,
  225. )
  226. # Prefer validator JSON sidecar when present.
  227. if not derived_report_path.is_file():
  228. # validate_detached_derived may write under BOARDVIEW_LOG_DIR.
  229. alt = log_root / "detached-derived-report.json"
  230. if alt.is_file():
  231. derived_report_path = alt
  232. status = "pass" if code == 0 else "fail"
  233. receipt = {
  234. "schema": "prod2u-board-viewer-receipt-v1",
  235. "mode": MODE_DETACHED,
  236. "status": status,
  237. "reference_change_detected": decision["reference_change_detected"],
  238. "reference_regeneration_replay": decision["reference_regeneration_replay"],
  239. "raw_reference_used": False,
  240. "selection": decision,
  241. "verification_run_id": run_id,
  242. "commit_full": prod2u_p4_harness.current_commit(),
  243. "command": " ".join(cmd),
  244. "returncode": code,
  245. "log_path": str(log_path),
  246. "derived_report_path": str(derived_report_path),
  247. "report_path": str(receipt_path),
  248. "work_root": str(work_root),
  249. "resource_class": classify_task("board_viewer"),
  250. }
  251. _write_json(receipt_path, receipt)
  252. return receipt
  253. # Full regeneration mode: require raw reference; never silently fall back.
  254. if not decision.get("raw_reference_available"):
  255. receipt = {
  256. "schema": "prod2u-board-viewer-receipt-v1",
  257. "mode": MODE_FULL,
  258. "status": "blocked",
  259. "reference_change_detected": decision["reference_change_detected"],
  260. "reference_regeneration_replay": "required",
  261. "raw_reference_used": False,
  262. "selection": decision,
  263. "failures": ["board_viewer_full_regeneration_missing_raw_reference"],
  264. "verification_run_id": run_id,
  265. "commit_full": prod2u_p4_harness.current_commit(),
  266. "command": None,
  267. "returncode": None,
  268. "log_path": str(log_path),
  269. "report_path": str(receipt_path),
  270. "work_root": str(work_root),
  271. "resource_class": classify_task("board_viewer"),
  272. }
  273. _write_json(receipt_path, receipt)
  274. log_path.write_text(
  275. "blocked: full_regeneration requested but raw BRD/PDF/DSN not available\n",
  276. encoding="utf-8",
  277. )
  278. return receipt
  279. cmd = [
  280. _safe_python(),
  281. "-B",
  282. "-m",
  283. "pytest",
  284. "-q",
  285. "-p",
  286. "no:cacheprovider",
  287. f"--basetemp={work_root / 'tmp' / 'pytest'}",
  288. "tests/board_viewer",
  289. ]
  290. code = _run_visible_cmd(
  291. cmd,
  292. cwd=repo,
  293. log_path=log_path,
  294. status_path=status_path,
  295. name="board_viewer",
  296. timeout_s=900,
  297. env=isolation,
  298. )
  299. receipt = {
  300. "schema": "prod2u-board-viewer-receipt-v1",
  301. "mode": MODE_FULL,
  302. "status": "pass" if code == 0 else "fail",
  303. "reference_change_detected": decision["reference_change_detected"],
  304. "reference_regeneration_replay": "required",
  305. "raw_reference_used": True,
  306. "selection": decision,
  307. "verification_run_id": run_id,
  308. "commit_full": prod2u_p4_harness.current_commit(),
  309. "command": " ".join(cmd),
  310. "returncode": code,
  311. "log_path": str(log_path),
  312. "report_path": str(receipt_path),
  313. "work_root": str(work_root),
  314. "resource_class": classify_task("board_viewer"),
  315. }
  316. _write_json(receipt_path, receipt)
  317. return receipt
  318. def _run_harness_lane(
  319. repo: Path,
  320. work_root: Path,
  321. run_id: str,
  322. lane: str,
  323. subcommand: str,
  324. extra_args: list[str] | None = None,
  325. *,
  326. timeout_s: float = 1800,
  327. log_dir: Path | None = None,
  328. ) -> dict[str, Any]:
  329. log_root = log_dir or work_root
  330. receipt_path = work_root / f"{lane}-receipt.json"
  331. log_path = log_root / f"{lane}.log"
  332. status_path = log_root / f"{lane}.status.json"
  333. work_root.mkdir(parents=True, exist_ok=True)
  334. log_root.mkdir(parents=True, exist_ok=True)
  335. isolation = lane_isolation_env(work_root, task=lane)
  336. isolation["PRODU2_VERIFY_PYTHON"] = _safe_python()
  337. isolation.setdefault(
  338. "PRODU2_VERIFY_VENV",
  339. os.environ.get("PRODU2_VERIFY_VENV", "/data/prod2u/venvs/verify"),
  340. )
  341. cmd = [
  342. _safe_python(),
  343. "-B",
  344. "tools/prod2u_p4_harness.py",
  345. subcommand,
  346. "--run",
  347. "--work-root",
  348. str(work_root),
  349. "--verification-run-id",
  350. run_id,
  351. "--report-file",
  352. str(receipt_path),
  353. ]
  354. if extra_args:
  355. cmd.extend(extra_args)
  356. _run_visible_cmd(
  357. cmd,
  358. cwd=repo,
  359. log_path=log_path,
  360. status_path=status_path,
  361. name=lane,
  362. timeout_s=timeout_s,
  363. env=isolation,
  364. )
  365. try:
  366. receipt = json.loads(receipt_path.read_text(encoding="utf-8-sig"))
  367. except (OSError, json.JSONDecodeError):
  368. receipt = {
  369. "schema": f"prod2u-p4-normal-v3-{lane}-receipt-v1",
  370. "status": "blocked",
  371. "verification_run_id": run_id,
  372. "failures": [f"receipt_unreadable:{lane}"],
  373. "log_path": str(log_path),
  374. }
  375. receipt.setdefault("log_path", str(log_path))
  376. receipt.setdefault("report_path", str(receipt_path))
  377. receipt.setdefault("status_path", str(status_path))
  378. receipt.setdefault("work_root", str(work_root))
  379. receipt.setdefault("resource_class", classify_task(lane))
  380. return receipt
  381. def run_hdl_lane(
  382. repo: Path,
  383. work_root: Path,
  384. run_id: str,
  385. lane: str,
  386. *,
  387. log_dir: Path | None = None,
  388. ) -> dict[str, Any]:
  389. return _run_harness_lane(
  390. repo,
  391. work_root,
  392. run_id,
  393. lane,
  394. "hdl-sim",
  395. ["--backend", lane],
  396. timeout_s=1200,
  397. log_dir=log_dir,
  398. )
  399. def run_formal(
  400. repo: Path,
  401. work_root: Path,
  402. run_id: str,
  403. *,
  404. log_dir: Path | None = None,
  405. ) -> dict[str, Any]:
  406. # Wall-clock for the whole formal lane. Per-task timeout remains
  407. # PROD2U_P4_TIMEOUT_FORMAL_SECONDS (default 600). Low-memory hosts need a
  408. # long lane budget because frame_tx BMC depth=96 alone can exceed 15 minutes.
  409. raw = os.environ.get("PROD2U_P4_TIMEOUT_FORMAL_LANE_SECONDS", "").strip()
  410. try:
  411. lane_timeout = float(raw) if raw else 7200.0
  412. except ValueError:
  413. lane_timeout = 7200.0
  414. if lane_timeout <= 0:
  415. lane_timeout = 7200.0
  416. return _run_harness_lane(
  417. repo,
  418. work_root,
  419. run_id,
  420. "formal",
  421. "formal",
  422. timeout_s=lane_timeout,
  423. log_dir=log_dir,
  424. )
  425. def run_td(
  426. repo: Path,
  427. work_root: Path,
  428. run_id: str,
  429. *,
  430. log_dir: Path | None = None,
  431. ) -> dict[str, Any]:
  432. lock_dir = Path(os.environ.get("XDG_RUNTIME_DIR", "/tmp")) / "prod2u"
  433. lock_dir.mkdir(parents=True, exist_ok=True)
  434. lock_path = lock_dir / "td.lock"
  435. # Exclusive file lock via O_EXCL marker.
  436. try:
  437. fd = os.open(str(lock_path), os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
  438. os.write(fd, f"{os.getpid()} {run_id}\n".encode())
  439. os.close(fd)
  440. except FileExistsError:
  441. return {
  442. "schema": "prod2u-p4-normal-v3-td-build-receipt-v2",
  443. "status": "blocked",
  444. "verification_run_id": run_id,
  445. "failures": [f"td_lock_held:{lock_path}"],
  446. "report_path": str(work_root / "td-receipt.json"),
  447. "work_root": str(work_root),
  448. "resource_class": "exclusive",
  449. }
  450. try:
  451. receipt = _run_harness_lane(
  452. repo,
  453. work_root,
  454. run_id,
  455. "td",
  456. "td-build",
  457. timeout_s=3600,
  458. log_dir=log_dir,
  459. )
  460. receipt["resource_class"] = "exclusive"
  461. return receipt
  462. finally:
  463. try:
  464. lock_path.unlink(missing_ok=True)
  465. except OSError:
  466. pass
  467. LANE_RUNNERS: dict[str, Callable[..., dict[str, Any]]] = {
  468. "python": run_python_unit,
  469. "board_viewer": run_board_viewer,
  470. "icarus": run_hdl_lane,
  471. "verilator": run_hdl_lane,
  472. "cocotb": run_hdl_lane,
  473. "formal": run_formal,
  474. "td": run_td,
  475. }
  476. def _overall_status(results: dict[str, dict[str, Any]], selected: list[str]) -> str:
  477. if not selected:
  478. return "not_run"
  479. statuses = {lane: results.get(lane, {}).get("status", "not_run") for lane in selected}
  480. if all(s == "pass" for s in statuses.values()):
  481. return "pass"
  482. if all(s in ("blocked", "not_run") for s in statuses.values()):
  483. return "blocked"
  484. return "fail"
  485. def main() -> int:
  486. parser = argparse.ArgumentParser(description="Run the verification matrix")
  487. parser.add_argument(
  488. "--work-root-prefix",
  489. default="",
  490. help="Legacy prefix: {prefix}-{lane}-{run_id8} (mutually exclusive with --run-root).",
  491. )
  492. parser.add_argument(
  493. "--run-root",
  494. default="",
  495. help="Run root with builds/ and logs/ per task (preferred for packager matrix).",
  496. )
  497. parser.add_argument("--verification-run-id", default="")
  498. parser.add_argument("--report-file", required=True)
  499. parser.add_argument("--lanes", default=",".join(DEFAULT_LANES))
  500. parser.add_argument("--only-lane", help="rerun a single lane")
  501. parser.add_argument(
  502. "--max-workers",
  503. type=int,
  504. default=None,
  505. help="Cap open-source concurrency (default: host-resource plan).",
  506. )
  507. args = parser.parse_args()
  508. strip_poison_env()
  509. ensure_safe_sys_executable()
  510. if not os.environ.get("PRODU2_VERIFY_PYTHON", "").strip():
  511. os.environ["PRODU2_VERIFY_PYTHON"] = _safe_python()
  512. _prefer_oss_cad_on_path()
  513. repo = _repo_root
  514. run_id = (args.verification_run_id or uuid.uuid4().hex).strip().lower()
  515. if len(run_id) != 32 or any(c not in "0123456789abcdef" for c in run_id):
  516. # Allow non-hex run ids from wrappers by hashing to 32 hex.
  517. import hashlib
  518. run_id = hashlib.sha256(run_id.encode()).hexdigest()[:32]
  519. selected = [args.only_lane] if args.only_lane else [l.strip() for l in args.lanes.split(",") if l.strip()]
  520. unknown = [l for l in selected if l not in LANE_RUNNERS]
  521. if unknown:
  522. print(f"unknown lanes: {unknown}", file=sys.stderr)
  523. return 1
  524. run_root = Path(args.run_root).expanduser().resolve() if args.run_root else None
  525. work_root_prefix = args.work_root_prefix.strip() or None
  526. if run_root is None and work_root_prefix is None:
  527. print("error: provide --run-root or --work-root-prefix", file=sys.stderr)
  528. return 2
  529. plan = plan_concurrency(selected, max_workers_cap=args.max_workers)
  530. print(
  531. f"[matrix] resource_plan workers={plan['max_workers']} "
  532. f"formal_slots={plan['formal_slots']} td_exclusive={plan['td_exclusive']} "
  533. f"nproc={plan['host']['nproc']} mem_available_kb={plan['host']['mem_available_kb']} "
  534. f"disk_free_bytes={plan['host'].get('disk_free_bytes')} "
  535. f"classes={plan['lane_classes']}",
  536. flush=True,
  537. )
  538. results: dict[str, dict[str, Any]] = {}
  539. lane_dirs: dict[str, dict[str, str]] = {}
  540. def _run_lane(lane: str) -> tuple[str, dict[str, Any]]:
  541. paths = _lane_paths(
  542. lane=lane,
  543. run_id=run_id,
  544. run_root=run_root,
  545. work_root_prefix=work_root_prefix,
  546. )
  547. work_root = paths["work_root"]
  548. log_dir = paths["log_dir"]
  549. lane_dirs[lane] = {
  550. "work_root": str(work_root),
  551. "build_dir": str(paths["build_dir"]),
  552. "log_dir": str(log_dir),
  553. }
  554. runner = LANE_RUNNERS[lane]
  555. print(
  556. f"[matrix] starting lane={lane} class={classify_task(lane)} "
  557. f"work_root={work_root} log_dir={log_dir}",
  558. flush=True,
  559. )
  560. if lane in ("icarus", "verilator", "cocotb"):
  561. receipt = runner(repo, work_root, run_id, lane, log_dir=log_dir)
  562. else:
  563. receipt = runner(repo, work_root, run_id, log_dir=log_dir)
  564. print(f"[matrix] finished lane={lane} status={receipt.get('status')}", flush=True)
  565. return lane, receipt
  566. start = time.time()
  567. open_lanes = [lane for lane in selected if lane not in TD_EXCLUSIVE]
  568. td_lanes = [lane for lane in selected if lane in TD_EXCLUSIVE]
  569. for wave in schedule_waves(open_lanes, plan):
  570. workers = min(plan["max_workers"], max(1, len(wave)))
  571. with ThreadPoolExecutor(max_workers=workers) as pool:
  572. futures = [pool.submit(_run_lane, lane) for lane in wave]
  573. for fut in as_completed(futures):
  574. lane, receipt = fut.result()
  575. results[lane] = receipt
  576. # TD exclusive: never overlap with OSS lanes or another TD.
  577. for lane in td_lanes:
  578. lane_name, receipt = _run_lane(lane)
  579. results[lane_name] = receipt
  580. duration = time.time() - start
  581. full_commit = prod2u_p4_harness.current_commit()
  582. overall = _overall_status(results, selected)
  583. matrix = {
  584. "schema": "prod2u-p4-normal-v3-verification-matrix-v2",
  585. "generated_at": _utc_now(),
  586. "verification_run_id": run_id,
  587. "commit": full_commit[:8] if full_commit else None,
  588. "commit_full": full_commit,
  589. "dirty": None,
  590. "project_config_sha256": _sha256_file(repo / "projects" / "prod2u-door-temp" / "project.json"),
  591. "td_source_manifest_sha256": _sha256_file(repo / "src" / "generated" / "td-source-manifest.json"),
  592. "status": overall,
  593. "duration_seconds": round(duration, 3),
  594. "lanes": results,
  595. "lane_dirs": lane_dirs,
  596. "failures": [f"{lane}:{r['status']}" for lane, r in results.items() if r.get("status") != "pass"],
  597. "environment": "linux",
  598. "td_command": "td2026",
  599. "resource_plan": plan,
  600. "host_resources": host_resources(),
  601. }
  602. report_path = Path(args.report_file)
  603. report_path.parent.mkdir(parents=True, exist_ok=True)
  604. _write_json(report_path, matrix)
  605. print(json.dumps({"status": overall, "report": str(report_path)}, indent=2))
  606. return 0 if overall == "pass" else 1
  607. if __name__ == "__main__":
  608. sys.exit(main())