run_all_tiers.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #!/usr/bin/env python3
  2. """
  3. run_all_tiers.py — XJKJ-STL Four-Tier Web-Only Full-Stack Simulation & Verification Master Runner
  4. Executes all 4 simulation & verification tiers end-to-end and generates an aggregated
  5. JSON audit report at `build/sim/full_sim_report.json`:
  6. - Tier 1: Native Kernel / Actor / Watchdog / Thermal Closed-Loop / Trace / SIMD Unit & Integration Suite
  7. + `bmc_ssh_hil_sim` C RMCP+/SSHv2 Kernel Smoke Test + `web/*.js` Syntax Check
  8. - Tier 2: Multi-Station Hardware-in-the-Loop (HIL) Full-Stack E2E (`bmc_ssh_hil_sim` UDP :623 RMCP+
  9. Cipher Suite 17 + 24-ch SDR + SSHv2 :2200 + UDP TFTP WRQ + `/dev/pts/*` 6400 Hood v1.1)
  10. - Tier 3: Real Hardware KVM (`/dev/kvm` on `192.168.2.25`) + EDK2 OVMF UEFI + Real `mt86plus.efi`
  11. + QMP Hardware vCPU Freeze & IPMI-to-QMP Reset E2E
  12. - Tier 4: Real Headless Chrome 156 CDP Web Frontend E2E (Login, Production/Engineering Views, Watchdog, Trace)
  13. """
  14. import argparse
  15. import datetime as dt
  16. import json
  17. import os
  18. from pathlib import Path
  19. import subprocess
  20. import sys
  21. import time
  22. from typing import Any, Dict, List
  23. ROOT_DIR = Path(__file__).resolve().parents[1]
  24. PY_BIN = "/opt/prod2u/venv/bin/python3" if os.path.exists("/opt/prod2u/venv/bin/python3") else sys.executable
  25. def clean_env() -> Dict[str, str]:
  26. env = dict(os.environ)
  27. for k in (
  28. "LD_LIBRARY_PATH",
  29. "QT_PLUGIN_PATH",
  30. "QT_QPA_PLATFORM_PLUGIN_PATH",
  31. "QT_QPA_PLATFORM",
  32. "http_proxy",
  33. "https_proxy",
  34. "HTTP_PROXY",
  35. "HTTPS_PROXY",
  36. "all_proxy",
  37. "ALL_PROXY",
  38. ):
  39. env.pop(k, None)
  40. return env
  41. def run_step(name: str, cmd: List[str], cwd: Path = ROOT_DIR, timeout_s: int = 300) -> Dict[str, Any]:
  42. print(f"\n{'=' * 78}\n>>> RUNNING {name}\n CMD: {' '.join(cmd)}\n{'=' * 78}", flush=True)
  43. t0 = time.monotonic()
  44. proc = subprocess.run(
  45. cmd,
  46. cwd=str(cwd),
  47. env=clean_env(),
  48. text=True,
  49. capture_output=True,
  50. timeout=timeout_s,
  51. )
  52. elapsed = round(time.monotonic() - t0, 2)
  53. if proc.stdout:
  54. print(proc.stdout.rstrip(), flush=True)
  55. if proc.returncode != 0:
  56. if proc.stderr:
  57. print(proc.stderr.rstrip(), file=sys.stderr, flush=True)
  58. raise RuntimeError(f"{name} FAILED with exit code {proc.returncode} after {elapsed}s")
  59. print(f"<<< {name} PASSED in {elapsed}s", flush=True)
  60. return {"name": name, "ok": True, "elapsed_s": elapsed}
  61. def run_tier1(skip_native_rebuild: bool = False) -> Dict[str, Any]:
  62. t0 = time.monotonic()
  63. sub = []
  64. # 1a. Full native C/Zig/ASM/re2c/Rust server + 28 unit/integration tests
  65. if skip_native_rebuild and (ROOT_DIR / "build" / "native" / "stl_native_tests").is_file():
  66. sub.append(
  67. run_step(
  68. "Tier1.1 Native 31 Rust/C/Zig/ASM Tests",
  69. [str(ROOT_DIR / "build" / "native" / "stl_native_tests")],
  70. cwd=ROOT_DIR,
  71. timeout_s=180,
  72. )
  73. )
  74. else:
  75. sub.append(
  76. run_step(
  77. "Tier1.1 Native Build & 31 Rust/C/Zig/ASM Tests",
  78. ["bash", str(ROOT_DIR / "native" / "stl_accel" / "build.sh")],
  79. cwd=ROOT_DIR,
  80. timeout_s=480,
  81. )
  82. )
  83. # 1b. Compile C HIL BMC RMCP+/SSHv2 daemon + direct `libstl_kernels.a` smoke test
  84. build_sim = ROOT_DIR / "build" / "sim"
  85. build_sim.mkdir(parents=True, exist_ok=True)
  86. bmc_sim_bin = build_sim / "bmc_ssh_hil_sim"
  87. smoke_bin = build_sim / "smoke_test_bmc_ssh"
  88. sub.append(
  89. run_step(
  90. "Tier1.2a Compile bmc_ssh_hil_sim & smoke_test_bmc_ssh",
  91. [
  92. "gcc",
  93. "-O2",
  94. "-Wall",
  95. "-Wextra",
  96. str(ROOT_DIR / "sim" / "hil_cluster" / "bmc_ssh_hil_sim.c"),
  97. "-o",
  98. str(bmc_sim_bin),
  99. "-lfreeipmi",
  100. "-lssh",
  101. "-lcrypto",
  102. "-lpthread",
  103. ],
  104. cwd=ROOT_DIR,
  105. timeout_s=60,
  106. )
  107. )
  108. run_step(
  109. "Tier1.2b Link smoke_test_bmc_ssh against libstl_kernels.a",
  110. [
  111. "gcc",
  112. "-O2",
  113. "-Wall",
  114. "-Wextra",
  115. str(ROOT_DIR / "sim" / "hil_cluster" / "smoke_test_bmc_ssh.c"),
  116. f"-L{ROOT_DIR / 'build' / 'native'}",
  117. "-lstl_kernels",
  118. "-lfreeipmi",
  119. "-lipmiconsole",
  120. "-lssh",
  121. "-lutil",
  122. "-ldl",
  123. "-lpthread",
  124. "-o",
  125. str(smoke_bin),
  126. ],
  127. cwd=ROOT_DIR,
  128. timeout_s=60,
  129. )
  130. t_smk = time.monotonic()
  131. print(f"\n{'=' * 78}\n>>> RUNNING Tier1.2c Execute Kernel RMCP+/SSHv2 Smoke Test\n{'=' * 78}", flush=True)
  132. sim_proc = subprocess.Popen(
  133. [
  134. str(bmc_sim_bin),
  135. "--ctrl-port", "19199",
  136. "--uart-base", "19200",
  137. "--ipmi-port", "623",
  138. "--ssh-port", "2200",
  139. "--probe22-port", "0",
  140. "127.0.2.166",
  141. ],
  142. cwd=str(ROOT_DIR),
  143. env=clean_env(),
  144. stdout=subprocess.PIPE,
  145. stderr=subprocess.PIPE,
  146. text=True,
  147. )
  148. try:
  149. time.sleep(0.5)
  150. sub.append(
  151. run_step(
  152. "Tier1.2c Execute Kernel RMCP+/SSHv2 Smoke Test",
  153. [str(smoke_bin), "127.0.2.166", "19200"],
  154. cwd=ROOT_DIR,
  155. timeout_s=30,
  156. )
  157. )
  158. finally:
  159. sim_proc.terminate()
  160. try:
  161. sim_proc.wait(timeout=3.0)
  162. except Exception:
  163. sim_proc.kill()
  164. _ = t_smk
  165. # 1c. Web JS syntax check across all frontend modules
  166. js_files = sorted((ROOT_DIR / "web").glob("*.js"))
  167. assert js_files, "No web/*.js files found"
  168. for jf in js_files:
  169. run_step(f"Tier1.3 JS Syntax Check ({jf.name})", ["node", "--check", str(jf)], cwd=ROOT_DIR, timeout_s=30)
  170. sub.append({"name": f"Tier1.3 Web Frontend JS Syntax ({len(js_files)} files)", "ok": True, "elapsed_s": 0.0})
  171. return {"tier": "Tier1_Build_And_Native_Unit_Suite", "ok": True, "elapsed_s": round(time.monotonic() - t0, 2), "steps": sub}
  172. def main() -> None:
  173. parser = argparse.ArgumentParser()
  174. parser.add_argument("--skip-kvm", action="store_true", help="Skip Tier 3 remote 192.168.2.25 KVM tier")
  175. parser.add_argument("--skip-native-rebuild", action="store_true", help="Run prebuilt stl_native_tests directly instead of full build.sh")
  176. args = parser.parse_args()
  177. t_all = time.monotonic()
  178. tiers: List[Dict[str, Any]] = []
  179. tiers.append(run_tier1(skip_native_rebuild=args.skip_native_rebuild))
  180. tiers.append(run_step("Tier2 Multi-Station HIL Full-Stack E2E", [PY_BIN, str(ROOT_DIR / "sim" / "hil_cluster" / "test_tier2_hil_e2e.py")], timeout_s=360))
  181. if not args.skip_kvm:
  182. tiers.append(run_step("Tier3A Real KVM + OVMF UEFI + mt86plus.efi E2E", [PY_BIN, str(ROOT_DIR / "sim" / "kvm_uefi_tier" / "test_tier3_kvm_uefi_e2e.py")], timeout_s=300))
  183. tiers.append(run_step("Tier3B Real 100% Diskless KVM+OVMF ProxyDHCP under Competing LAN Router", [PY_BIN, str(ROOT_DIR / "sim" / "kvm_uefi_tier" / "test_tier3b_diskless_pxe.py")], timeout_s=240))
  184. tiers.append(run_step("Tier4 Headless Chrome 156 CDP Web E2E", [PY_BIN, str(ROOT_DIR / "sim" / "web_e2e" / "test_tier4_chrome_web_e2e.py")], timeout_s=300))
  185. tiers.append(run_step("Tier5 6-Tier ISA Kernels & 200-Station Scale Benchmark", [PY_BIN, str(ROOT_DIR / "sim" / "bench_scale_performance.py")], timeout_s=240))
  186. total_s = round(time.monotonic() - t_all, 2)
  187. report = {
  188. "schema": "xjkj-stl-5tier-full-sim-v3",
  189. "version": (ROOT_DIR / "VERSION").read_text(encoding="utf-8").strip(),
  190. "completed_utc": dt.datetime.now(dt.timezone.utc).isoformat(),
  191. "all_passed": True,
  192. "total_elapsed_s": total_s,
  193. "tiers": tiers,
  194. }
  195. out_path = ROOT_DIR / "build" / "sim" / "full_sim_report.json"
  196. out_path.parent.mkdir(parents=True, exist_ok=True)
  197. out_path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
  198. print(f"\n{'#' * 78}\nALL {len(tiers)} SIMULATION & VERIFICATION TIERS PASSED 100% in {total_s}s!\nReport: {out_path}\n{'#' * 78}", flush=True)
  199. if __name__ == "__main__":
  200. main()