From 078d0144ada566d48b93f7dd15174d83c6043c07 Mon Sep 17 00:00:00 2001 From: Romain PINSOLLE Date: Tue, 24 Nov 2026 10:55:40 +0100 Subject: run_gpu_tests: report a missing spirv-as instead of a traceback (RUN-GPU-SPIRVAS-MISSING) spirv_as ran spirv-as without handling OSError, so a missing spirv-as ended the run with a raw FileNotFoundError after the assemble and translate steps. It now raises the RuntimeError a failed assembly already raises, with "spirv-as not found on PATH" (or the OSError text for other failures to start the tool). Tests cover the missing-tool and other-OSError messages, a stubbed successful run, and a nonzero exit with stderr. --- tests/test_run_gpu_tests_python_assembler.py | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/test_run_gpu_tests_python_assembler.py') diff --git a/tests/test_run_gpu_tests_python_assembler.py b/tests/test_run_gpu_tests_python_assembler.py index 31a99aa90..d817f4ec0 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 import os from pathlib import Path import struct +import subprocess import sys import tempfile from types import SimpleNamespace @@ -41,6 +42,44 @@ class PythonAssemblerTests(unittest.TestCase): self.assertGreaterEqual(len(data), 20) self.assertEqual(struct.unpack(" None: + # An empty PATH: spirv-as cannot be found, and the caller must get the RuntimeError it handles for a failed + # assembly, not a raw FileNotFoundError traceback (RUN-GPU-SPIRVAS-MISSING). + with tempfile.TemporaryDirectory() as tmp, patch.dict(os.environ, {"PATH": ""}): + with self.assertRaises(RuntimeError) as ctx: + run_gpu_tests.spirv_as("OpCapability Shader\n", str(Path(tmp) / "out.spv"), assembler="spirv-as") + self.assertIn("spirv-as not found on PATH", str(ctx.exception)) + self.assertNotIsInstance(ctx.exception, FileNotFoundError) + self.assertIsNone(ctx.exception.__cause__) + self.assertTrue(ctx.exception.__suppress_context__) + + def test_spirv_as_other_oserror_is_a_readable_runtime_error(self) -> None: + with tempfile.TemporaryDirectory() as tmp, \ + patch.object(run_gpu_tests.subprocess, "run", + side_effect=PermissionError(13, "Permission denied")): + with self.assertRaises(RuntimeError) as ctx: + run_gpu_tests.spirv_as("", str(Path(tmp) / "out.spv"), assembler="spirv-as") + self.assertIn("spirv-as could not be started: Permission denied", str(ctx.exception)) + + def test_spirv_as_present_and_succeeding_runs_spirv_as(self) -> None: + # Stubbed success: spirv-as is invoked with the same arguments and a zero exit code is not an error. + done = subprocess.CompletedProcess(args=[], returncode=0, stdout="", stderr="") + with tempfile.TemporaryDirectory() as tmp, \ + patch.object(run_gpu_tests.subprocess, "run", return_value=done) as run: + run_gpu_tests.spirv_as("asm", str(Path(tmp) / "out.spv"), assembler="spirv-as") + run.assert_called_once() + self.assertEqual(run.call_args.args[0], + ["spirv-as", "--target-env", "vulkan1.2", "-o", str(Path(tmp) / "out.spv"), "-"]) + self.assertEqual(run.call_args.kwargs["input"], "asm") + + def test_spirv_as_nonzero_exit_reports_stderr(self) -> None: + bad = subprocess.CompletedProcess(args=[], returncode=1, stdout="", stderr="error: bad opcode") + with tempfile.TemporaryDirectory() as tmp, \ + patch.object(run_gpu_tests.subprocess, "run", return_value=bad): + with self.assertRaises(RuntimeError) as ctx: + run_gpu_tests.spirv_as("", str(Path(tmp) / "out.spv"), assembler="spirv-as") + self.assertIn("error: bad opcode", str(ctx.exception)) + def test_rdna2spirv_assemble_spirv_no_validate_skips_spirv_val(self) -> None: with tempfile.TemporaryDirectory() as tmp: spvasm = Path(tmp) / "fs_passthru.spvasm" -- cgit v1.2.3