diff options
| author | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-22 15:51:40 +0100 |
|---|---|---|
| committer | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-22 15:51:40 +0100 |
| commit | df91c6624b69ee4e6c6eeca20ed68d331ed0e728 (patch) | |
| tree | 323c88b9df89bf8abaa2b98d10808474ab675dc2 /tests/test_rdna2spirv_cli.py | |
| parent | b40d8039a98f57b26bd05860febbabbe59b97873 (diff) | |
| parent | 6a6704df1592e1dc4a3215ddf1423a78adb52045 (diff) | |
Merge main into test/valu-int-misc (#1492)
Conflicted files: runtime/test/shaders/check.py, scripts/run_gpu_tests.py
AI-assisted.
Diffstat (limited to 'tests/test_rdna2spirv_cli.py')
| -rw-r--r-- | tests/test_rdna2spirv_cli.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_rdna2spirv_cli.py b/tests/test_rdna2spirv_cli.py index 64dfca3bb..353f79cdb 100644 --- a/tests/test_rdna2spirv_cli.py +++ b/tests/test_rdna2spirv_cli.py | |||
| @@ -215,6 +215,34 @@ class ValidatedOutput(unittest.TestCase): | |||
| 215 | self.assertEqual(json.loads(self.index.read_text(encoding="utf-8")), previous) | 215 | self.assertEqual(json.loads(self.index.read_text(encoding="utf-8")), previous) |
| 216 | self.assertEqual(other.read_bytes(), b"unrelated module") | 216 | self.assertEqual(other.read_bytes(), b"unrelated module") |
| 217 | 217 | ||
| 218 | def test_unsupported_clears_retried_shader_but_preserves_unrelated_output(self): | ||
| 219 | # s_barrier is compute-only, so this PS is Unsupported before any SPIR-V tool runs. A module an | ||
| 220 | # earlier run published for it must not survive: the index is make_game.py's proof of completion. | ||
| 221 | self.src.write_text("\ts_barrier\n\ts_endpgm\n", encoding="utf-8") | ||
| 222 | other = self.out / "cs_other.spv" | ||
| 223 | other.write_bytes(b"unrelated module") | ||
| 224 | previous = {"cs_other": {"stage": "cs"}} | ||
| 225 | self.module.write_bytes(b"old module") | ||
| 226 | self.index.write_text(json.dumps({**previous, "ps_fixture": {"stage": "ps"}}), encoding="utf-8") | ||
| 227 | output = self.translate() | ||
| 228 | self.assertIn("s_barrier outside compute", output) | ||
| 229 | self.assertFalse(self.module.exists()) | ||
| 230 | self.assertEqual(json.loads(self.index.read_text(encoding="utf-8")), previous) | ||
| 231 | self.assertEqual(other.read_bytes(), b"unrelated module") | ||
| 232 | self.assertEqual(list(self.out.glob("*.tmp")), []) | ||
| 233 | |||
| 234 | def test_translator_error_clears_retried_shader(self): | ||
| 235 | self.module.write_bytes(b"old module") | ||
| 236 | self.index.write_text(json.dumps({"ps_fixture": {"stage": "ps"}}), encoding="utf-8") | ||
| 237 | output = io.StringIO() | ||
| 238 | with mock.patch.object(rdna2spirv, "translate", side_effect=ValueError("synthetic translator error")), \ | ||
| 239 | mock.patch.object(sys, "argv", [TOOL, str(self.src), "--out", str(self.out)]), \ | ||
| 240 | redirect_stdout(output): | ||
| 241 | rdna2spirv.main() | ||
| 242 | self.assertIn("translator error ValueError", output.getvalue()) | ||
| 243 | self.assertFalse(self.module.exists()) | ||
| 244 | self.assertEqual(json.loads(self.index.read_text(encoding="utf-8")), {}) | ||
| 245 | |||
| 218 | def test_validation_success_publishes_binary_and_metadata(self): | 246 | def test_validation_success_publishes_binary_and_metadata(self): |
| 219 | self.assertIn("1 pass spirv-val", self.translate()) | 247 | self.assertIn("1 pass spirv-val", self.translate()) |
| 220 | self.assertEqual(self.module.read_bytes(), b"new module") | 248 | self.assertEqual(self.module.read_bytes(), b"new module") |
| @@ -223,3 +251,26 @@ class ValidatedOutput(unittest.TestCase): | |||
| 223 | 251 | ||
| 224 | if __name__ == "__main__": | 252 | if __name__ == "__main__": |
| 225 | unittest.main() | 253 | unittest.main() |
| 254 | |||
| 255 | |||
| 256 | class EmptyShader(unittest.TestCase): | ||
| 257 | """A .s with no tab-indented instruction parses to an empty shader. | ||
| 258 | |||
| 259 | It used to translate to a module that passes spirv-val, lands in index.json and does no work at all, which is | ||
| 260 | what a hand-written or re-indented .s looks like: found while writing a fixture with spaces instead of tabs. | ||
| 261 | """ | ||
| 262 | |||
| 263 | def test_no_instructions_is_reported_and_no_module_is_published(self): | ||
| 264 | with tempfile.TemporaryDirectory() as tmp: | ||
| 265 | src = os.path.join(tmp, "disasm") | ||
| 266 | os.mkdir(src) | ||
| 267 | with open(os.path.join(src, "ps_empty.s"), "w", encoding="utf-8") as f: | ||
| 268 | f.write("; ps_empty code 0x0..0x0 (synthetic), gfx1013, 0 invalid words\n s_endpgm\n") | ||
| 269 | with open(os.path.join(tmp, "ps_empty.dxbc"), "wb") as f: | ||
| 270 | f.write(b"DXBC" + bytes(28)) | ||
| 271 | out = os.path.join(tmp, "spirv") | ||
| 272 | p = subprocess.run([sys.executable, "-I", TOOL, src, "--out", out], capture_output=True, text=True) | ||
| 273 | self.assertEqual(p.returncode, 0, p.stderr) | ||
| 274 | self.assertIn("0 translated", p.stdout, p.stdout) | ||
| 275 | self.assertIn("no instructions (nothing tab-indented?)", p.stdout, p.stdout) | ||
| 276 | self.assertFalse(os.path.exists(os.path.join(out, "ps_empty.spv"))) | ||