Support NV_RS_ANALYSIS_ROOT/extracted/kernel discovery and add self-contained offline success test

- Check /extracted/kernel/<relpath> ahead of sources/nvidia-580.178.04
  in discover_hwref_header().
- Add test_offline_success_with_analysis_root_and_blocked_unicorn using valid synthetic
  gm107/gp100 dev_mmu.h fixtures while blocking unicorn imports.
This commit is contained in:
morebrackets
2026-12-02 16:27:21 -08:00
parent 02c558d073
commit 5542a29bd8
2 changed files with 35 additions and 1 deletions

View File

@ -94,6 +94,38 @@ class OracleMaxwellPascalTests(unittest.TestCase):
self.assertTrue(any("NV_MMU_PDE_APERTURE_BIG" in d for d in gm_diffs))
self.assertTrue(any("NV_MMU_VER2_PDE_IS_PDE" in d for d in gp_diffs))
def test_offline_success_with_analysis_root_and_blocked_unicorn(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
td = pathlib.Path(tmp)
kernel_root = td / "analysis" / "extracted/kernel"
gm107 = kernel_root / omp.GM107_DEV_MMU_REL
gp100 = kernel_root / omp.GP100_DEV_MMU_REL
gm107.parent.mkdir(parents=True)
gp100.parent.mkdir(parents=True)
gm107.write_text(
"".join(f"#define {m} {bits} /* RWXVF */\n" for m, bits in omp.GM107_EXPECTED_DEFS.items())
)
gp100.write_text(
"".join(f"#define {m} {bits} /* RWXVF */\n" for m, bits in omp.GP100_EXPECTED_DEFS)
)
# Shadow unicorn with an ImportError stub so this also proves --check-offline is unicorn-free.
blocker = td / "block_unicorn"
blocker.mkdir()
(blocker / "unicorn.py").write_text('raise ImportError("unicorn intentionally blocked")\n')
env = {k: v for k, v in os.environ.items() if k != "NV_RS_KERNEL_SRC"}
env["NV_RS_ANALYSIS_ROOT"] = str(td / "analysis")
env["PYTHONPATH"] = f"{blocker}{os.pathsep}{env.get('PYTHONPATH', '')}".rstrip(os.pathsep)
proc = subprocess.run(
[sys.executable, "-O", str(SCRIPT), "--check-offline", "--require-hwref", "--json"],
capture_output=True,
text=True,
env=env,
)
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
payload = json.loads(proc.stdout)
self.assertTrue(payload["passed"], payload)
self.assertEqual(payload["passed_count"], 2)
def test_live_shipped_headers_when_present(self) -> None:
hdr_gm, _ = omp.discover_hwref_header(omp.GM107_DEV_MMU_REL)
hdr_gp, _ = omp.discover_hwref_header(omp.GP100_DEV_MMU_REL)

View File

@ -89,7 +89,9 @@ def discover_hwref_header(relpath: str, kernel_src: str | Path | None = None) ->
candidates: list[Path] = []
analysis_root = os.environ.get("NV_RS_ANALYSIS_ROOT")
if analysis_root:
candidates.append(Path(analysis_root).expanduser() / "sources/nvidia-580.178.04" / relpath)
ar = Path(analysis_root).expanduser()
candidates.append(ar / "extracted/kernel" / relpath)
candidates.append(ar / "sources/nvidia-580.178.04" / relpath)
candidates.extend(
(
Path("/usr/src/nvidia-580.178.04") / relpath,