Files
strata/tests/terminal/test_release_matrix.py
T

115 lines
6.5 KiB
Python

"""The 0.2.0-beta release set as a signed feed offers it: one engine package per platform/backend/variant (values copied from the
packages' engine-component.json), and what `feed.select_engine` hands each kind of PC. This is the evidence that engine updates
reach every installer variant by card, so the app update can stay engine-less (tauri.update.conf.json)."""
from __future__ import annotations
import os
import sys
import tarfile
import tempfile
import unittest
from pathlib import Path
from strata_control import feed as feedmod
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "packaging"))
import feed_tool # noqa: E402
V = "0.1.45.3"
SM_NEW = ("sm_75", "sm_86", "sm_89", "sm_120", "compute_120") # the CUDA 13 packages
SM_OLD = ("sm_60", "sm_61", "sm_70", "sm_75", "sm_80", "sm_86", "sm_89", "compute_89") # the CUDA 12 packages (Pascal and Volta)
def pkg(platform, backend, variant, archs, driver=None):
return {"version": V, "platform": platform, "backend": backend, "variant": variant, "archs": list(archs),
"min_driver": {"nvidia": driver} if driver else {}, "min_runtime": None,
"build_id": f"rel-{platform}-{backend}-{variant}", "format": "tar.gz", "url": f"strata-engine-{platform}-{variant}.tar.gz",
"size": 1000, "sha256": "a" * 64, "manifest_sha256": "b" * 64, "installed_bytes": 2000, "notes": ""}
RELEASE = [
pkg("windows-x86_64", "cuda", "cuda13", SM_NEW, "580.65"),
pkg("windows-x86_64", "cuda", "cuda12", SM_OLD, "576.02"),
pkg("windows-x86_64", "hip", "rx9070", ("gfx1200", "gfx1201")),
pkg("linux-x86_64", "cuda", "cuda13", SM_NEW, "580.65"),
pkg("linux-x86_64", "cuda", "cuda12", SM_OLD, "575.51"),
pkg("linux-x86_64", "hip", "rx9070", ("gfx1200", "gfx1201")),
pkg("linux-x86_64", "hip", "rx7900", ("gfx1100", "gfx1101", "gfx1102")),
pkg("macos-arm64", "metal", "", ("apple-gpu",)),
]
def pc(platform, backend, driver=None, sm=(), gfx=()):
return {"platform": platform, "backend": backend, "runtime": "0.2.0", "nvidia_driver": driver, "cuda_archs": list(sm), "gfx": list(gfx)}
class ReleaseSelection(unittest.TestCase):
def pick(self, hardware):
best, reasons = feedmod.select_engine([feedmod._engine_package(p) for p in RELEASE], hardware)
return (best.platform, best.backend, best.variant) if best else None, reasons
def test_every_release_variant_is_chosen_by_some_pc(self):
chosen = {
self.pick(pc("windows-x86_64", "cuda", "590.10", ["sm_120"]))[0], # RTX 5070
self.pick(pc("windows-x86_64", "cuda", "576.02", ["sm_61"]))[0], # GTX 1080 on an older driver
self.pick(pc("windows-x86_64", "hip", gfx=["gfx1201"]))[0], # RX 9070
self.pick(pc("linux-x86_64", "cuda", "615.71", ["sm_86"]))[0], # RTX 3060
self.pick(pc("linux-x86_64", "cuda", "575.51", ["sm_60"]))[0], # Tesla P100
self.pick(pc("linux-x86_64", "hip", gfx=["gfx1201"]))[0], # Radeon AI PRO R9700
self.pick(pc("linux-x86_64", "hip", gfx=["gfx1100"]))[0], # RX 7900 XTX
self.pick(pc("macos-arm64", "metal"))[0],
}
self.assertEqual(chosen, {(p["platform"], p["backend"], p["variant"]) for p in RELEASE})
def test_cuda_13_or_12_follows_the_driver_and_the_card(self):
win = "windows-x86_64"
self.assertEqual(self.pick(pc(win, "cuda", "580.65", ["sm_86"]))[0][2], "cuda13")
self.assertEqual(self.pick(pc(win, "cuda", "590.10", ["sm_120"]))[0][2], "cuda13")
got, why = self.pick(pc(win, "cuda", "576.02", ["sm_120"])) # a new card on an older driver: CUDA 12 reaches it by PTX
self.assertEqual(got[2], "cuda12")
self.assertTrue(any("580.65" in r for r in why))
self.assertEqual(self.pick(pc(win, "cuda", "615.71", ["sm_70"]))[0][2], "cuda12", "Volta is only in the CUDA 12 build")
self.assertEqual(self.pick(pc("linux-x86_64", "cuda", "575.51", ["sm_75"]))[0][2], "cuda12")
self.assertEqual(self.pick(pc("linux-x86_64", "cuda", "580.65", ["sm_75"]))[0][2], "cuda13")
def test_a_driver_that_is_too_old_gets_no_engine_and_a_reason(self):
got, why = self.pick(pc("windows-x86_64", "cuda", "551.00", ["sm_86"]))
self.assertIsNone(got)
self.assertTrue(any("576.02" in r for r in why) and any("580.65" in r for r in why))
def test_amd_gets_its_own_build_and_never_a_cuda_one(self):
self.assertEqual(self.pick(pc("linux-x86_64", "hip", gfx=["gfx1200"]))[0][2], "rx9070")
self.assertEqual(self.pick(pc("linux-x86_64", "hip", gfx=["gfx1102"]))[0][2], "rx7900")
got, why = self.pick(pc("windows-x86_64", "hip", gfx=["gfx1100"])) # no Windows RX 7000 build in this release
self.assertIsNone(got)
self.assertTrue(any("gfx1100" in r for r in why))
for hw in (pc("windows-x86_64", "hip", gfx=["gfx1201"]), pc("linux-x86_64", "hip", gfx=["gfx1201"])):
self.assertEqual(self.pick(hw)[0][1], "hip")
def test_the_platform_decides_first(self):
self.assertIsNone(self.pick(pc("macos-arm64", "cuda", "590.10", ["sm_86"]))[0])
self.assertEqual(self.pick(pc("macos-arm64", "metal"))[0], ("macos-arm64", "metal", ""))
class PackedOnWindows(unittest.TestCase):
def test_programs_are_recognised_by_their_header_so_a_linux_package_packed_on_windows_keeps_them_executable(self):
with tempfile.TemporaryDirectory() as t:
root = Path(t)
(root / "strata-vision").write_bytes(b"\x7fELF\x02\x01" + bytes(20))
(root / "libx.dylib").write_bytes(b"\xcf\xfa\xed\xfe" + bytes(20))
(root / "run.sh").write_bytes(b"#!/bin/sh\n")
(root / "BUILD.json").write_text("{}")
(root / "kernel.hsaco").write_bytes(b"\x00\x01\x02\x03")
names = ("strata-vision", "libx.dylib", "run.sh", "BUILD.json", "kernel.hsaco")
self.assertEqual([feed_tool._is_native_executable(root / n) for n in names], [True, True, True, False, False])
if os.name == "nt": # the owner's release PC: the archive is what matters
archive = root / "a.tar.gz"
feed_tool._write_archive([(n, root / n) for n in ("strata-vision", "BUILD.json")], archive, "tar.gz", None)
with tarfile.open(archive) as tar:
modes = {m.name: m.mode for m in tar.getmembers()}
self.assertEqual(modes, {"strata-vision": 0o755, "BUILD.json": 0o644})
if __name__ == "__main__":
unittest.main()