Files
nvdriver/tests/offline/test_init_api_outcome.py
2026-12-01 12:25:31 -05:00

54 lines
2.0 KiB
Python

"""Summarize synthetic saved API events without a live capture."""
import json
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
SCRIPT = Path(__file__).resolve().parents[2] / "tools" / "summarize_original_live_init.py"
ENTER = {"kind": "cuda_enter", "tid": 1, "name": "cuInit"}
LEAVE = {"kind": "cuda_leave", "tid": 1, "name": "cuInit", "result": 0}
class InitApiOutcomeTests(unittest.TestCase):
def outcome(self, events, *, truncated=False):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
messages = [{"payload": event} for event in events]
(root / "rea-evidence-bundle.json").write_text(json.dumps({
"records": [{
"operation": "frida_session_status",
"evidence_id": "synthetic-evidence",
"normalized_result": {
"messages": messages,
"messages_truncated": truncated,
},
}],
}))
(root / "overflow-aware-init-calls.txt").touch()
result = subprocess.run(
[sys.executable, str(SCRIPT), str(root)], capture_output=True, text=True,
)
self.assertEqual(result.returncode, 0, result.stderr)
return json.loads((root / "live-initialization-timeline.json").read_text())["api_success"]
def test_unknown_without_completed_calls(self):
self.assertIsNone(self.outcome([ENTER]))
def test_unknown_with_a_truncated_capture(self):
self.assertIsNone(self.outcome([ENTER, LEAVE], truncated=True))
def test_unknown_when_a_return_cannot_be_paired(self):
self.assertIsNone(self.outcome([ENTER, {**LEAVE, "tid": 2}]))
def test_observed_failure_survives_incomplete_capture(self):
self.assertIs(self.outcome([ENTER, {**LEAVE, "result": 7}], truncated=True), False)
def test_complete_success(self):
self.assertIs(self.outcome([ENTER, LEAVE]), True)
if __name__ == "__main__":
unittest.main()