diff options
| author | Yash Dubey <yash.dubey803at@gmail.com> | 2026-11-24 07:35:50 +0530 |
|---|---|---|
| committer | Yash Dubey <yash.dubey803at@gmail.com> | 2026-11-24 07:35:50 +0530 |
| commit | dfd239266fd62e1fbbfcf264e9bb4e5c8e8dc801 (patch) | |
| tree | 0fb3fbb22dda6a8b3af3b30b0fc3bcc1a23480f6 /tests | |
| parent | 9ec34cdff41b19d7671bc260e5f40dc69790d905 (diff) | |
make_game, first_light: a vk_pipeline_check or vk_harness older than its sources is rebuilt or reported, not reused silently
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_first_light_harness_paths.py | 46 | ||||
| -rw-r--r-- | tests/test_make_game_pipeline_preflight.py | 59 |
2 files changed, 105 insertions, 0 deletions
diff --git a/tests/test_first_light_harness_paths.py b/tests/test_first_light_harness_paths.py index 58ab34800..438dce472 100644 --- a/tests/test_first_light_harness_paths.py +++ b/tests/test_first_light_harness_paths.py | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | """CPU-only checks for the first-light harness lookup.""" | 1 | """CPU-only checks for the first-light harness lookup.""" |
| 2 | 2 | ||
| 3 | import contextlib | ||
| 4 | import io | ||
| 3 | import os | 5 | import os |
| 4 | from pathlib import Path | 6 | from pathlib import Path |
| 5 | import sys | 7 | import sys |
| @@ -49,6 +51,50 @@ class FirstLightHarnessPathsTests(unittest.TestCase): | |||
| 49 | environment.unlink() | 51 | environment.unlink() |
| 50 | self.assertEqual(first_light.find_harness(None), str(configured)) | 52 | self.assertEqual(first_light.find_harness(None), str(configured)) |
| 51 | 53 | ||
| 54 | def put_sources(self) -> Path: | ||
| 55 | test = self.root / "runtime" / "test" | ||
| 56 | test.mkdir(parents=True, exist_ok=True) | ||
| 57 | (test / "vk_harness.cpp").write_text('#include "../src/table.h"\n', encoding="utf-8") | ||
| 58 | (self.root / "runtime" / "src").mkdir(exist_ok=True) | ||
| 59 | (self.root / "runtime" / "src" / "table.h").write_text("", encoding="utf-8") | ||
| 60 | return test | ||
| 61 | |||
| 62 | def find_with_stderr(self) -> tuple[str, str]: | ||
| 63 | err = io.StringIO() | ||
| 64 | with contextlib.redirect_stderr(err): | ||
| 65 | found = first_light.find_harness(None) | ||
| 66 | return found, err.getvalue() | ||
| 67 | |||
| 68 | def test_a_harness_older_than_its_sources_is_reported(self) -> None: | ||
| 69 | # Old #7148: a harness built before a pull drew with the old program and said nothing. | ||
| 70 | harness = self.put_harness("runtime", "build", "linux") | ||
| 71 | self.put_sources() | ||
| 72 | os.utime(harness, (1_000_000, 1_000_000)) | ||
| 73 | found, err = self.find_with_stderr() | ||
| 74 | self.assertEqual(found, str(harness)) | ||
| 75 | self.assertIn("WARNING", err) | ||
| 76 | self.assertIn("runtime/test/vk_harness.cpp", err) | ||
| 77 | self.assertIn("runtime/src/table.h", err) | ||
| 78 | self.assertIn("--target vk_harness", err) | ||
| 79 | |||
| 80 | def test_a_current_harness_is_used_quietly(self) -> None: | ||
| 81 | self.put_sources() | ||
| 82 | harness = self.put_harness("runtime", "build", "linux") | ||
| 83 | future = os.path.getmtime(self.root / "runtime" / "src" / "table.h") + 60 | ||
| 84 | os.utime(harness, (future, future)) | ||
| 85 | found, err = self.find_with_stderr() | ||
| 86 | self.assertEqual(found, str(harness)) | ||
| 87 | self.assertEqual(err, "") | ||
| 88 | |||
| 89 | def test_a_harness_outside_the_build_folder_is_not_compared(self) -> None: | ||
| 90 | self.put_sources() | ||
| 91 | explicit = self.put_harness("explicit") | ||
| 92 | os.utime(explicit, (1_000_000, 1_000_000)) | ||
| 93 | err = io.StringIO() | ||
| 94 | with contextlib.redirect_stderr(err): | ||
| 95 | self.assertEqual(first_light.find_harness(str(explicit)), str(explicit)) | ||
| 96 | self.assertEqual(err.getvalue(), "") | ||
| 97 | |||
| 52 | 98 | ||
| 53 | if __name__ == "__main__": | 99 | if __name__ == "__main__": |
| 54 | unittest.main() | 100 | unittest.main() |
diff --git a/tests/test_make_game_pipeline_preflight.py b/tests/test_make_game_pipeline_preflight.py index 6197a924e..01e61aec7 100644 --- a/tests/test_make_game_pipeline_preflight.py +++ b/tests/test_make_game_pipeline_preflight.py | |||
| @@ -192,6 +192,65 @@ class LinuxPipelineCheckTest(PreflightEnv, unittest.TestCase): | |||
| 192 | make_game.preflight(["pipelines"], self.work) | 192 | make_game.preflight(["pipelines"], self.work) |
| 193 | build.assert_not_called() | 193 | build.assert_not_called() |
| 194 | 194 | ||
| 195 | def put_checker_older_than_its_source(self): | ||
| 196 | """runtime/build/linux/vk_pipeline_check built before its source last changed (a pull since the build).""" | ||
| 197 | build = os.path.join(self.root, "runtime", "build", "linux") | ||
| 198 | test = os.path.join(self.root, "runtime", "test") | ||
| 199 | os.makedirs(build) | ||
| 200 | os.makedirs(test) | ||
| 201 | checker = os.path.join(build, "vk_pipeline_check") | ||
| 202 | for path, text in ((checker, ""), (os.path.join(test, "vk_pipeline_check.cpp"), '#include "gate.h"\n'), | ||
| 203 | (os.path.join(test, "gate.h"), "")): | ||
| 204 | with open(path, "w", encoding="utf-8") as f: | ||
| 205 | f.write(text) | ||
| 206 | os.utime(checker, (1_000_000, 1_000_000)) | ||
| 207 | os.utime(os.path.join(test, "vk_pipeline_check.cpp"), (500_000, 500_000)) | ||
| 208 | return checker | ||
| 209 | |||
| 210 | def test_a_checker_older_than_its_sources_is_rebuilt(self): | ||
| 211 | # Old #7148: a checker from before a pull was taken as it was, and the stage checked with the old program. | ||
| 212 | self.write_shader_index() | ||
| 213 | checker = self.put_checker_older_than_its_source() | ||
| 214 | with mock.patch.object(make_game, "ROOT", self.root), mock.patch.object(make_game, "pipeline_check_exe", return_value=checker), mock.patch.object(make_game, "build_pipeline_check") as build: | ||
| 215 | self.assertEqual(make_game.stale_checker(checker), ["runtime/test/gate.h"]) | ||
| 216 | make_game.preflight(["pipelines"], self.work, jobs=4) | ||
| 217 | build.assert_called_once_with(4) | ||
| 218 | |||
| 219 | def test_a_current_checker_in_the_build_folder_is_not_rebuilt(self): | ||
| 220 | self.write_shader_index() | ||
| 221 | checker = self.put_checker_older_than_its_source() | ||
| 222 | future = os.path.getmtime(os.path.join(self.root, "runtime", "test", "gate.h")) + 60 | ||
| 223 | os.utime(checker, (future, future)) | ||
| 224 | with mock.patch.object(make_game, "ROOT", self.root), mock.patch.object(make_game, "pipeline_check_exe", return_value=checker), mock.patch.object(make_game, "build_pipeline_check") as build: | ||
| 225 | self.assertEqual(make_game.stale_checker(checker), []) | ||
| 226 | make_game.preflight(["pipelines"], self.work) | ||
| 227 | build.assert_not_called() | ||
| 228 | |||
| 229 | def test_a_stale_checker_without_cmake_is_used_with_a_warning(self): | ||
| 230 | self.write_shader_index() | ||
| 231 | checker = self.put_checker_older_than_its_source() | ||
| 232 | with mock.patch.object(make_game, "ROOT", self.root), mock.patch("shutil.which", side_effect=lambda t: None if t == "cmake" else "/bin/tool"), mock.patch.object(make_game, "pipeline_check_exe", return_value=checker), mock.patch.object(make_game, "build_pipeline_check") as build: | ||
| 233 | make_game.preflight(["pipelines"], self.work) | ||
| 234 | build.assert_not_called() | ||
| 235 | with mock.patch.object(make_game, "log") as log, mock.patch.object(make_game, "checker_supports", side_effect=SystemExit(0)): | ||
| 236 | with self.assertRaises(SystemExit): | ||
| 237 | make_game.pipelines(self.work, os.path.join(self.root, "out")) | ||
| 238 | warning = log.call_args_list[0].args[0] | ||
| 239 | self.assertIn("WARNING", warning) | ||
| 240 | self.assertIn("runtime/test/gate.h", warning) | ||
| 241 | self.assertIn("cmake --build runtime/build/linux --target vk_pipeline_check", warning) | ||
| 242 | |||
| 243 | def test_a_checker_outside_the_build_folder_is_not_compared(self): | ||
| 244 | # --runtime-build and the like: their time stamps say nothing about this checkout's sources. | ||
| 245 | self.put_checker_older_than_its_source() | ||
| 246 | elsewhere = os.path.join(self.root, "elsewhere", "vk_pipeline_check") | ||
| 247 | os.makedirs(os.path.dirname(elsewhere)) | ||
| 248 | with open(elsewhere, "w", encoding="utf-8"): | ||
| 249 | pass | ||
| 250 | os.utime(elsewhere, (1_000_000, 1_000_000)) | ||
| 251 | with mock.patch.object(make_game, "ROOT", self.root): | ||
| 252 | self.assertEqual(make_game.stale_checker(elsewhere), []) | ||
| 253 | |||
| 195 | def test_the_build_uses_the_readme_folder(self): | 254 | def test_the_build_uses_the_readme_folder(self): |
| 196 | with mock.patch.object(make_game, "ROOT", self.root), \ | 255 | with mock.patch.object(make_game, "ROOT", self.root), \ |
| 197 | mock.patch.object(make_game, "log"), \ | 256 | mock.patch.object(make_game, "log"), \ |