"""scripts/run_gpu_tests.py: how it judges the output of a compute "dump" test (no device needed).""" import contextlib import io from pathlib import Path import sys import tempfile from types import SimpleNamespace import unittest from unittest.mock import patch sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) import run_gpu_tests as rgt WANT = [55, 48] DEVICE_32 = "device: X (subgroup 32..32)\n" DEVICE_64 = "device: X (subgroup 32..64)\n" CONFIRMED = "compute subgroup size: 64\n" def dump(words, pad=8): return "out[0..7] = " + " ".join(str(w) for w in (list(words) + [0] * pad)[:8]) + "\n" def judge(rc, msg, **kw): kw = {"wave64": False, "partial": False, "emulated": False, **kw} return rgt.judge_cs_dump(rc, msg, WANT, **kw) class DumpWords(unittest.TestCase): def test_eight_decimal_words(self): self.assertEqual(rgt.dump_words("noise\n" + dump(WANT) + "tail\n"), WANT + [0] * 6) def test_anything_else_is_not_a_dump(self): for line in ("out[0..7] = 55 48\n", "out[0..7] = 55 48 BAD 0 0 0 0 0\n", "out[0..7] = 1 BAD 3\n", "out[0..7] = 55 48 0 0 0 0 0\n", "out[0..7] = 55 48 0 0 0 0 0 0 0\n", "out[0..7] = 55 48 0 0 0 0 0 0 x\n", "out[0..7] = \n", "no dump here\n"): with self.subTest(line=line): self.assertIsNone(rgt.dump_words(line)) class PackedFormatFixture(unittest.TestCase): def test_filtered_suite_counts_a_packed_store_mismatch(self): name = "cs_fmt_1010102" with tempfile.TemporaryDirectory() as tmp: args = SimpleNamespace(filter=name, build=tmp, llvm_mc="unused") def translate(_cmd, env=None, gpu=True): (Path(tmp) / "spirv" / f"{name}.spv").touch() return 0, "" output = io.StringIO() problem = "word 15: expected 0xffe00003, got 0xe00003ff" with (patch.object(rgt, "assemble_to_s", side_effect=lambda _mc, _src, dst, _name: Path(dst).touch()), patch.object(rgt, "spirv_as"), patch.object(rgt, "run_cmd", side_effect=translate), patch.object(rgt, "fmt_1010102_test", return_value=problem) as check_fmt, contextlib.redirect_stdout(output)): self.assertEqual(rgt.run_suite(args, tmp), 1) check_fmt.assert_called_once() self.assertIn(problem, output.getvalue()) self.assertIn("0/1 passed", output.getvalue()) class TextureTestOnASmallPushConstantDevice(unittest.TestCase): """vk_texture_test exits 77 on a device with 128 push constant bytes: a SKIP, not a FAIL.""" UNSUPPORTED_MSG = "unsupported: need 144 push constant bytes, device has 128\n" def run_one(self, name): with tempfile.TemporaryDirectory() as tmp: args = SimpleNamespace(filter=name, build=tmp, llvm_mc="unused") def translate(_cmd, env=None, gpu=True): (Path(tmp) / "spirv" / f"{name}.spv").touch() return 0, "" output = io.StringIO() texture = SimpleNamespace(returncode=77, stdout="", stderr=self.UNSUPPORTED_MSG) with (patch.object(rgt, "assemble_to_s", side_effect=lambda _mc, _src, dst, _name: Path(dst).touch()), patch.object(rgt, "spirv_as"), patch.object(rgt, "run_cmd", side_effect=translate), patch.object(rgt.subprocess, "run", return_value=texture), contextlib.redirect_stdout(output), contextlib.redirect_stderr(output)): rc = rgt.run_suite(args, tmp) return rc, output.getvalue() def test_bindless_texture_and_gather_tests_skip(self): for name in ("ps_cube_sample", "ps_texture_sample_d16", "ps_gather_wrap", "ps_array_resinfo"): with self.subTest(name=name): rc, out = self.run_one(name) self.assertEqual(rc, 0, out) self.assertIn("SKIP (unsupported: need 144 push constant bytes, device has 128)", out) self.assertIn("0/1 passed, 1 skipped", out) self.assertNotIn("no runnable", out) class BindlessTestOnASmallPushConstantDevice(unittest.TestCase): """vk_bindless_test (ps_tex) exits 77 below its 144 push constant bytes (TEST-149): a SKIP with that reason.""" def run_ps_tex(self, rc, msg): with tempfile.TemporaryDirectory() as tmp: args = SimpleNamespace(filter="ps_tex.asm", build=tmp, llvm_mc="unused") # not ps_texoff etc. def run(cmd, env=None, gpu=True): if Path(cmd[0]).stem == "vk_bindless_test": return rc, msg (Path(tmp) / "spirv" / "ps_tex.spv").touch() # rdna2spirv.py "translating" the shader return 0, "" output = io.StringIO() with (patch.object(rgt, "assemble_to_s", side_effect=lambda _mc, _src, dst, _name: Path(dst).touch()), patch.object(rgt, "spirv_as"), patch.object(rgt, "run_cmd", side_effect=run), contextlib.redirect_stdout(output), contextlib.redirect_stderr(output)): suite_rc = rgt.run_suite(args, tmp) return suite_rc, output.getvalue() def test_too_few_push_constant_bytes_skip(self): rc, out = self.run_ps_tex(77, "device: X\nunsupported: need 144 push constant bytes, device has 128") self.assertEqual(rc, 0, out) self.assertIn("SKIP (unsupported: need 144 push constant bytes, device has 128)", out) self.assertIn("0/1 passed, 1 skipped", out) def test_other_failures_still_fail(self): rc, out = self.run_ps_tex(1, "device: X\nps_tex: 12 pixels differ") self.assertEqual(rc, 1, out) self.assertIn("0/1 passed", out) self.assertNotIn("skipped", out) class FilterWithoutRunnableCases(unittest.TestCase): """A filter selecting only an input shader (cs_bench_mix) must not report 0/0 passed with exit 0.""" def run_filter(self, name, translate_rc=0, spv=True): with tempfile.TemporaryDirectory() as tmp: args = SimpleNamespace(filter=name, build=tmp, llvm_mc="unused") def translate(_cmd, env=None, gpu=True): if spv: (Path(tmp) / "spirv" / f"{name}.spv").touch() return translate_rc, "" out, err = io.StringIO(), io.StringIO() with (patch.object(rgt, "assemble_to_s", side_effect=lambda _mc, _src, dst, _name: Path(dst).touch()) as asm, patch.object(rgt, "spirv_as"), patch.object(rgt, "run_cmd", side_effect=translate) as run, patch.object(rgt, "fmt_1010102_test", return_value=None), contextlib.redirect_stdout(out), contextlib.redirect_stderr(err)): rc = rgt.run_suite(args, tmp) return rc, out.getvalue(), err.getvalue(), asm, run def test_benchmark_input_reports_no_runnable_cases(self): rc, out, err, _, _ = self.run_filter("cs_bench_mix") self.assertEqual(rc, 2, out + err) self.assertIn("--filter 'cs_bench_mix' selected cs_bench_mix but no runnable GPU test cases", err) self.assertIn("inputs without a GPU test row", err) self.assertIn("benchmark tool", err) self.assertIn("=== rdna2spirv.py ===", out) self.assertNotIn("0/0 passed", out) def test_translation_failure_stays_a_failure(self): rc, out, err, _, _ = self.run_filter("cs_bench_mix", translate_rc=1) self.assertEqual((rc, err), (1, "")) rc, out, err, _, _ = self.run_filter("cs_bench_mix", spv=False) self.assertEqual((rc, err), (1, "")) self.assertIn("missing .spv (translation failed)", out) self.assertIn("0/1 passed", out) def test_supported_case_still_passes(self): rc, out, err, _, _ = self.run_filter("cs_fmt_1010102") self.assertEqual((rc, err), (0, "")) self.assertIn("1/1 passed", out) def test_unmatched_filter_fails_before_the_tools_run(self): rc, out, err, asm, run = self.run_filter("unmatched_nicofilter") self.assertEqual(rc, 2) self.assertEqual(err, "error: --filter 'unmatched_nicofilter' matched no GPU test cases\n") asm.assert_not_called() run.assert_not_called() class WholeWaveDump(unittest.TestCase): """wave64: run with --require-wave64 (the whole-wave mask tests).""" def judge(self, rc, msg): return judge(rc, msg, wave64=True) def test_passes_with_the_words_and_the_confirmation(self): self.assertEqual(self.judge(0, DEVICE_64 + CONFIRMED + dump(WANT)), (True, "55 48")) def test_a_device_without_64_wide_subgroups_skips(self): ok, detail = self.judge(77, DEVICE_32 + "full 64-wide compute subgroups unavailable\n") self.assertIs(ok, None) self.assertTrue(detail.startswith("SKIP")) def test_right_words_without_the_confirmation_fail(self): # a vk_compute_test that ignores the flag ok, detail = self.judge(0, DEVICE_64 + dump(WANT)) self.assertIs(ok, False) self.assertIn("not confirmed", detail) def test_wrong_word_and_harness_errors_fail(self): for i in range(len(WANT)): wrong = list(WANT) wrong[i] ^= 1 with self.subTest(word=i): self.assertIs(self.judge(0, CONFIRMED + dump(wrong))[0], False) self.assertIs(self.judge(1, "Vulkan pipeline failed\n")[0], False) # an error is not a skip self.assertIs(self.judge(1, CONFIRMED + dump(WANT))[0], False) def test_malformed_dump_lines_fail_without_raising(self): for line in ("out[0..7] = 55 48\n", "out[0..7] = 55 48 BAD 0 0 0 0 0\n", "out[0..7] = 1 BAD 3\n", "out[0..7] = 55 48 0 0 0 0 0 0 0\n"): with self.subTest(line=line): ok, detail = self.judge(0, CONFIRMED + line) self.assertIs(ok, False) self.assertIn(line.strip(), detail) class NotWholeWave(unittest.TestCase): """Dumps run without --require-wave64: cs_store, emulated wave64 (#152) and partial-group tests.""" def test_plain_dump_needs_no_confirmation_and_a_77_is_a_failure(self): self.assertEqual(judge(0, dump(WANT)), (True, "55 48")) self.assertIs(judge(77, "unavailable\n")[0], False) def test_hex_words(self): ok, detail = rgt.judge_cs_dump(0, dump([0x400080FF, 7]), [0x400080FF, 7], wave64=False, partial=False, emulated=False, hexwords=True) self.assertEqual((ok, detail), (True, "0x400080ff 0x7")) def test_emulated_wave64_runs_on_any_subgroup_size_without_the_confirmation(self): self.assertEqual(judge(0, DEVICE_32 + dump(WANT), emulated=True), (True, "55 48")) self.assertIs(judge(77, DEVICE_32, emulated=True)[0], False) # no skip: it must run here self.assertIs(judge(0, DEVICE_32 + dump([1, 2]), emulated=True)[0], False) def test_partial_group_skips_unless_the_device_reports_a_64_subgroup(self): ok, detail = judge(0, DEVICE_32 + dump(WANT), partial=True) self.assertIs(ok, None) self.assertTrue(detail.startswith("SKIP")) self.assertEqual(judge(0, DEVICE_64 + dump(WANT), partial=True), (True, "55 48")) # no confirmation line self.assertIs(judge(0, DEVICE_64 + dump([1, 2]), partial=True)[0], False) def test_partial_group_emulated_runs_everywhere(self): self.assertEqual(judge(0, DEVICE_32 + dump(WANT), partial=True, emulated=True), (True, "55 48")) def test_malformed_dump_lines_fail_in_every_mode(self): for kw in ({}, {"emulated": True}, {"partial": True, "emulated": True}): with self.subTest(**kw): self.assertIs(judge(0, DEVICE_64 + "out[0..7] = 55 48 BAD 0 0 0 0 0\n", **kw)[0], False) class UniformBranchCheck(unittest.TestCase): """check_uniform_branch (ps_uniform_branch, ps_scc_mask32) must reject a readback in which no bit=0 pixel got s5 = 8: that is what a translator deciding the branch per lane draws (#477, measured on RTX 5080 and RX 9070 XT: 1856 (8,1) / 192 (8,0) / 2048 (7,0) with the vote, 1856 / 0 / 2240 without).""" @staticmethod def judge(rows): import os import struct import tempfile fd, path = tempfile.mkstemp(suffix=".raw") try: with os.fdopen(fd, "wb") as f: # the rows repeated over a full 64x64 frame (a short one fails, TEST-29) for k in range(64 * 64): s5, bit, bary = rows[k % len(rows)] f.write(struct.pack("<2I2f", s5, bit, bary, 0.0)) return rgt.check_uniform_branch(path) finally: os.remove(path) def test_wave_vote_passes(self): ok, detail = self.judge([(8, 1, 0.5), (8, 0, 0.1), (7, 0, 0.1)]) self.assertTrue(ok, detail) def test_per_lane_decision_fails(self): ok, detail = self.judge([(8, 1, 0.5), (7, 0, 0.1), (7, 0, 0.1)]) self.assertFalse(ok) self.assertIn("no bit=0 pixel got s5=8", detail) def test_set_bit_without_8_fails(self): self.assertFalse(self.judge([(7, 1, 0.5), (8, 0, 0.1), (7, 0, 0.1)])[0]) class Wave32LaneDumps(unittest.TestCase): """run_gpu_tests.py skips cs_wqm_w32 and cs_w32_lane_wrap below 32 lanes with check.py's rule.""" def test_uses_check_py_rule(self): import check self.assertIs(rgt.narrow_subgroup_skip, check.narrow_subgroup_skip) self.assertIs(rgt.wave32_lane_skip, check.wave32_lane_skip) self.assertIs(rgt.WAVE32_LANE_DUMPS, check.WAVE32_LANE_DUMPS) self.assertIs(rgt.WAVE32_LANE_ENV, check.WAVE32_LANE_ENV) def test_unpinned_rule(self): self.assertEqual(rgt.wave32_lane_skip("device: X (subgroup 8..32)\ncompute subgroup size: 32 not available\n"), "SKIP (the device can't run this shader at 32 lanes on request)") self.assertIsNone(rgt.wave32_lane_skip("device: X (subgroup 8..32)\ncompute subgroup size: 32\n")) def test_rule(self): self.assertEqual(rgt.narrow_subgroup_skip("device: llvmpipe (subgroup 8..8)\n"), "SKIP (subgroup 8 is narrower than 32 lanes)") for out in ("device: X (subgroup 32..32)\n", "device: X (subgroup 8..32)\n", "device: X (subgroup 32..64)\n", "no device line\n"): with self.subTest(out=out): self.assertIsNone(rgt.narrow_subgroup_skip(out)) class ComputedIJWithoutPerVertexInputs(unittest.TestCase): """ps_ij_computed (SHADER-177): without PerVertexKHR inputs (--bary-fallback, --f16-interp-fallback, the latter on by default on MoltenVK) the translator refuses the computed I/J pair, so there is no .spv. Both runners SKIP it there, before their missing-.spv check; a missing .spv without a fallback stays a translation failure.""" NAME = "ps_ij_computed" def run_suite(self, bary, f16): with tempfile.TemporaryDirectory() as tmp: args = SimpleNamespace(filter=self.NAME, build=tmp, llvm_mc="unused") env = {"LEONIDA_BARY_FALLBACK": "1" if bary else "0", "LEONIDA_F16_INTERP_FALLBACK": "1" if f16 else "0"} out = io.StringIO() with (patch.dict(rgt.os.environ, env), patch.object(rgt, "assemble_to_s", side_effect=lambda _mc, _src, dst, _name: Path(dst).touch()), patch.object(rgt, "spirv_as"), patch.object(rgt, "run_cmd", return_value=(0, "1 shaders: 0 translated, 0 pass spirv-val")), # refused contextlib.redirect_stdout(out), contextlib.redirect_stderr(out)): rc = rgt.run_suite(args, tmp) return rc, out.getvalue() def test_run_gpu_tests_skips_under_either_fallback(self): for bary, f16 in ((True, False), (False, True)): with self.subTest(bary=bary, f16=f16): rc, out = self.run_suite(bary, f16) self.assertIn("SKIP (computed I/J pairs need PerVertexKHR inputs", out) self.assertIn("0/1 passed, 1 skipped", out) self.assertNotIn("missing .spv", out) self.assertEqual(rc, 0, out) def test_run_gpu_tests_missing_spv_without_fallback_still_fails(self): rc, out = self.run_suite(False, False) self.assertIn("missing .spv (translation failed)", out) self.assertEqual(rc, 1, out) def test_check_py_skips_before_its_spv_check(self): import check with tempfile.TemporaryDirectory() as tmp: for bary, f16 in ((True, False), (False, True)): with self.subTest(bary=bary, f16=f16), \ patch.object(check, "BARY_FALLBACK", bary), patch.object(check, "F16_HALVES", f16): self.assertIsInstance(check.pixel_test("unused", tmp, self.NAME), check.Skip) with patch.object(check, "BARY_FALLBACK", False), patch.object(check, "F16_HALVES", False): self.assertEqual(check.pixel_test("unused", tmp, self.NAME), f"missing {self.NAME}.spv") if __name__ == "__main__": unittest.main()