mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 22:48:43 +00:00
78 lines
2.6 KiB
Python
78 lines
2.6 KiB
Python
"""Simulate validate_all commands to inspect guest prerequisites without hardware."""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
SCRIPT = Path(__file__).resolve().parents[2] / "tools/validate_all.sh"
|
|
|
|
STUBS = r"""
|
|
cargo() { return 0; }
|
|
make() { return 0; }
|
|
sh() {
|
|
case "$1" in
|
|
tools/vm/build_guest_test.sh) [ "$FAILED_STEP" != guest_build ] ;;
|
|
tools/vm/build_initramfs.sh) [ "$FAILED_STEP" != initramfs ] ;;
|
|
*) return 0 ;;
|
|
esac
|
|
}
|
|
bash() { return 0; }
|
|
python3() {
|
|
case "$*" in
|
|
tools/vm/run_guest.py) [ "$FAILED_STEP" != guest ] ;;
|
|
*) return 0 ;;
|
|
esac
|
|
}
|
|
sudo() { return 0; }
|
|
modinfo() { return 0; }
|
|
sha256sum() { return 0; }
|
|
"""
|
|
|
|
|
|
class GuestStepTests(unittest.TestCase):
|
|
def simulate(self, failed_step):
|
|
work = tempfile.TemporaryDirectory()
|
|
self.addCleanup(work.cleanup)
|
|
root = Path(work.name)
|
|
script = root / "tools/validate_all.sh"
|
|
script.parent.mkdir()
|
|
shutil.copyfile(SCRIPT, script)
|
|
functions = root / "simulated_commands.sh"
|
|
functions.write_text(STUBS, encoding="utf-8")
|
|
env = dict(os.environ, BASH_ENV="", FAILED_STEP=failed_step)
|
|
run = subprocess.run(
|
|
["/bin/bash", "-c", 'source "$1" && declare -F sudo sh python3 >/dev/null && source "$0"',
|
|
str(script), str(functions)],
|
|
env=env, capture_output=True, text=True,
|
|
)
|
|
return run, root
|
|
|
|
def test_failed_guest_build_skips_archive_and_both_guests(self):
|
|
result, root = self.simulate("guest_build")
|
|
self.assertEqual(result.returncode, 1)
|
|
self.assertIn("FAIL guest_build ", result.stdout)
|
|
for step in ("initramfs", "guest", "guest_iommu"):
|
|
self.assertIn(f"SKIP {step} (guest build failed)", result.stdout)
|
|
self.assertEqual((root / f"target/validate-logs/{step}.log").read_text(), "guest build failed\n")
|
|
|
|
def test_failed_archive_skips_both_guests(self):
|
|
result, _ = self.simulate("initramfs")
|
|
self.assertEqual(result.returncode, 1)
|
|
self.assertIn("PASS guest_build\n", result.stdout)
|
|
self.assertIn("FAIL initramfs ", result.stdout)
|
|
self.assertIn("SKIP guest (initramfs build failed)", result.stdout)
|
|
self.assertIn("SKIP guest_iommu (initramfs build failed)", result.stdout)
|
|
|
|
def test_direct_guest_failure_does_not_suppress_iommu_result(self):
|
|
result, _ = self.simulate("guest")
|
|
self.assertEqual(result.returncode, 1)
|
|
self.assertIn("FAIL guest ", result.stdout)
|
|
self.assertIn("PASS guest_iommu\n", result.stdout)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|