run_verification_matrix.py 22 KB

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