upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/test_run_gpu_tests_python_assembler.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_run_gpu_tests_python_assembler.py')
-rw-r--r--tests/test_run_gpu_tests_python_assembler.py37
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
6import struct 6import struct
7import sys 7import sys
8import tempfile 8import tempfile
9from types import SimpleNamespace
9import unittest 10import unittest
10from unittest.mock import patch 11from 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
103if __name__ == "__main__": 140if __name__ == "__main__":
104 unittest.main() 141 unittest.main()