mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
Address Greptile review findings on #284
- tools/decode_original_pt_bounded.py (4777575187): only suppress non-zero exit status when stop is 'line_limit' or 'error_limit', so 'decoder_shutdown_timeout' exits non-zero. - tools/check_compat_layout.py (4777575220): replace hardcoded /home/geodd DEFAULT_ANALYSIS with home-relative Path.home() / 'nvidia-driver/analysis-580.178.04'. - tests/offline/test_oracle_check_and_pt_decoder_tools.py (4777575238): add negative -O-safe tests covering alarm-vector drift, mismatched i386/x86_64 layouts, and decoder shutdown timeouts.
This commit is contained in:
@ -2,8 +2,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
@ -14,7 +18,8 @@ ROOT = Path(__file__).resolve().parents[2]
|
||||
def _load(rel_path: str, module_name: str):
|
||||
path = ROOT / rel_path
|
||||
spec = importlib.util.spec_from_file_location(module_name, path)
|
||||
assert spec is not None and spec.loader is not None
|
||||
if spec is None or spec.loader is None:
|
||||
raise RuntimeError(f"cannot load module spec for {rel_path}")
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
return mod
|
||||
@ -78,6 +83,83 @@ class TestOracleCheckAndPtDecoderTools(unittest.TestCase):
|
||||
self.assertTrue(callable(vectors.main))
|
||||
self.assertTrue(callable(live_init.main))
|
||||
|
||||
def test_timer_alarm_vectors_check_detects_drift_under_O(self):
|
||||
mod = _load("tools/timer-alarm-vectors.py", "timer_alarm_vectors_drift")
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
root = Path(td)
|
||||
(root / "reports").mkdir()
|
||||
(root / "tests/timer-alarm").mkdir(parents=True)
|
||||
(root / "reports/timer-alarm-original.json").write_text(json.dumps({"cases": []}))
|
||||
(root / "tests/timer-alarm/vectors.rs").write_text("// stale\n")
|
||||
with mock.patch.object(mod, "R", root):
|
||||
with self.assertRaisesRegex(SystemExit, "Original alarm Rust vectors drift"):
|
||||
mod.main(["--check"])
|
||||
|
||||
def test_check_compat_layout_detects_mismatched_layouts_under_O(self):
|
||||
mod = _load("tools/check_compat_layout.py", "check_compat_layout_mismatch")
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
root = Path(td)
|
||||
inc0 = root / "common/inc"
|
||||
inc1 = root / "sdk/inc"
|
||||
inc0.mkdir(parents=True)
|
||||
inc1.mkdir(parents=True)
|
||||
(inc0 / "nv-ioctl.h").write_text("")
|
||||
(inc0 / "nvtypes.h").write_text("")
|
||||
(inc1 / "nvos.h").write_text("")
|
||||
(root / "tests/oracles").mkdir(parents=True)
|
||||
(root / "tests/oracles/compat-layout.c").write_text("")
|
||||
|
||||
def fake_run(cmd, check=False, **_kwargs):
|
||||
if cmd[0] == "objcopy":
|
||||
out_path = Path(cmd[2].split("=", 1)[1])
|
||||
if "layout32" in cmd[3]:
|
||||
out_path.write_bytes(struct.pack("<II", 4, 16))
|
||||
else:
|
||||
out_path.write_bytes(struct.pack("<II", 8, 24))
|
||||
return subprocess.CompletedProcess(cmd, 0)
|
||||
|
||||
with (
|
||||
mock.patch.object(mod, "R", root),
|
||||
mock.patch.object(mod, "resolve_include_dirs", return_value=[inc0, inc1]),
|
||||
mock.patch.object(mod.subprocess, "run", side_effect=fake_run),
|
||||
):
|
||||
with self.assertRaisesRegex(SystemExit, "wire layouts differ beyond pointer width"):
|
||||
mod.main()
|
||||
|
||||
def test_decode_original_pt_bounded_fails_on_decoder_shutdown_timeout(self):
|
||||
mod = _load("tools/decode_original_pt_bounded.py", "decode_pt_timeout")
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
root = Path(td)
|
||||
inp = root / "perf.data"
|
||||
syms = root / "kallsyms"
|
||||
out = root / "out.txt"
|
||||
inp.write_bytes(b"")
|
||||
syms.write_text("")
|
||||
|
||||
class FakeProc:
|
||||
def __init__(self):
|
||||
self.stdout = io.StringIO("sample line\n")
|
||||
self.waits = 0
|
||||
self.killed = False
|
||||
|
||||
def wait(self, timeout=None):
|
||||
self.waits += 1
|
||||
if self.waits == 1:
|
||||
raise subprocess.TimeoutExpired(["perf"], timeout or 10)
|
||||
return -9
|
||||
|
||||
def kill(self):
|
||||
self.killed = True
|
||||
|
||||
fake = FakeProc()
|
||||
with mock.patch.object(mod.subprocess, "Popen", return_value=fake):
|
||||
with self.assertRaises(SystemExit) as ctx:
|
||||
mod.main(["--input", str(inp), "--kallsyms", str(syms), "--output", str(out)])
|
||||
self.assertEqual(ctx.exception.code, 1)
|
||||
self.assertTrue(fake.killed)
|
||||
report = json.loads(out.with_suffix(".json").read_text())
|
||||
self.assertEqual(report["stop"], "decoder_shutdown_timeout")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@ -9,7 +9,7 @@ import subprocess
|
||||
import tempfile
|
||||
|
||||
R = Path(__file__).resolve().parent.parent
|
||||
DEFAULT_ANALYSIS = Path("/home/geodd/nvidia-driver/analysis-580.178.04")
|
||||
DEFAULT_ANALYSIS = Path.home() / "nvidia-driver/analysis-580.178.04"
|
||||
|
||||
|
||||
def resolve_include_dirs():
|
||||
|
||||
@ -107,7 +107,7 @@ def main(argv=None):
|
||||
}
|
||||
reportpath.write_text(json.dumps(report, indent=2) + "\n")
|
||||
print(json.dumps(report))
|
||||
if stop is None and status != 0:
|
||||
if stop not in ("line_limit", "error_limit") and status != 0:
|
||||
raise SystemExit(status if status > 0 else 1)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user