okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-141-fixb: Python, docs and bench fixes and portsef8071303

main
1.1 KiB36 linesraw
1"""#1445: setup warns when nvidia-smi reports a compute mode other than Default (never refuses).
2
3    python -m unittest tools.test_setup_compute_mode
4"""
5from __future__ import annotations
6
7import sys
8import unittest
9from pathlib import Path
10from unittest import mock
11
12ROOT = Path(__file__).resolve().parents[1]
13sys.path.insert(0, str(ROOT))
14import setup  # noqa: E402
15
16
17class Mode(unittest.TestCase):
18    def test_default_is_silent(self):
19        for m in ("Default", "default", "", "[N/A]", "N/A"):
20            self.assertIsNone(setup.compute_mode_warning(0, m), m)
21
22    def test_other_modes_warn(self):
23        for m in ("Exclusive_Process", "Prohibited", "Exclusive_Thread"):
24            w = setup.compute_mode_warning(2, m)
25            self.assertIn(m, w)
26            self.assertIn("GPU 2", w)
27            self.assertIn("nvidia-smi -i 2 -c DEFAULT", w)
28
29    def test_query(self):
30        with mock.patch.object(setup, "out", return_value="Exclusive_Process\n") as o:
31            self.assertEqual(setup.gpu_compute_mode(1), "Exclusive_Process")
32        self.assertIn("compute_mode", " ".join(o.call_args[0][0]))
33
34
35if __name__ == "__main__":
36    unittest.main()