Files
nvdriver/tests/offline/test_summarize_dispatch_partial.py
2026-12-01 12:24:03 -05:00

71 lines
3.0 KiB
Python

"""Validate phase evidence from synthetic saved dispatch rows."""
import json
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
SCRIPT = Path(__file__).resolve().parents[2] / "tools" / "summarize_original_dispatch.py"
class PartialDispatchTests(unittest.TestCase):
def summarize(self, stages):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
registers, symbols, sites, report = [
root / name for name in ("registers", "symbols", "sites", "report")
]
symbols.write_text("00000008 t callback\n")
sites.write_text(json.dumps({"sites": [
{"runtime_ip": hex(i), "stage": stage}
for i, (stage, _) in enumerate(stages, 1)
]}))
registers.write_text("".join(
f"fixture 4/5 1.00000000{i}: mem:{hex(i)}:x: {i:x} ABI:2 "
f"AX:0x8 DI:0x2 SI:{hex(engine)} DX:0x0\n"
for i, (_, engine) in enumerate(stages, 1)
))
run = subprocess.run([
sys.executable, str(SCRIPT), str(registers), "--kallsyms",
str(symbols), "--sites", str(sites), "--output", str(report),
], capture_output=True, text=True)
self.assertEqual(run.returncode, 0, run.stderr)
return json.loads(report.read_text())
def test_missing_comparison_stages_do_not_discard_observed_samples(self):
report = self.summarize([("InitUnlocked", 8)])
self.assertEqual(report["samples"], 1)
checks = report["gpu_groups"][0]
self.assertIsNone(checks["same_engine_set_across_locked_preload_load"])
self.assertIsNone(checks["all_preload_before_load"])
self.assertIsNone(checks["unlocked_before_matching_locked"])
def test_unmatched_engine_makes_its_order_unknown(self):
report = self.summarize([
("InitUnlocked", 8), ("InitUnlocked", 9), ("InitLocked", 8),
("PreLoad", 8), ("Load", 8),
])
checks = report["gpu_groups"][0]
self.assertTrue(checks["same_engine_set_across_locked_preload_load"])
self.assertTrue(checks["all_preload_before_load"])
self.assertIsNone(checks["unlocked_before_matching_locked"])
def test_complete_trace_without_optional_unlocked_stage_still_passes(self):
report = self.summarize([("InitLocked", 8), ("PreLoad", 8), ("Load", 8)])
checks = report["gpu_groups"][0]
self.assertTrue(checks["unlocked_before_matching_locked"])
def test_complete_trace_keeps_positive_order_checks(self):
report = self.summarize([
("InitUnlocked", 8), ("InitLocked", 8), ("PreLoad", 8), ("Load", 8),
])
checks = report["gpu_groups"][0]
self.assertTrue(checks["same_engine_set_across_locked_preload_load"])
self.assertTrue(checks["all_preload_before_load"])
self.assertTrue(checks["unlocked_before_matching_locked"])
if __name__ == "__main__":
unittest.main()