#!/usr/bin/env python3 """ run_all_tiers.py — XJKJ-STL Four-Tier Web-Only Full-Stack Simulation & Verification Master Runner Executes all 4 simulation & verification tiers end-to-end and generates an aggregated JSON audit report at `build/sim/full_sim_report.json`: - Tier 1: Native Kernel / Actor / Watchdog / Thermal Closed-Loop / Trace / SIMD Unit & Integration Suite + `bmc_ssh_hil_sim` C RMCP+/SSHv2 Kernel Smoke Test + `web/*.js` Syntax Check - Tier 2: Multi-Station Hardware-in-the-Loop (HIL) Full-Stack E2E (`bmc_ssh_hil_sim` UDP :623 RMCP+ Cipher Suite 17 + 24-ch SDR + SSHv2 :2200 + UDP TFTP WRQ + `/dev/pts/*` 6400 Hood v1.1) - Tier 3: Real Hardware KVM (`/dev/kvm` on `192.168.2.25`) + EDK2 OVMF UEFI + Real `mt86plus.efi` + QMP Hardware vCPU Freeze & IPMI-to-QMP Reset E2E - Tier 4: Real Headless Chrome 156 CDP Web Frontend E2E (Login, Production/Engineering Views, Watchdog, Trace) """ import argparse import datetime as dt import json import os from pathlib import Path import subprocess import sys import time from typing import Any, Dict, List ROOT_DIR = Path(__file__).resolve().parents[1] PY_BIN = "/opt/prod2u/venv/bin/python3" if os.path.exists("/opt/prod2u/venv/bin/python3") else sys.executable def clean_env() -> Dict[str, str]: env = dict(os.environ) for k in ( "LD_LIBRARY_PATH", "QT_PLUGIN_PATH", "QT_QPA_PLATFORM_PLUGIN_PATH", "QT_QPA_PLATFORM", "http_proxy", "https_proxy", "HTTP_PROXY", "HTTPS_PROXY", "all_proxy", "ALL_PROXY", ): env.pop(k, None) return env def run_step(name: str, cmd: List[str], cwd: Path = ROOT_DIR, timeout_s: int = 300) -> Dict[str, Any]: print(f"\n{'=' * 78}\n>>> RUNNING {name}\n CMD: {' '.join(cmd)}\n{'=' * 78}", flush=True) t0 = time.monotonic() proc = subprocess.run( cmd, cwd=str(cwd), env=clean_env(), text=True, capture_output=True, timeout=timeout_s, ) elapsed = round(time.monotonic() - t0, 2) if proc.stdout: print(proc.stdout.rstrip(), flush=True) if proc.returncode != 0: if proc.stderr: print(proc.stderr.rstrip(), file=sys.stderr, flush=True) raise RuntimeError(f"{name} FAILED with exit code {proc.returncode} after {elapsed}s") print(f"<<< {name} PASSED in {elapsed}s", flush=True) return {"name": name, "ok": True, "elapsed_s": elapsed} def run_tier1(skip_native_rebuild: bool = False) -> Dict[str, Any]: t0 = time.monotonic() sub = [] # 1a. Full native C/Zig/ASM/re2c/Rust server + 28 unit/integration tests if skip_native_rebuild and (ROOT_DIR / "build" / "native" / "stl_native_tests").is_file(): sub.append( run_step( "Tier1.1 Native 31 Rust/C/Zig/ASM Tests", [str(ROOT_DIR / "build" / "native" / "stl_native_tests")], cwd=ROOT_DIR, timeout_s=180, ) ) else: sub.append( run_step( "Tier1.1 Native Build & 31 Rust/C/Zig/ASM Tests", ["bash", str(ROOT_DIR / "native" / "stl_accel" / "build.sh")], cwd=ROOT_DIR, timeout_s=480, ) ) # 1b. Compile C HIL BMC RMCP+/SSHv2 daemon + direct `libstl_kernels.a` smoke test build_sim = ROOT_DIR / "build" / "sim" build_sim.mkdir(parents=True, exist_ok=True) bmc_sim_bin = build_sim / "bmc_ssh_hil_sim" smoke_bin = build_sim / "smoke_test_bmc_ssh" sub.append( run_step( "Tier1.2a Compile bmc_ssh_hil_sim & smoke_test_bmc_ssh", [ "gcc", "-O2", "-Wall", "-Wextra", str(ROOT_DIR / "sim" / "hil_cluster" / "bmc_ssh_hil_sim.c"), "-o", str(bmc_sim_bin), "-lfreeipmi", "-lssh", "-lcrypto", "-lpthread", ], cwd=ROOT_DIR, timeout_s=60, ) ) run_step( "Tier1.2b Link smoke_test_bmc_ssh against libstl_kernels.a", [ "gcc", "-O2", "-Wall", "-Wextra", str(ROOT_DIR / "sim" / "hil_cluster" / "smoke_test_bmc_ssh.c"), f"-L{ROOT_DIR / 'build' / 'native'}", "-lstl_kernels", "-lfreeipmi", "-lipmiconsole", "-lssh", "-lutil", "-ldl", "-lpthread", "-o", str(smoke_bin), ], cwd=ROOT_DIR, timeout_s=60, ) t_smk = time.monotonic() print(f"\n{'=' * 78}\n>>> RUNNING Tier1.2c Execute Kernel RMCP+/SSHv2 Smoke Test\n{'=' * 78}", flush=True) sim_proc = subprocess.Popen( [ str(bmc_sim_bin), "--ctrl-port", "19199", "--uart-base", "19200", "--ipmi-port", "623", "--ssh-port", "2200", "--probe22-port", "0", "127.0.2.166", ], cwd=str(ROOT_DIR), env=clean_env(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, ) try: time.sleep(0.5) sub.append( run_step( "Tier1.2c Execute Kernel RMCP+/SSHv2 Smoke Test", [str(smoke_bin), "127.0.2.166", "19200"], cwd=ROOT_DIR, timeout_s=30, ) ) finally: sim_proc.terminate() try: sim_proc.wait(timeout=3.0) except Exception: sim_proc.kill() _ = t_smk # 1c. Web JS syntax check across all frontend modules js_files = sorted((ROOT_DIR / "web").glob("*.js")) assert js_files, "No web/*.js files found" for jf in js_files: run_step(f"Tier1.3 JS Syntax Check ({jf.name})", ["node", "--check", str(jf)], cwd=ROOT_DIR, timeout_s=30) sub.append({"name": f"Tier1.3 Web Frontend JS Syntax ({len(js_files)} files)", "ok": True, "elapsed_s": 0.0}) return {"tier": "Tier1_Build_And_Native_Unit_Suite", "ok": True, "elapsed_s": round(time.monotonic() - t0, 2), "steps": sub} def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("--skip-kvm", action="store_true", help="Skip Tier 3 remote 192.168.2.25 KVM tier") parser.add_argument("--skip-native-rebuild", action="store_true", help="Run prebuilt stl_native_tests directly instead of full build.sh") args = parser.parse_args() t_all = time.monotonic() tiers: List[Dict[str, Any]] = [] tiers.append(run_tier1(skip_native_rebuild=args.skip_native_rebuild)) 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)) if not args.skip_kvm: 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)) 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)) 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)) 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)) total_s = round(time.monotonic() - t_all, 2) report = { "schema": "xjkj-stl-5tier-full-sim-v3", "version": (ROOT_DIR / "VERSION").read_text(encoding="utf-8").strip(), "completed_utc": dt.datetime.now(dt.timezone.utc).isoformat(), "all_passed": True, "total_elapsed_s": total_s, "tiers": tiers, } out_path = ROOT_DIR / "build" / "sim" / "full_sim_report.json" out_path.parent.mkdir(parents=True, exist_ok=True) out_path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") print(f"\n{'#' * 78}\nALL {len(tiers)} SIMULATION & VERIFICATION TIERS PASSED 100% in {total_s}s!\nReport: {out_path}\n{'#' * 78}", flush=True) if __name__ == "__main__": main()