tools: defer Unicorn import and add --check-offline to standalone oracle scripts

This commit is contained in:
morebrackets
2026-12-02 07:12:57 -08:00
parent db720ba4a6
commit 9bda72abc1
5 changed files with 241 additions and 35 deletions

View File

@ -0,0 +1,82 @@
#!/usr/bin/env python3
"""Offline tests for oracle_{enterprise_subsystems,fabric_sriov,live_runtime_wiring,vbios_inforom_tegra}.py."""
from __future__ import annotations
import json
import pathlib
import subprocess
import sys
import unittest
ROOT = pathlib.Path(__file__).resolve().parents[2]
class StandaloneOraclesOfflineTests(unittest.TestCase):
def test_help_works_without_unicorn(self) -> None:
for rel in (
"tools/oracle_enterprise_subsystems.py",
"tools/oracle_fabric_sriov.py",
"tools/oracle_live_runtime_wiring.py",
"tools/oracle_vbios_inforom_tegra.py",
):
proc = subprocess.run(
[sys.executable, "-O", str(ROOT / rel), "--help"],
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, f"{rel} --help failed: {proc.stderr}")
def test_live_runtime_wiring_offline_e2e_checks(self) -> None:
proc = subprocess.run(
[
sys.executable,
"-O",
str(ROOT / "tools/oracle_live_runtime_wiring.py"),
"--check-offline",
"--json",
],
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
payload = json.loads(proc.stdout)
self.assertTrue(payload["passed"], payload)
self.assertEqual(payload["passed_count"], 10)
self.assertEqual(payload["total"], 10)
def test_enterprise_subsystems_aes256_gcm_offline(self) -> None:
proc = subprocess.run(
[
sys.executable,
"-O",
str(ROOT / "tools/oracle_enterprise_subsystems.py"),
"--check-offline",
],
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
payload = json.loads(proc.stdout)
self.assertTrue(payload["passed"], payload)
self.assertEqual(payload["passed_count"], 1)
def test_vbios_inforom_tegra_offline(self) -> None:
proc = subprocess.run(
[
sys.executable,
"-O",
str(ROOT / "tools/oracle_vbios_inforom_tegra.py"),
"--check-offline",
"--json",
],
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
payload = json.loads(proc.stdout)
self.assertTrue(payload["all_passed"], payload)
self.assertEqual(payload["passed"], 1)
if __name__ == "__main__":
unittest.main()

View File

@ -11,17 +11,21 @@ Exports `run_checks()` returning a list of `{"name": str, "passed": bool, "diffs
"""
from __future__ import annotations
import argparse
import hashlib
import hmac
import json
import struct
import sys
from pathlib import Path
from typing import TYPE_CHECKING
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tools"))
if str(ROOT / "tools") not in sys.path:
sys.path.insert(0, str(ROOT / "tools"))
from rmapi_binary_emulator import Emulator # noqa: E402
if TYPE_CHECKING:
from rmapi_binary_emulator import Emulator
# ---------------------------------------------------------------------------
@ -577,7 +581,29 @@ def check_gpudirect_rdma_dma_map_oracle(emu: Emulator) -> dict:
return {"name": "gpudirect_rdma_p2p_dma_map", "passed": len(diffs) == 0, "diffs": diffs}
def run_offline_checks() -> list[dict]:
"""Run pure-Python NIST AES-256-GCM & HMAC-SHA256 reference checks without Unicorn."""
diffs: list[str] = []
# NIST SP 800-38D Test Case 14 (AES-256-GCM, 16-byte plaintext, empty AAD)
key = bytes(32)
nonce = bytes(12)
pt = bytes(16)
ct, tag = rust_model_aes256_gcm(key, nonce, b"", pt, True)
expected_ct = bytes.fromhex("cea7403d4d606b6e074ec5d3baf39d18")
expected_tag = bytes.fromhex("d0d1c8a799996bf0265b98b5d48ab919")
if ct != expected_ct:
diffs.append({"case": "nist_tc14_ct", "expected": expected_ct.hex(), "got": ct.hex()})
if tag != expected_tag:
diffs.append({"case": "nist_tc14_tag", "expected": expected_tag.hex(), "got": tag.hex()})
dec, dec_tag = rust_model_aes256_gcm(key, nonce, b"", ct, False)
if dec != pt or dec_tag != expected_tag:
diffs.append({"case": "nist_tc14_decrypt", "pt_ok": dec == pt, "tag_ok": dec_tag == expected_tag})
return [{"name": "csl_aes256_gcm_nist_offline", "passed": not diffs, "diffs": diffs}]
def run_checks() -> list[dict]:
from rmapi_binary_emulator import Emulator
emu = Emulator()
install_standard_externals(emu)
return [
@ -592,8 +618,19 @@ def run_checks() -> list[dict]:
]
def main() -> int:
results = run_checks()
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
ap = argparse.ArgumentParser(description="Binary & reference oracle for Enterprise Subsystems.")
ap.add_argument(
"--check-offline",
action="store_true",
help="Run pure-Python AES-256-GCM reference self-checks without Unicorn",
)
return ap.parse_args(argv)
def main(argv: list[str] | None = None) -> int:
args = parse_args(argv)
results = run_offline_checks() if args.check_offline else run_checks()
passed = sum(1 for r in results if r["passed"])
total = len(results)
print(json.dumps({"passed": passed == total, "passed_count": passed, "total": total, "results": results}, indent=2))

View File

@ -13,15 +13,19 @@ Exports `run_checks()` returning a list of `{"name": str, "passed": bool, "diffs
"""
from __future__ import annotations
import argparse
import json
import struct
import sys
from pathlib import Path
from typing import TYPE_CHECKING
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tools"))
if str(ROOT / "tools") not in sys.path:
sys.path.insert(0, str(ROOT / "tools"))
from rmapi_binary_emulator import Emulator # noqa: E402
if TYPE_CHECKING:
from rmapi_binary_emulator import Emulator
_HOOK_DISPATCH: dict[str, object] = {}
@ -658,6 +662,8 @@ def check_grid_timer_intentionally_unlocked_nv033873rm(emu: Emulator) -> dict:
def run_checks() -> list[dict]:
from rmapi_binary_emulator import Emulator
_HOOK_DISPATCH.clear()
emu = Emulator()
install_base_externals(emu)
@ -674,7 +680,13 @@ def run_checks() -> list[dict]:
]
def main() -> int:
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
ap = argparse.ArgumentParser(description="Binary oracle for NVSwitch/Fabric/IMEX and SR-IOV/vGPU.")
return ap.parse_args(argv)
def main(argv: list[str] | None = None) -> int:
parse_args(argv)
results = run_checks()
passed = sum(1 for r in results if r["passed"])
total = len(results)

View File

@ -18,14 +18,19 @@ Exports `run_checks()` returning a list of:
from __future__ import annotations
import argparse
import json
import struct
import sys
from pathlib import Path
from typing import TYPE_CHECKING
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT / "tools"))
if str(ROOT / "tools") not in sys.path:
sys.path.insert(0, str(ROOT / "tools"))
from rmapi_binary_emulator import Emulator # noqa: E402
if TYPE_CHECKING:
from rmapi_binary_emulator import Emulator
# ---------------------------------------------------------------------------
# Constants matching nv-kernel.o_binary (580.178.04) & gsp_rpc.rs / gsp_bringup.rs
@ -652,14 +657,9 @@ def check_e2e_mig_and_pmu_loops() -> dict:
return {"name": "e2e_mig_routing_and_dynamic_pmu_loops", "passed": not diffs, "diffs": diffs}
def run_checks() -> list[dict]:
emu = Emulator()
results = [
check_unicorn_gsp_rpc_header_and_checksum(emu),
check_unicorn_maxwell_pascal_hal(emu),
check_unicorn_mig_kmigmgr(emu),
check_unicorn_pmu_controls(emu),
]
def run_offline_checks() -> list[dict]:
"""Run all 10 pure-Python Boot-to-CUDA E2E mock-hardware checks without Unicorn."""
results: list[dict] = []
for chip_name, boot0, boot42, expected_fw in GSP_CHIPS:
results.append(check_gsp_chip_boot_to_cuda(chip_name, boot0, boot42, expected_fw))
results.extend(
@ -672,15 +672,54 @@ def run_checks() -> list[dict]:
return results
def main() -> int:
results = run_checks()
def run_checks() -> list[dict]:
from rmapi_binary_emulator import Emulator
emu = Emulator()
results = [
check_unicorn_gsp_rpc_header_and_checksum(emu),
check_unicorn_maxwell_pascal_hal(emu),
check_unicorn_mig_kmigmgr(emu),
check_unicorn_pmu_controls(emu),
]
results.extend(run_offline_checks())
return results
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
ap = argparse.ArgumentParser(description="Live runtime wiring & Boot-to-CUDA oracle.")
ap.add_argument(
"--check-offline",
action="store_true",
help="Run the 10 pure-Python GSP/Maxwell/Pascal/MIG/PMU E2E checks without Unicorn",
)
ap.add_argument("--json", action="store_true", help="Print structured JSON output")
return ap.parse_args(argv)
def main(argv: list[str] | None = None) -> int:
args = parse_args(argv)
results = run_offline_checks() if args.check_offline else run_checks()
passed = sum(1 for r in results if r["passed"])
for r in results:
status = "PASS" if r["passed"] else "FAIL"
print(f"[{status}] {r['name']}")
for d in r["diffs"]:
print(f" DIFF: {d}")
print(f"\nSummary: {passed}/{len(results)} checks passed, {sum(len(r['diffs']) for r in results)} diffs.")
if args.json:
print(
json.dumps(
{
"passed": passed == len(results),
"passed_count": passed,
"total": len(results),
"results": results,
},
indent=2,
)
)
else:
for r in results:
status = "PASS" if r["passed"] else "FAIL"
print(f"[{status}] {r['name']}")
for d in r["diffs"]:
print(f" DIFF: {d}")
print(f"\nSummary: {passed}/{len(results)} checks passed, {sum(len(r['diffs']) for r in results)} diffs.")
return 0 if passed == len(results) else 1

View File

@ -8,15 +8,19 @@ Exports `run_checks()` returning a list of:
from __future__ import annotations
import argparse
import json
import struct
import sys
from pathlib import Path
from typing import TYPE_CHECKING
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT / "tools"))
if str(ROOT / "tools") not in sys.path:
sys.path.insert(0, str(ROOT / "tools"))
from rmapi_binary_emulator import Emulator # noqa: E402
if TYPE_CHECKING:
from rmapi_binary_emulator import Emulator
# ---------------------------------------------------------------------------
@ -484,7 +488,24 @@ def check_boot_id_and_tegra_gsp_capability(emu: Emulator) -> dict:
return {"name": "boot_id_and_tegra_gsp_capability_nv030823rm_nv031458rm", "passed": not diffs, "diffs": diffs}
def run_offline_checks() -> list[dict]:
"""Run pure-Python InfoROM/VBIOS/boot-ID reference self-checks without Unicorn."""
diffs: list[str] = []
if rust_inforom_packed_object_size(b"3s2bwdq") != 3 + 2 + 2 + 4 + 8:
diffs.append("rust_inforom_packed_object_size mismatch")
if rust_inforom_packed_object_size(b"3n") != 0:
diffs.append("odd nibble count must return 0")
ok, unpacked = rust_inforom_unpack_object(b"2bw", bytes([0x11, 0x22, 0x34, 0x12]))
if not ok or len(unpacked) != 12:
diffs.append(f"rust_inforom_unpack_object unexpected result: ok={ok} len={len(unpacked)}")
if rust_inforom_first_nonzero_parity([0, 0, 0x07]) != 1:
diffs.append("rust_inforom_first_nonzero_parity mismatch")
return [{"name": "vbios_inforom_tegra_reference_offline", "passed": not diffs, "diffs": diffs}]
def run_checks() -> list[dict]:
from rmapi_binary_emulator import Emulator
emu = Emulator()
# Stub _nv047869rm / _nv046744rm / _nv046745rm (RM logging/asserts) and _nv028876rm (memcpy)
for noop in ("_nv047869rm", "_nv046744rm", "_nv046745rm"):
@ -512,16 +533,31 @@ def run_checks() -> list[dict]:
return checks
def main() -> int:
results = run_checks()
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
ap = argparse.ArgumentParser(description="Binary & reference oracle for InfoROM, VBIOS, and Tegra SoC.")
ap.add_argument(
"--check-offline",
action="store_true",
help="Run pure-Python InfoROM/VBIOS reference self-checks without Unicorn",
)
ap.add_argument("--json", action="store_true", help="Print structured JSON output only")
return ap.parse_args(argv)
def main(argv: list[str] | None = None) -> int:
args = parse_args(argv)
results = run_offline_checks() if args.check_offline else run_checks()
passed = sum(1 for r in results if r["passed"])
total = len(results)
for r in results:
status = "PASS" if r["passed"] else "FAIL"
print(f"[{status}] {r['name']}")
for d in r["diffs"]:
print(f" DIFF: {d}")
print(json.dumps({"passed": passed, "total": total, "all_passed": passed == total}))
if args.json:
print(json.dumps({"passed": passed, "total": total, "all_passed": passed == total, "results": results}, indent=2))
else:
for r in results:
status = "PASS" if r["passed"] else "FAIL"
print(f"[{status}] {r['name']}")
for d in r["diffs"]:
print(f" DIFF: {d}")
print(json.dumps({"passed": passed, "total": total, "all_passed": passed == total}))
return 0 if passed == total else 1