upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/test_run_gpu_tests_python_assembler.py
diff options
context:
space:
mode:
authorOreoFR <29048345+OreoFR@users.noreply.github.com>2026-11-29 17:14:37 +0100
committerOreoFR <29048345+OreoFR@users.noreply.github.com>2026-11-29 17:14:37 +0100
commit51445af78349413cf06bc01a0a3ea8f213bd52a1 (patch)
tree1415ced5e23ad85221095d108b21de8a5556dbf7 /tests/test_run_gpu_tests_python_assembler.py
parent1826e88839fe079d37d107f8efbadb6ddf8d4a38 (diff)
parent1d3da5ebc7c59cf0c614774c7cdf0ca3ba796eac (diff)
Merge origin/main into carry/pr-282
Conflict in the x_memory_order docstring (tools/rdna2spirv.py): main already ignores ds_nop (80417b9c4), so the PR's part still new is ordering image_sample, image_gather4 and image_bvh; its docstring is kept. The PR's parity test probe gains x_one_lane, which main's Gen.x_memory_order reads. Co-authored-by: totonii <totonicontato@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_run_gpu_tests_python_assembler.py')
-rw-r--r--tests/test_run_gpu_tests_python_assembler.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_run_gpu_tests_python_assembler.py b/tests/test_run_gpu_tests_python_assembler.py
index 31a99aa90..fd61b6a9d 100644
--- a/tests/test_run_gpu_tests_python_assembler.py
+++ b/tests/test_run_gpu_tests_python_assembler.py
@@ -4,6 +4,7 @@ import json
4import os 4import os
5from pathlib import Path 5from pathlib import Path
6import struct 6import struct
7import subprocess
7import sys 8import sys
8import tempfile 9import tempfile
9from types import SimpleNamespace 10from types import SimpleNamespace
@@ -19,6 +20,14 @@ import run_gpu_tests
19 20
20 21
21class PythonAssemblerTests(unittest.TestCase): 22class PythonAssemblerTests(unittest.TestCase):
23 def test_native_assembler_error_preserves_undecodable_diagnostics(self):
24 run = subprocess.run
25 child = [sys.executable, "-c", "import sys; sys.stderr.buffer.write(b'bad operand \\xff'); sys.exit(1)"]
26 with patch.object(run_gpu_tests.subprocess, "run", side_effect=lambda _, **kw: run(child, **kw)):
27 with self.assertRaises(RuntimeError) as raised:
28 run_gpu_tests.spirv_as("", "unused.spv")
29 self.assertIn(r"bad operand \xff", str(raised.exception))
30
22 def test_resolve_assembler_auto_and_explicit(self) -> None: 31 def test_resolve_assembler_auto_and_explicit(self) -> None:
23 self.assertEqual(run_gpu_tests.resolve_assembler("python"), "python") 32 self.assertEqual(run_gpu_tests.resolve_assembler("python"), "python")
24 self.assertEqual(run_gpu_tests.resolve_assembler("spirv-as"), "spirv-as") 33 self.assertEqual(run_gpu_tests.resolve_assembler("spirv-as"), "spirv-as")
@@ -41,6 +50,44 @@ class PythonAssemblerTests(unittest.TestCase):
41 self.assertGreaterEqual(len(data), 20) 50 self.assertGreaterEqual(len(data), 20)
42 self.assertEqual(struct.unpack("<I", data[:4])[0], 0x07230203) 51 self.assertEqual(struct.unpack("<I", data[:4])[0], 0x07230203)
43 52
53 def test_spirv_as_missing_on_path_is_a_readable_runtime_error(self) -> None:
54 # An empty PATH: spirv-as cannot be found, and the caller must get the RuntimeError it handles for a failed
55 # assembly, not a raw FileNotFoundError traceback (RUN-GPU-SPIRVAS-MISSING).
56 with tempfile.TemporaryDirectory() as tmp, patch.dict(os.environ, {"PATH": ""}):
57 with self.assertRaises(RuntimeError) as ctx:
58 run_gpu_tests.spirv_as("OpCapability Shader\n", str(Path(tmp) / "out.spv"), assembler="spirv-as")
59 self.assertIn("spirv-as not found on PATH", str(ctx.exception))
60 self.assertNotIsInstance(ctx.exception, FileNotFoundError)
61 self.assertIsNone(ctx.exception.__cause__)
62 self.assertTrue(ctx.exception.__suppress_context__)
63
64 def test_spirv_as_other_oserror_is_a_readable_runtime_error(self) -> None:
65 with tempfile.TemporaryDirectory() as tmp, \
66 patch.object(run_gpu_tests.subprocess, "run",
67 side_effect=PermissionError(13, "Permission denied")):
68 with self.assertRaises(RuntimeError) as ctx:
69 run_gpu_tests.spirv_as("", str(Path(tmp) / "out.spv"), assembler="spirv-as")
70 self.assertIn("spirv-as could not be started: Permission denied", str(ctx.exception))
71
72 def test_spirv_as_present_and_succeeding_runs_spirv_as(self) -> None:
73 # Stubbed success: spirv-as is invoked with the same arguments and a zero exit code is not an error.
74 done = subprocess.CompletedProcess(args=[], returncode=0, stdout="", stderr="")
75 with tempfile.TemporaryDirectory() as tmp, \
76 patch.object(run_gpu_tests.subprocess, "run", return_value=done) as run:
77 run_gpu_tests.spirv_as("asm", str(Path(tmp) / "out.spv"), assembler="spirv-as")
78 run.assert_called_once()
79 self.assertEqual(run.call_args.args[0],
80 ["spirv-as", "--target-env", "vulkan1.2", "-o", str(Path(tmp) / "out.spv"), "-"])
81 self.assertEqual(run.call_args.kwargs["input"], "asm")
82
83 def test_spirv_as_nonzero_exit_reports_stderr(self) -> None:
84 bad = subprocess.CompletedProcess(args=[], returncode=1, stdout="", stderr="error: bad opcode")
85 with tempfile.TemporaryDirectory() as tmp, \
86 patch.object(run_gpu_tests.subprocess, "run", return_value=bad):
87 with self.assertRaises(RuntimeError) as ctx:
88 run_gpu_tests.spirv_as("", str(Path(tmp) / "out.spv"), assembler="spirv-as")
89 self.assertIn("error: bad opcode", str(ctx.exception))
90
44 def test_rdna2spirv_assemble_spirv_no_validate_skips_spirv_val(self) -> None: 91 def test_rdna2spirv_assemble_spirv_no_validate_skips_spirv_val(self) -> None:
45 with tempfile.TemporaryDirectory() as tmp: 92 with tempfile.TemporaryDirectory() as tmp:
46 spvasm = Path(tmp) / "fs_passthru.spvasm" 93 spvasm = Path(tmp) / "fs_passthru.spvasm"