okami.mom/strata

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

Niko1221Merge f-022-int into f-022-gyrocuda: Pascal path kept for cc 6.0, 8-lane trellis rows for every other CUDA card01f8c3255

main
4.2 KiB83 linesraw
1"""#3469 #3437: the 0.2 releases carry no flat engine zip, so a source checkout (UPDATE.bat, setup) fetches the engine package
2for its card from the signed update feed and installs its files in engine/.
3
4    python -m unittest tools.test_setup_feed_engine
5"""
6from __future__ import annotations
7
8import json
9import sys
10import tempfile
11import types
12import unittest
13from pathlib import Path
14from unittest import mock
15
16ROOT = Path(__file__).resolve().parents[1]
17sys.path.insert(0, str(ROOT))
18sys.path.insert(0, str(ROOT / "tools"))
19import setup  # noqa: E402
20from strata_control import engine_component as ec  # noqa: E402
21
22
23class FeedEngine(unittest.TestCase):
24    def setUp(self):
25        self.tmp = tempfile.TemporaryDirectory()
26        self.addCleanup(self.tmp.cleanup)
27        self.root = Path(self.tmp.name)
28        self.eng = self.root / "engine"
29        self.eng.mkdir()
30        (self.eng / "BUILD.json").write_text(json.dumps({"version": "0.1.45", "source": "prebuilt", "archs": [89]}), encoding="utf-8")
31        (self.eng / setup.EXE).write_bytes(b"old")
32        self.package = self.root / "components" / "engine" / "0.1.46-test"
33        self.package.mkdir(parents=True)
34        (self.package / "BUILD.json").write_text(json.dumps({"version": "0.1.46", "archs": [89]}), encoding="utf-8")
35        (self.package / setup.EXE).write_bytes(b"new")
36        for name, value in (("home", lambda: self.root), ("say", lambda *a, **k: None), ("ok", lambda *a, **k: None),
37                            ("warn", lambda *a, **k: None)):
38            patch = mock.patch.object(setup, name, value)
39            patch.start()
40            self.addCleanup(patch.stop)
41        patch = mock.patch.object(setup.acquisition, "require", lambda what: None)
42        patch.start()
43        self.addCleanup(patch.stop)
44
45    def run_update(self, code=0):
46        return mock.patch.object(setup.subprocess, "run", return_value=types.SimpleNamespace(returncode=code, stdout="", stderr="no feed"))
47
48    def test_the_package_becomes_the_installed_engine(self):
49        with self.run_update() as run, mock.patch.object(ec, "resolve", return_value=types.SimpleNamespace(root=self.package)):
50            got = setup.engine_from_feed(self.eng, updating=True)
51        self.assertEqual(got, self.eng)
52        cmd = run.call_args.args[0]
53        self.assertIn("update", cmd)
54        self.assertIn("--no-control", cmd)
55        self.assertNotIn("STRATA_NO_ACQUIRE", run.call_args.kwargs["env"])        # this one step may fetch
56        self.assertEqual((self.eng / setup.EXE).read_bytes(), b"new")
57        meta = json.loads((self.eng / "BUILD.json").read_text(encoding="utf-8"))
58        self.assertEqual((meta["version"], meta["source"]), ("0.1.46", "prebuilt"))
59        self.assertEqual((self.eng / ".previous" / setup.EXE).read_bytes(), b"old")      # one generation to roll back to
60
61    def test_no_feed_keeps_the_installed_engine(self):
62        with self.run_update(code=6):
63            self.assertIsNone(setup.engine_from_feed(self.eng, updating=True))
64        self.assertEqual((self.eng / setup.EXE).read_bytes(), b"old")
65
66    def test_a_release_without_the_zip_falls_back_to_the_feed(self):
67        gpu = {"arch": 89, "archs": [89], "vram_gb": 8.0, "index": 0}
68        (self.eng / "BUILD.json").write_text(json.dumps({"version": "0.1.45", "source": "prebuilt", "archs": [89]}), encoding="utf-8")
69        with mock.patch.object(setup, "engine_dir", lambda toolkit=13: self.eng),                 mock.patch.object(setup, "_urlopen", side_effect=OSError("HTTP Error 404")),                 mock.patch.object(setup, "engine_from_feed", return_value=self.eng) as feed:
70            got = setup.get_prebuilt(setup.PREBUILT_URL, gpu, "none", updating=True)
71            self.assertEqual(got, self.eng)
72            feed.assert_called_once()
73            feed.reset_mock()
74            setup.get_prebuilt(setup.PREBUILT_URL, gpu, "none", updating=True, toolkit=12)
75            feed.assert_not_called()                      # the experimental CUDA 12 engine has no feed package here
76
77    def test_the_minimum_is_the_0_2_engine(self):
78        self.assertLess((0, 1, 45), setup.MIN_ENGINE)
79        self.assertGreaterEqual((0, 1, 46), setup.WIN_HIP_MIN_ENGINE)
80
81
82if __name__ == "__main__":
83    unittest.main()