Files
nvdriver/tests/offline/test_host_fixtures_and_arch_codegen_scripts.py

56 lines
2.1 KiB
Python

import os
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
class TestHostFixturesAndArchCodegenScripts(unittest.TestCase):
def test_shell_syntax(self):
for rel in (
"src/nvidia/kernel/run-host-fixtures.sh",
"tools/test_gpu_arch_codegen.sh",
):
proc = subprocess.run(["sh", "-n", str(ROOT / rel)], capture_output=True, text=True)
self.assertEqual(proc.returncode, 0, f"{rel}: {proc.stderr}")
def test_missing_rustc_fails_loudly_instead_of_false_green(self):
with tempfile.TemporaryDirectory() as empty_home:
# Build an isolated PATH with only the basic non-rustc POSIX utilities
# needed by the script prologues so a system /usr/bin/rustc cannot leak in.
bin_dir = Path(empty_home) / "bin"
bin_dir.mkdir()
for tool in ("sh", "dirname", "mkdir", "pwd"):
resolved = shutil.which(tool)
if resolved:
os.symlink(resolved, bin_dir / tool)
sh_bin = str(bin_dir / "sh") if (bin_dir / "sh").exists() else "/bin/sh"
env = {
"PATH": str(bin_dir),
"HOME": empty_home,
"CARGO_HOME": str(Path(empty_home) / "no-cargo"),
}
for rel in (
"src/nvidia/kernel/run-host-fixtures.sh",
"tools/test_gpu_arch_codegen.sh",
):
proc = subprocess.run(
[sh_bin, str(ROOT / rel)],
env=env,
capture_output=True,
text=True,
)
self.assertNotEqual(proc.returncode, 0, f"{rel} unexpectedly succeeded without rustc")
self.assertIn("rustc not found", proc.stderr)
def test_no_stray_rustc_long_type_diagnostic_file(self):
stray = list((ROOT / "kernel-open").rglob("*.long-type-*.txt"))
self.assertEqual(stray, [], f"Stray rustc long-type diagnostic files: {stray}")
if __name__ == "__main__":
unittest.main()