okami.mom/strata

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

Niko1221Merge f-023-int into f-023-guifcb0c2d0e

main
4.2 KiB94 linesraw
1"""I1 / I2 (tools and images review, 2026-10-22): the picture reader in an engine package must run on every card and Mac the package does.
2
3#3669: the Windows cuda12 package reused a strata-vision.exe built before Pascal support; the engine ran on a P100 and the reader stopped
4with "device kernel image is invalid". #3697: a macOS package with no reader at all. These tests need no GPU and no toolkit."""
5
6import json
7import sys
8import tempfile
9import unittest
10from pathlib import Path
11
12ROOT = Path(__file__).resolve().parents[2]
13sys.path.insert(0, str(ROOT / "packaging"))
14import package_engine  # noqa: E402
15
16CUDA12 = ("sm_60", "sm_61", "sm_70", "sm_75", "sm_80", "sm_86", "sm_89", "compute_89")
17CUDA13 = ("sm_75", "sm_86", "sm_89", "sm_120", "compute_120")
18
19
20class ReaderCheck(unittest.TestCase):
21    def setUp(self):
22        self.tmp = tempfile.TemporaryDirectory()
23        self.addCleanup(self.tmp.cleanup)
24        self.src = Path(self.tmp.name)
25        (self.src / "strata").write_text("x")
26
27    def reader(self, vision_archs=None):
28        (self.src / "strata-vision").write_text("x")
29        data = {"version": "0.2.3"}
30        if vision_archs is not None:
31            data["vision_archs"] = vision_archs
32        (self.src / "BUILD.json").write_text(json.dumps(data))
33
34    def check(self, backend, target, archs, **kw):
35        return package_engine.check_picture_reader(self.src, backend, target, archs, **kw)
36
37    def test_a_reader_with_no_recorded_archs_is_refused_for_cuda12(self):
38        self.reader()
39        with self.assertRaises(SystemExit) as cm:
40            self.check("cuda", "windows-x86_64", CUDA12, variant="cuda12")
41        self.assertIn("vision_archs", str(cm.exception))
42        self.assertIn("3669", str(cm.exception))
43
44    def test_a_cuda13_reader_does_not_pass_for_the_pascal_package(self):
45        self.reader("75;86;89;120")
46        with self.assertRaises(SystemExit) as cm:
47            self.check("cuda", "windows-x86_64", CUDA12, variant="cuda12")
48        for n in ("sm_60", "sm_61", "sm_70"):
49            self.assertIn(n, str(cm.exception))
50
51    def test_a_reader_built_for_the_packages_archs_passes(self):
52        self.reader("60;61;70;75;80;86;89")
53        self.assertEqual(self.check("cuda", "linux-x86_64", CUDA12, variant="cuda12"), [])
54        self.reader(["75", "sm_86", "89-real", 120])
55        self.assertEqual(self.check("cuda", "windows-x86_64", CUDA13, variant="cuda13"), [])
56
57    def test_allow_stale_vision_packages_it_and_says_what_is_missing(self):
58        self.reader("75;86;89;120")
59        notes = self.check("cuda", "windows-x86_64", CUDA12, variant="cuda12", allow_stale=True)
60        self.assertIn("sm_60", notes[0])
61
62    def test_a_cuda_package_without_a_reader_is_text_only_not_an_error(self):
63        notes = self.check("cuda", "linux-x86_64", CUDA13, variant="cuda13")
64        self.assertIn("text only", notes[0])
65
66    def test_a_macos_package_without_a_reader_is_refused(self):
67        with self.assertRaises(SystemExit) as cm:
68            self.check("metal", "macos-arm64", ())
69        self.assertIn("build_vision_mac.sh", str(cm.exception))
70        self.assertIn("pictures are off", self.check("metal", "macos-arm64", (), allow_none=True)[0])
71
72    def test_a_macos_package_with_a_reader_passes(self):
73        self.reader()
74        self.assertEqual(self.check("metal", "macos-arm64", ()), [])
75
76    def test_build_runs_the_check_only_when_asked(self):
77        self.reader("75;86;89;120")
78        out = Path(self.tmp.name) / "out"
79        out.mkdir()
80        with self.assertRaises(SystemExit) as cm:
81            package_engine.build(self.src, "cuda", "0.2.3", "linux-x86_64", out, archs=CUDA12, variant="cuda12", build_id="t",
82                                 check_reader=True)
83        self.assertIn("picture reader", str(cm.exception))
84
85    def test_stamp_vision_writes_the_record(self):
86        (self.src / "BUILD.json").write_text(json.dumps({"version": "0.2.3", "archs": "60;61"}))
87        self.assertEqual(package_engine.main(["--stamp-vision", str(self.src), "--vision-archs", "60;61;70"]), 0)
88        data = json.loads((self.src / "BUILD.json").read_text())
89        self.assertEqual(data["vision_archs"], "60;61;70")
90        self.assertEqual(data["archs"], "60;61")
91
92
93if __name__ == "__main__":
94    unittest.main()