diff options
| author | Thatters <69167449+Thatters@users.noreply.github.com> | 2026-11-22 15:20:40 -0500 |
|---|---|---|
| committer | Thatters <69167449+Thatters@users.noreply.github.com> | 2026-11-22 15:20:40 -0500 |
| commit | b21c38e1d2a93bfcd39c45ae9e27ae4aa12d5e7a (patch) | |
| tree | c75d3cb9eb7b9c17f0bad6c68874942e560bd7ab /tests/test_rdna2spirv_cli.py | |
| parent | 48a4c4d130c003ab7c8ffd44ea3c91e5995a672c (diff) | |
| parent | f847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff) | |
Merge origin/main into fix/shader-427-structured-depth
Conflicts: tools/rdna2spirv.py (--pc-tail-ubo and --max-structured-depth
both added next to --max-shared-memory: kept both) and docs/design.md
(upstream reworded the neighbouring rows: kept theirs and re-applied the
SHADER-427 sentence of the "Control flow" row).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_rdna2spirv_cli.py')
| -rw-r--r-- | tests/test_rdna2spirv_cli.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/test_rdna2spirv_cli.py b/tests/test_rdna2spirv_cli.py index a40b4b76b..aa9986426 100644 --- a/tests/test_rdna2spirv_cli.py +++ b/tests/test_rdna2spirv_cli.py | |||
| @@ -150,6 +150,19 @@ class SourceDiscovery(unittest.TestCase): | |||
| 150 | self.assertTrue((out / "ps_ok.spv").is_file()) | 150 | self.assertTrue((out / "ps_ok.spv").is_file()) |
| 151 | self.assertFalse((out / "nested.spv").exists()) | 151 | self.assertFalse((out / "nested.spv").exists()) |
| 152 | 152 | ||
| 153 | def test_a_new_output_folder_with_missing_parents_still_works(self): | ||
| 154 | # The ancestor walk in the --out guard must not reject folders that simply don't exist yet. | ||
| 155 | with tempfile.TemporaryDirectory() as tmp: | ||
| 156 | root = Path(tmp) | ||
| 157 | src = root / "disasm" | ||
| 158 | src.mkdir() | ||
| 159 | (src / "ps_ok.s").write_text("\ts_endpgm\n", encoding="utf-8") | ||
| 160 | (root / "ps_ok.dxbc").write_bytes(b"DXBC" + bytes(28)) | ||
| 161 | out = root / "new" / "deep" / "spirv" | ||
| 162 | stdout = self.run_main(src, out) | ||
| 163 | self.assertIn("1 pass spirv-val", stdout) | ||
| 164 | self.assertTrue((out / "ps_ok.spv").is_file()) | ||
| 165 | |||
| 153 | def test_non_s_file_as_src_is_refused_with_usage_error(self): | 166 | def test_non_s_file_as_src_is_refused_with_usage_error(self): |
| 154 | with tempfile.TemporaryDirectory() as tmp: | 167 | with tempfile.TemporaryDirectory() as tmp: |
| 155 | src = os.path.join(tmp, "notes.txt") | 168 | src = os.path.join(tmp, "notes.txt") |
| @@ -182,6 +195,81 @@ class CommandLine(unittest.TestCase): | |||
| 182 | self.assertFalse(os.path.exists(out)) # 9/8 used to write an empty index.part9.json | 195 | self.assertFalse(os.path.exists(out)) # 9/8 used to write an empty index.part9.json |
| 183 | 196 | ||
| 184 | 197 | ||
| 198 | class OutputFolderValidation(unittest.TestCase): | ||
| 199 | """--out must be a folder path: a file there is a usage error, never a traceback.""" | ||
| 200 | |||
| 201 | def setUp(self): | ||
| 202 | self.tmp = Path(self.enterContext(tempfile.TemporaryDirectory())) | ||
| 203 | self.src = self.tmp / "disasm" | ||
| 204 | self.src.mkdir() | ||
| 205 | (self.src / "ps_x.s").write_text("\ts_endpgm\n", encoding="utf-8") | ||
| 206 | |||
| 207 | def run_tool(self, out, *extra, timeout=None): | ||
| 208 | return subprocess.run([sys.executable, "-I", TOOL, str(self.src), "--out", os.fspath(out), *extra], | ||
| 209 | capture_output=True, text=True, timeout=timeout) | ||
| 210 | |||
| 211 | def assert_usage_error(self, p, message): | ||
| 212 | self.assertEqual(p.returncode, 2, p.stderr) | ||
| 213 | self.assertNotIn("Traceback", p.stderr) | ||
| 214 | # argparse prints its usage and one error line; no exception text besides that line. | ||
| 215 | self.assertEqual(len([line for line in p.stderr.splitlines() if "error:" in line]), 1, p.stderr) | ||
| 216 | self.assertIn(message, p.stderr) | ||
| 217 | |||
| 218 | def test_a_file_at_out_is_refused_and_left_alone(self): | ||
| 219 | out = self.tmp / "out.txt" | ||
| 220 | out.write_text("keep", encoding="utf-8") | ||
| 221 | p = self.run_tool(out) | ||
| 222 | self.assert_usage_error(p, "is a file, not a folder") | ||
| 223 | self.assertEqual(out.read_text(encoding="utf-8"), "keep") | ||
| 224 | |||
| 225 | def test_an_out_under_a_file_is_refused_and_the_file_is_left_alone(self): | ||
| 226 | blocker = self.tmp / "blocker.txt" | ||
| 227 | blocker.write_text("keep", encoding="utf-8") | ||
| 228 | p = self.run_tool(blocker / "sub") | ||
| 229 | self.assert_usage_error(p, "cannot create") | ||
| 230 | self.assertEqual(blocker.read_text(encoding="utf-8"), "keep") | ||
| 231 | self.assertFalse((blocker / "sub").exists()) | ||
| 232 | |||
| 233 | def test_a_file_at_out_is_refused_with_merge(self): | ||
| 234 | out = self.tmp / "out.txt" | ||
| 235 | out.write_text("keep", encoding="utf-8") | ||
| 236 | p = self.run_tool(out, "--merge") | ||
| 237 | self.assert_usage_error(p, "is a file, not a folder") | ||
| 238 | self.assertEqual(out.read_text(encoding="utf-8"), "keep") | ||
| 239 | |||
| 240 | def test_a_file_at_out_with_a_trailing_separator_is_refused(self): | ||
| 241 | out = self.tmp / "out.txt" | ||
| 242 | out.write_text("keep", encoding="utf-8") | ||
| 243 | p = self.run_tool(str(out) + os.sep) | ||
| 244 | self.assertEqual(p.returncode, 2, p.stderr) | ||
| 245 | self.assertNotIn("Traceback", p.stderr) | ||
| 246 | self.assertIn(str(out), p.stderr) | ||
| 247 | self.assertEqual(out.read_text(encoding="utf-8"), "keep") | ||
| 248 | |||
| 249 | def test_an_unmapped_drive_root_is_refused_without_hanging(self): | ||
| 250 | if os.name != "nt": | ||
| 251 | self.skipTest("unmapped drive roots are a Windows path case") | ||
| 252 | drive = next((f"{c}:\\" for c in "ZYXWVUTSRQPONMLKJIHGFEDCBA" if not os.path.exists(f"{c}:\\")), None) | ||
| 253 | if drive is None: | ||
| 254 | self.skipTest("every drive letter exists on this machine") | ||
| 255 | out = os.path.join(drive, "shaders") | ||
| 256 | p = self.run_tool(out, timeout=30) | ||
| 257 | # A root that does not exist used to make the ancestor walk spin forever. | ||
| 258 | self.assert_usage_error(p, "cannot create") | ||
| 259 | |||
| 260 | def test_a_symlink_to_a_file_at_out_is_refused(self): | ||
| 261 | target = self.tmp / "target.txt" | ||
| 262 | target.write_text("keep", encoding="utf-8") | ||
| 263 | link = self.tmp / "link-out" | ||
| 264 | try: | ||
| 265 | os.symlink(target, link) | ||
| 266 | except (OSError, NotImplementedError) as e: | ||
| 267 | self.skipTest(f"symlinks are not available here: {e}") | ||
| 268 | p = self.run_tool(link) | ||
| 269 | self.assert_usage_error(p, "is a file, not a folder") | ||
| 270 | self.assertEqual(target.read_text(encoding="utf-8"), "keep") | ||
| 271 | |||
| 272 | |||
| 185 | class ValidatedOutput(unittest.TestCase): | 273 | class ValidatedOutput(unittest.TestCase): |
| 186 | def setUp(self): | 274 | def setUp(self): |
| 187 | root = Path(self.enterContext(tempfile.TemporaryDirectory())) | 275 | root = Path(self.enterContext(tempfile.TemporaryDirectory())) |