run_6400_soak.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. """Run the active simulator-free 6400 manual soak and emit a receipt."""
  3. from __future__ import annotations
  4. import hashlib
  5. import json
  6. import os
  7. from pathlib import Path
  8. import subprocess
  9. import sys
  10. import time
  11. ROOT = Path(__file__).resolve().parents[1]
  12. CLOSURE = ROOT / "products/6400-front-rear/source-closure.json"
  13. def sha256(path: Path) -> str:
  14. digest = hashlib.sha256()
  15. with path.open("rb") as stream:
  16. for block in iter(lambda: stream.read(1024 * 1024), b""):
  17. digest.update(block)
  18. return digest.hexdigest()
  19. def git(*args: str) -> str:
  20. return subprocess.check_output(["git", *args], cwd=ROOT, text=True).strip()
  21. def main() -> int:
  22. dirty = git("status", "--porcelain")
  23. if dirty:
  24. raise SystemExit("soak requires a clean source worktree")
  25. commit, tree = git("rev-parse", "HEAD"), git("rev-parse", "HEAD^{tree}")
  26. closure = json.loads(CLOSURE.read_text(encoding="utf-8"))
  27. sources = [ROOT / item for item in closure["sources"] if item.endswith(".v")]
  28. test = ROOT / "tests/manual_6400_soak.py"
  29. inputs = [CLOSURE, test, *sources]
  30. source_manifest = hashlib.sha256(
  31. json.dumps({str(p.relative_to(ROOT)): sha256(p) for p in inputs}, sort_keys=True, separators=(",", ":")).encode()
  32. ).hexdigest()
  33. run_id = "6400-manual-soak-" + commit[:8]
  34. run_root = Path(os.environ.get("PROD2U_SOAK_RUN_ROOT", "/data/prod2u/runs")) / run_id
  35. run_root.mkdir(parents=True, exist_ok=False)
  36. result_json = run_root / "soak-result.json"
  37. env = os.environ.copy()
  38. env["PROD2U_SOAK_RESULT"] = str(result_json)
  39. env.setdefault("PROD2U_SOAK_ITERATIONS", "2048")
  40. env.setdefault("PROD2U_SOAK_SEED", "64006400")
  41. started = time.monotonic()
  42. completed = subprocess.run([sys.executable, "-B", str(test)], cwd=ROOT, env=env, text=True, capture_output=True, check=False)
  43. status = "PASS" if completed.returncode == 0 and result_json.is_file() else "FAIL"
  44. receipt = {
  45. "schema": "prod2u-6400-manual-soak-receipt-v1", "run_id": run_id, "status": status,
  46. "commit": commit, "tree": tree, "clean": not bool(dirty),
  47. "command": "python3 tools/run_6400_soak.py", "duration_seconds": round(time.monotonic() - started, 3),
  48. "source_manifest_sha256": source_manifest, "iterations": int(env["PROD2U_SOAK_ITERATIONS"]),
  49. "seed": int(env["PROD2U_SOAK_SEED"]), "result": json.loads(result_json.read_text()) if result_json.is_file() else None,
  50. "stdout": completed.stdout[-4000:], "stderr": completed.stderr[-4000:], "hardware": "NOT_RUN",
  51. }
  52. receipt_path = run_root / "soak-receipt.json"
  53. receipt_path.write_text(json.dumps(receipt, indent=2, sort_keys=True) + "\n", encoding="utf-8")
  54. print(receipt_path)
  55. print("MANUAL_SOAK_PASS" if status == "PASS" else "MANUAL_SOAK_FAIL")
  56. return 0 if status == "PASS" else 1
  57. if __name__ == "__main__":
  58. raise SystemExit(main())