mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
MK = ROOT / "tests/software-manager/codegen.mk"
|
|
|
|
|
|
class TestSoftwareManagerCodegenMk(unittest.TestCase):
|
|
def test_missing_rustc_fails_loudly_instead_of_false_green(self):
|
|
with tempfile.TemporaryDirectory() as empty_home:
|
|
env = {
|
|
"PATH": "/usr/local/bin:/usr/bin:/bin",
|
|
"HOME": empty_home,
|
|
"CARGO_HOME": str(Path(empty_home) / "no-cargo"),
|
|
}
|
|
proc = subprocess.run(
|
|
[
|
|
"make",
|
|
"-f",
|
|
str(MK),
|
|
"RUSTC=",
|
|
f"RUST_BUILD_PRODUCT_RECEIPT={Path(empty_home) / 'build-product' / 'config.json'}",
|
|
],
|
|
cwd=empty_home,
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
self.assertNotEqual(proc.returncode, 0)
|
|
self.assertIn("rustc not found", proc.stderr)
|
|
|
|
def test_resolves_rustup_inside_repo_root_from_external_cwd(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
fake_bin = Path(tmp) / "bin"
|
|
fake_bin.mkdir()
|
|
recorded = Path(tmp) / "rustup_cwd.txt"
|
|
fake_rustup = fake_bin / "rustup"
|
|
fake_rustup.write_text(
|
|
f'#!/bin/sh\npwd > "{recorded}"\necho "{fake_bin}/fake-rustc"\n'
|
|
)
|
|
fake_rustup.chmod(0o755)
|
|
env = {
|
|
"PATH": f"{fake_bin}:/usr/local/bin:/usr/bin:/bin",
|
|
"HOME": tmp,
|
|
"CARGO_HOME": tmp,
|
|
}
|
|
proc = subprocess.run(
|
|
[
|
|
"make",
|
|
"-n",
|
|
"-f",
|
|
str(MK),
|
|
f"RUST_BUILD_PRODUCT_RECEIPT={Path(tmp) / 'build-product' / 'config.json'}",
|
|
],
|
|
cwd=tmp,
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
self.assertEqual(proc.returncode, 0, proc.stderr)
|
|
self.assertEqual(Path(recorded.read_text().strip()).resolve(), ROOT.resolve())
|
|
self.assertIn(f'"{fake_bin}/fake-rustc"', proc.stdout)
|
|
|
|
def test_uses_toolchain_vars_and_quotes_rustc(self):
|
|
text = MK.read_text()
|
|
self.assertIn('"$(RUSTC)"', text)
|
|
self.assertIn("$(LD) -r", text)
|
|
self.assertIn("$(OBJCOPY) --remove-section", text)
|
|
self.assertIn("rm -f $(TASK_OUT)/libnv_rs_abi.rlib", text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|