mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
99 lines
4.0 KiB
Python
99 lines
4.0 KiB
Python
"""Validate copied synthetic artifacts with the original labels provenance."""
|
|
from hashlib import sha256
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
SCRIPT = Path(__file__).resolve().parents[2] / "tools" / "check_original_live_init.py"
|
|
EVIDENCE_IDS = (
|
|
"ev_b1b9a9279aa151b6f51c93b6bee10b9949d4c6e0f4afcc14d61579d213210443",
|
|
"ev_1b2d3b2a0781ff192ac6f67dc3e065dafe95bcb8960d5a122583f4e3cbff8e46",
|
|
)
|
|
RECORDED_NAME = "reports/original-live-init-bp-4/timestamped-dispatch.json"
|
|
|
|
|
|
class RelocatedLiveLabelsTests(unittest.TestCase):
|
|
def setUp(self):
|
|
directory = tempfile.TemporaryDirectory()
|
|
self.addCleanup(directory.cleanup)
|
|
self.root = Path(directory.name) / "copied-capture"
|
|
self.root.mkdir()
|
|
checks = {
|
|
"timestamp_ordered": True,
|
|
"same_engine_set_across_locked_preload_load": True,
|
|
"all_preload_before_load": True,
|
|
"unlocked_before_matching_locked": True,
|
|
}
|
|
event = {
|
|
"gpu_ordinal": 0, "gpu_owner": "synthetic-gpu",
|
|
"engine_ordinal": 0, "engine_owner": "synthetic-engine",
|
|
"stage": "Load", "callback_address": "0x1",
|
|
"callback": {"name": "placeholder", "offset": 0}, "load_flags": 0,
|
|
}
|
|
capture = {
|
|
"samples": 2056, "gpu_count": 8, "rejected": [],
|
|
"all_gpu_sequences_identical": True, "gpu_groups": [checks] * 8,
|
|
"events": [event] * 2056,
|
|
}
|
|
capture_text = json.dumps(capture)
|
|
(self.root / "timestamped-dispatch.json").write_text(capture_text)
|
|
(self.root / "standalone-dispatch.json").write_text(capture_text)
|
|
(self.root / "timestamped-record-dump.txt").touch()
|
|
(self.root / "final-rea-evidence-bundle.json").write_text(json.dumps({
|
|
"records": [{
|
|
"evidence_id": key,
|
|
"normalized_result": {
|
|
"exit": {"code": 0},
|
|
"frames": [{"data": '{"passed":true,"verified_words":64,"context_destroyed":true}'}],
|
|
},
|
|
} for key in EVIDENCE_IDS],
|
|
}))
|
|
self.recorded_hash = sha256(capture_text.encode()).hexdigest()
|
|
self.engines = [{
|
|
"engine_ordinal0": 0, "engine_owner": "synthetic-engine", "gpu_owner": "synthetic-gpu",
|
|
"callbacks": {"Load": {
|
|
"sample": 0, "symbol": "placeholder", "callback_address": "0x1",
|
|
}},
|
|
}]
|
|
|
|
def validate(self, inputs):
|
|
labels = self.root / "labels.json"
|
|
labels.write_text(json.dumps({"inputs": inputs, "engines": self.engines}))
|
|
result = subprocess.run(
|
|
[sys.executable, str(SCRIPT), str(self.root), "--labels", str(labels)],
|
|
capture_output=True, text=True,
|
|
)
|
|
validation = self.root / "validation.json"
|
|
self.assertTrue(validation.exists(), result.stderr)
|
|
return result.returncode, json.loads(validation.read_text())
|
|
|
|
def test_copied_capture_verifies_recorded_hash(self):
|
|
status, report = self.validate({RECORDED_NAME: self.recorded_hash})
|
|
self.assertEqual(status, 0)
|
|
self.assertTrue(report["passed"])
|
|
self.assertTrue(report["checks"]["label_input_hash_matches"])
|
|
|
|
def test_different_content_fails_hash_check(self):
|
|
path = self.root / "timestamped-dispatch.json"
|
|
path.write_text(path.read_text() + "\n")
|
|
status, report = self.validate({RECORDED_NAME: self.recorded_hash})
|
|
self.assertEqual(status, 1)
|
|
self.assertFalse(report["checks"]["label_input_hash_matches"])
|
|
|
|
def test_absent_or_ambiguous_provenance_fails_hash_check(self):
|
|
for inputs in ({}, {
|
|
RECORDED_NAME: self.recorded_hash,
|
|
"different/timestamped-dispatch.json": self.recorded_hash,
|
|
}):
|
|
with self.subTest(inputs=inputs):
|
|
status, report = self.validate(inputs)
|
|
self.assertEqual(status, 1)
|
|
self.assertFalse(report["checks"]["label_input_hash_matches"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|