Files
mandy/tests/test_llvm_source_version.py
fiestorra c6c8f5f5a3 scripts: build llvm-mc 23.1.5 by default, so the pipeline library translates (#1923)
* scripts, tools: build llvm-mc 23.1.5 by default, so the pipeline library translates

LLVM 21.1.8's gfx1013 decoder cannot decode 840 of the 2,684 compute
programs in the pipeline library of 1.0.2.1: their listings carry 79,490
undecodable words and 8,310 exp invalid_target_N lines, the translator
refuses all of them as "fall-through into undecodable words", and the
shaders stage keeps 1,844 of 2,684. LLVM 21 does translate all 26,503
shaders of shaders.rpf; the library is what it loses.

The same bytes under llvm-mc 23.1.5 have no rejected word in those 840,
and 839 of them translate and pass spirv-val (the last wants s_sethalt,
which the translator does not implement, under either version). The 1,844
that already translated were re-disassembled too: 1,674 listings change
and all 1,674 still translate, the other 170 are byte-identical, so the
stage goes from 1,844/2,684 to 2,683/2,684.

The build helper now builds 23.1.5 by default. The docs that name the
minimum version (README, docs/design.md, docs/testing.md, docs/linux.md)
and the three user-facing messages that still said 21+ (make_game.py's
preflight, shader_disasm.py's probe error, mc_command.py's install hint)
now say 23+, with the tests that assert those texts updated.

AI-assisted (DeepSeek Harness).
Written with an AI assistant.

* docs: LLVM 23 is what the shaders stage needs, and a test pins the script's default
2026-12-01 11:48:54 +01:00

106 lines
4.5 KiB
Python

"""Exercise source selection with tiny local Git repos; no LLVM download or build."""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "build_llvm_mc.ps1"
class DefaultVersionTest(unittest.TestCase):
"""The version the script builds when the caller names none: LLVM 23 for
the `shaders` stage (1844 of 2684 compute programs do not disassemble with
21's listings), so an accidental revert to 21 fails here instead of
silently in a translation run."""
def test_the_default_source_version_is_23(self):
text = SCRIPT.read_text(encoding="utf-8")
self.assertIn('[string]$Version = "23.1.5"', text)
@unittest.skipUnless(os.name == "nt" and shutil.which("git"), "Windows and Git required")
class SourceVersionTest(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.work = self.root / "retained work"
self.src = self.work / "src"
(self.src / "llvm").mkdir(parents=True)
(self.src / "llvm" / "CMakeLists.txt").write_text(
"# synthetic source\n", encoding="utf-8", newline="\n")
(self.work / "build").mkdir()
(self.work / "build" / "sentinel").write_bytes(b"keep existing build")
self.git("init", "-q")
self.git("add", ".")
self.git("-c", "user.name=Fixture", "-c", "user.email=fixture@example.invalid",
"commit", "-qm", "synthetic release")
self.git("tag", "llvmorg-21.1.8")
text = SCRIPT.read_text(encoding="utf-8-sig")
start = text.index('$src = Join-Path $Temp "src"')
block = text[start:text.index("# DIA SDK off:", start)]
self.driver = self.root / "select.ps1"
self.driver.write_text(
'param([string]$Temp, [string]$Version)\n'
'$ErrorActionPreference = "Stop"\n'
'function Remove-Item { throw "Unexpected deletion" }\n'
+ block + '\nWrite-Output "SOURCE_ACCEPTED"\n',
encoding="utf-8", newline="\n")
def git(self, *args):
return subprocess.run(["git", "-C", str(self.src), *args], check=True,
capture_output=True, text=True, timeout=15).stdout.strip()
def select(self, version, accepted):
before = {str(p.relative_to(self.work)): p.read_bytes()
for p in self.work.rglob("*") if p.is_file()}
result = subprocess.run(
["powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass",
"-File", str(self.driver), "-Temp", str(self.work), "-Version", version],
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=20)
self.assertEqual(result.returncode == 0, accepted, result.stdout + result.stderr)
if accepted:
self.assertIn("SOURCE_ACCEPTED", result.stdout)
else:
self.assertIn("Choose a fresh -Temp", result.stderr)
self.assertNotIn("SOURCE_ACCEPTED", result.stdout)
after = {str(p.relative_to(self.work)): p.read_bytes()
for p in self.work.rglob("*") if p.is_file()}
self.assertEqual(before, after)
def test_same_release_reused(self):
self.select("21.1.8", True)
def test_different_release_missing_tag_rejected(self):
self.select("23.1.5", False)
def test_unknown_release_rejected(self):
self.select("not-a-real-release", False)
def test_existing_tag_at_different_commit_rejected(self):
(self.src / "llvm" / "CMakeLists.txt").write_text(
"# another synthetic release\n", encoding="utf-8", newline="\n")
self.git("add", ".")
self.git("-c", "user.name=Fixture", "-c", "user.email=fixture@example.invalid",
"commit", "-qm", "second release")
self.git("tag", "llvmorg-23.1.5")
self.select("21.1.8", False)
self.select("23.1.5", True)
def test_annotated_release_tag_reused(self):
self.git("-c", "user.name=Fixture", "-c", "user.email=fixture@example.invalid",
"tag", "-am", "release", "llvmorg-23.1.5")
self.select("23.1.5", True)
def test_sources_without_git_metadata_rejected(self):
# Hide the fixture's metadata without deleting it. Do not use an enclosing repo's HEAD.
(self.src / ".git").rename(self.root / "saved-git")
self.select("21.1.8", False)
if __name__ == "__main__":
unittest.main()