diff options
| author | Barbital11111 <93769660+Barbital11111@users.noreply.github.com> | 2026-11-24 00:33:34 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-23 10:33:34 -0600 |
| commit | 511e3826ba8addd4adcd08270d788bc8cc4d4389 (patch) | |
| tree | c11933f0a252fd03c44682682cdd645f12ac0c35 /tests/test_run_gpu_tests_python_assembler.py | |
| parent | e0816d6af23f42353a3939cf4c228675c6e31305 (diff) | |
run_gpu_tests: reuse pre-disassembled work listings (#7332)
Merging after diff review as part of the base pass.
Diffstat (limited to 'tests/test_run_gpu_tests_python_assembler.py')
| -rw-r--r-- | tests/test_run_gpu_tests_python_assembler.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_run_gpu_tests_python_assembler.py b/tests/test_run_gpu_tests_python_assembler.py index 0f66fd2f3..31a99aa90 100644 --- a/tests/test_run_gpu_tests_python_assembler.py +++ b/tests/test_run_gpu_tests_python_assembler.py | |||
| @@ -6,6 +6,7 @@ from pathlib import Path | |||
| 6 | import struct | 6 | import struct |
| 7 | import sys | 7 | import sys |
| 8 | import tempfile | 8 | import tempfile |
| 9 | from types import SimpleNamespace | ||
| 9 | import unittest | 10 | import unittest |
| 10 | from unittest.mock import patch | 11 | from unittest.mock import patch |
| 11 | 12 | ||
| @@ -99,6 +100,42 @@ class PythonAssemblerTests(unittest.TestCase): | |||
| 99 | self.assertEqual(rc, 2) | 100 | self.assertEqual(rc, 2) |
| 100 | self.assertIn("--disasm-dir is not a directory", err.getvalue()) | 101 | self.assertIn("--disasm-dir is not a directory", err.getvalue()) |
| 101 | 102 | ||
| 103 | def test_run_suite_reuses_existing_work_listings(self) -> None: | ||
| 104 | listing = b"; synthetic\n\ts_endpgm\n" | ||
| 105 | run_command = run_gpu_tests.run_cmd | ||
| 106 | for placement in ("in-place", "hard-link", "separate"): | ||
| 107 | with self.subTest(placement=placement), tempfile.TemporaryDirectory() as tmp: | ||
| 108 | work = Path(tmp) / "work" | ||
| 109 | working = work / "disasm" / "cs_lds.s" | ||
| 110 | working.parent.mkdir(parents=True) | ||
| 111 | source = working if placement == "in-place" else Path(tmp) / "source" / working.name | ||
| 112 | source.parent.mkdir(exist_ok=True) | ||
| 113 | source.write_bytes(listing) | ||
| 114 | if placement == "hard-link": | ||
| 115 | try: | ||
| 116 | os.link(source, working) | ||
| 117 | except OSError as exc: | ||
| 118 | self.skipTest(f"hard links unavailable: {exc}") | ||
| 119 | |||
| 120 | args = SimpleNamespace(assembler="python", no_validate=True, disasm_dir=str(source.parent), | ||
| 121 | filter="cs_lds", build=str(work), require_pass=True) | ||
| 122 | |||
| 123 | def run(command, env=None, gpu=True): | ||
| 124 | if not gpu: | ||
| 125 | selected = Path(command[3]) | ||
| 126 | self.assertNotEqual(selected, working.parent) | ||
| 127 | self.assertEqual((selected / working.name).read_bytes(), listing) | ||
| 128 | return run_command(command, env=env, gpu=False) | ||
| 129 | self.assertTrue(Path(command[1]).is_file()) | ||
| 130 | return 0, "synthetic GPU result" | ||
| 131 | |||
| 132 | with (patch.object(run_gpu_tests, "run_cmd", side_effect=run) as launches, | ||
| 133 | patch.object(sys, "stdout", io.StringIO())): | ||
| 134 | self.assertEqual(run_gpu_tests.run_suite(args, str(work)), 0) | ||
| 135 | self.assertEqual(launches.call_count, 2) | ||
| 136 | self.assertEqual(source.read_bytes(), listing) | ||
| 137 | self.assertEqual(working.read_bytes(), listing) | ||
| 138 | |||
| 102 | 139 | ||
| 103 | if __name__ == "__main__": | 140 | if __name__ == "__main__": |
| 104 | unittest.main() | 141 | unittest.main() |