upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/test_gpu_shift64.py
diff options
context:
space:
mode:
authorDadaCap <167002618+DadaCap@users.noreply.github.com>2026-11-24 21:09:02 +0100
committerDadaCap <167002618+DadaCap@users.noreply.github.com>2026-11-24 21:09:02 +0100
commitbc245e5046124941bbdc7bb5c3bd7c739da4e03e (patch)
tree5b780fbcbc1dd131ee635980dfe3e996ac72928f /tests/test_gpu_shift64.py
parent30450e0e96e1df700bbfa9505433c9b9940e8694 (diff)
parent58be9cdf8df9a31bc7f6c068991f1aed381f7f4d (diff)
Merge remote-tracking branch 'origin/main' into vcc-tuple-resync
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_gpu_shift64.py')
-rw-r--r--tests/test_gpu_shift64.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/test_gpu_shift64.py b/tests/test_gpu_shift64.py
new file mode 100644
index 000000000..1ef33d475
--- /dev/null
+++ b/tests/test_gpu_shift64.py
@@ -0,0 +1,96 @@
1"""GPU-VALU64-SHIFTS: readback and runner verdicts, without needing a GPU."""
2import contextlib
3import io
4from pathlib import Path
5import struct
6import sys
7import tempfile
8from types import SimpleNamespace
9import unittest
10from unittest.mock import patch
11
12sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
13import run_gpu_tests as rgt
14import check
15
16
17class Shift64Readback(unittest.TestCase):
18 def test_oracle_boundaries(self):
19 initial, expected = check.shift64_words()
20 self.assertEqual(len(initial), 640)
21 self.assertEqual(len(expected), 640)
22 self.assertEqual(initial[:384], [0xEEEEEEEE] * 384)
23 self.assertEqual(initial[384:], expected[384:])
24 # 1 << 32, 1 >> 32, signed(1) >> 32, each as low/high words.
25 self.assertEqual(expected[66:72], [0, 1, 0, 0, 0, 0])
26 # INT64_MIN >> 63 is 1 logically and -1 arithmetically.
27 self.assertEqual(expected[270:276], [0, 0, 1, 0, 0xFFFFFFFF, 0xFFFFFFFF])
28 # A count of 64 leaves the operand unchanged for all three shifts.
29 self.assertEqual(expected[372:378], [0x89ABCDEF, 0x81234567] * 3)
30 self.assertEqual(expected[378:384], [0x13579BDE, 0x02468ACF, 0xC4D5E6F7, 0x4091A2B3,
31 0xC4D5E6F7, 0xC091A2B3])
32
33 def run_readback(self, mutate=None, code=0, output="", missing=False):
34 paths = []
35
36 def launch(*args, env):
37 paths.append(Path(env["VKC_HEAP_INIT"]))
38 initial, expected = check.shift64_words()
39 self.assertEqual(paths[-1].read_bytes(), struct.pack("<640I", *initial))
40 self.assertEqual(env["VKC_SUBGROUP_SIZE"], "32")
41 self.assertEqual(env["VKC_OUT_WORDS"], "640")
42 self.assertEqual(env["LEONIDA_VK_DEVICE"], "synthetic device")
43 if mutate:
44 mutate(expected)
45 if not missing:
46 Path(env["VKC_DUMP"]).write_bytes(struct.pack(f"<{len(expected)}I", *expected))
47 return code, output
48
49 with patch.object(check, "run", side_effect=launch):
50 result = check.shift64_test("unused", "unused", {"LEONIDA_VK_DEVICE": "synthetic device"})
51 self.assertEqual(len(paths), 1)
52 self.assertFalse(paths[0].exists(), "private heap input must be cleaned up")
53 return result
54
55 def test_complete_readback_passes(self):
56 self.assertEqual(self.run_readback(), "")
57
58 def test_late_result_and_untouched_input_corruption_fail(self):
59 for word in (383, 639):
60 with self.subTest(word=word):
61 result = self.run_readback(lambda data: data.__setitem__(word, data[word] ^ 1))
62 self.assertIn(f"word {word}:", result)
63
64 def test_truncated_and_missing_dump_fail(self):
65 self.assertIn("expected 2560 dump bytes, got 2556", self.run_readback(lambda data: data.pop()))
66 self.assertIn("no VKC_DUMP", self.run_readback(missing=True))
67
68 def test_unsupported_int64_skips_but_nonzero_exit_fails(self):
69 self.assertIsInstance(self.run_readback(code=77, output="unsupported: no Int64\n"), check.Skip)
70 self.assertIn("exit 1", self.run_readback(code=1, output="dispatch failed"))
71
72
73class Shift64Runner(unittest.TestCase):
74 def test_filtered_runner_counts_pass_failure_and_skip(self):
75 for detail, expected, verdict in (("", 0, "1/1 passed"), ("word 383: mismatch", 1, "0/1 passed"),
76 (check.Skip("SKIP (no Int64)"), 0, "0/1 passed, 1 skipped")):
77 with self.subTest(detail=detail), tempfile.TemporaryDirectory() as tmp:
78 args = SimpleNamespace(filter="cs_w32_shift64", build=tmp, llvm_mc="unused")
79
80 def translate(_cmd, **_kwargs):
81 (Path(tmp) / "spirv" / "cs_w32_shift64.spv").touch()
82 return 0, ""
83
84 output = io.StringIO()
85 with (patch.object(rgt, "assemble_to_s", side_effect=lambda _mc, _src, dst, _name: Path(dst).touch()),
86 patch.object(rgt, "spirv_as"), patch.object(rgt, "run_cmd", side_effect=translate),
87 patch.object(rgt, "shift64_test", return_value=detail) as readback,
88 contextlib.redirect_stdout(output)):
89 self.assertEqual(rgt.run_suite(args, tmp), expected)
90 readback.assert_called_once()
91 self.assertIn(verdict, output.getvalue())
92 self.assertIn("cs_w32_shift64", output.getvalue())
93
94
95if __name__ == "__main__":
96 unittest.main()