mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
86 lines
5.8 KiB
Python
86 lines
5.8 KiB
Python
"""Mutate real saved observations to check that incomplete runs fail closed."""
|
|
import copy
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT / "tools/vm"))
|
|
from guest_results import validate_guest_results
|
|
|
|
|
|
class ResultGate(unittest.TestCase):
|
|
def test_incomplete_and_differently_typed_json_records_are_rejected(self):
|
|
report = json.loads((ROOT / "reports/vm-adapter-validation.json").read_text())
|
|
serial = (ROOT / "reports/vm-adapter-serial.log").read_text()
|
|
results = report["guest_results"]
|
|
|
|
with self.subTest(row=None):
|
|
self.assertTrue(validate_guest_results([None, results[1]], serial, False))
|
|
|
|
for field, value in (
|
|
("irq_mode", 2.0),
|
|
("checks", 144.0),
|
|
("thread_state_checks", 12.0),
|
|
("rom_fw_removed", True),
|
|
("rom_fw_uc_pages", 133.0),
|
|
("rom_fw_wb_retries", True),
|
|
("dma_roundtrip_bytes", 64.0),
|
|
):
|
|
with self.subTest(field=field, value=value):
|
|
modified = copy.deepcopy(results)
|
|
modified[0][field] = value
|
|
self.assertTrue(validate_guest_results(modified, serial, False))
|
|
|
|
with self.subTest(rmapi="integer reported as a boolean"):
|
|
modified_serial = serial.replace('"gpus":1', '"gpus":true', 1)
|
|
self.assertNotEqual(modified_serial, serial)
|
|
self.assertTrue(validate_guest_results(results, modified_serial, False))
|
|
|
|
def test_recorded_runs_and_tampered_evidence(self):
|
|
for iommu, suffix in ((False, ""), (True, "-iommu")):
|
|
report = json.loads((ROOT / f"reports/vm-adapter{suffix}-validation.json").read_text())
|
|
serial = (ROOT / f"reports/vm-adapter{suffix}-serial.log").read_text()
|
|
results = report["guest_results"]
|
|
with self.subTest(iommu=iommu, mutation="unchanged"):
|
|
self.assertEqual(validate_guest_results(results, serial, iommu), [])
|
|
for field, value in (("checks", 143), ("checks", 145), ("rust_backing_checks", 34),
|
|
("native_memory_checks", 0), ("native_memory_checks", None), ("native_memory_checks", 23), ("native_memory_checks", 25), ("native_memory_checks", 24.0),
|
|
("gpu_cleanup_retries", 0), ("gpu_cleanup_retries", None),
|
|
("gpu_register_checks", 0), ("gpu_register_checks", None),
|
|
("gpu_operation_checks", 0), ("gpu_operation_checks", None),
|
|
("dma_poll_reads", 0), ("dma_poll_reads", None),
|
|
("device_software_checks", 0), ("device_software_checks", None), ("device_software_checks", 15), ("device_software_checks", 17), ("device_software_checks", 16.0),
|
|
("host_os_checks", 0), ("host_os_checks", None), ("host_os_checks", 8),
|
|
("fault_word_checks", 0), ("fault_word_checks", None), ("fault_word_checks", 44), ("fault_word_checks", 46), ("fault_word_checks", 45.0), ("fault_word_checks", True), ("fault_word_checks", "45"),
|
|
("rom_cpu_checks", 0), ("rom_cpu_checks", None), ("rom_cpu_checks", 4), ("rom_cpu_checks", 6), ("rom_cpu_checks", 5.0),
|
|
("gpu_registry_cleanup_retries", 0), ("gpu_registry_cleanup_retries", None), ("gpu_registry_cleanup_retries", 1.0),
|
|
("gpu_registry_checks", 0), ("gpu_registry_checks", None), ("gpu_registry_checks", 15), ("gpu_registry_checks", 17), ("gpu_registry_checks", 16.0),
|
|
("os_event_checks", 0), ("os_event_checks", None), ("os_event_checks", 31), ("os_event_checks", 33), ("os_event_checks", 32.0), ("os_event_checks", True), ("nano_timer_checks", 0), ("nano_timer_checks", None), ("nano_timer_checks", 28), ("nano_timer_checks", 30), ("nano_timer_checks", 29.0),
|
|
("thread_state_checks", 0), ("thread_state_checks", None), ("thread_state_checks", 11),
|
|
("host_irq_checks", 0), ("host_irq_checks", None),
|
|
("rom_fw_checks", 946), ("rom_fw_checks", 948), ("rom_fw_checks", 0), ("rom_fw_checks", None), ("rom_fw_uc_pages", 0), ("rom_fw_uc_pages", None),
|
|
("rom_fw_removed", 0), ("rom_fw_removed", None), ("rom_fw_cached_pages", 0), ("rom_fw_wb_pages", 0),
|
|
("rom_fw_wb_retries", 0), ("rom_fw_dma_bytes", 0),
|
|
("iommu_dma_domain", not iommu), ("gpu_parity", True),
|
|
("dma_roundtrip_bytes", 0), ("irq_mode", 99)):
|
|
modified = copy.deepcopy(results)
|
|
modified[0][field] = value
|
|
with self.subTest(iommu=iommu, mutation=(field, value)):
|
|
self.assertTrue(validate_guest_results(modified, serial, iommu))
|
|
for modified_serial in (serial.replace("NV_RS_VM_CLEAN_UNLOAD_4", "missing"),
|
|
serial + "\nNV_RS_VM_FAIL injected\n",
|
|
serial + "\nrefcount_t: underflow\n",
|
|
serial + "\nBUG: scheduling while atomic\n",
|
|
serial + "\nuse-after-free\n",
|
|
serial.replace("NV_RS_VM_RMAPI_PASS", "missing", 1),
|
|
serial.replace('NV_RS_VM_RMAPI_PASS {"checks":457', 'NV_RS_VM_RMAPI_PASS {"checks":456', 1),
|
|
serial + "\nNV_RS_VM_RMAPI_FAIL line 1 errno 0\n"):
|
|
self.assertTrue(validate_guest_results(results, modified_serial, iommu))
|
|
self.assertTrue(validate_guest_results(results[:1], serial, iommu))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|