1212"""
1313
1414import os
15+ import sys
1516import threading
1617import time
1718from dataclasses import dataclass
4041from ci .util .timestamp_print import ts_print as _ts_print
4142
4243
44+ _DEFAULT_TEST_PROCESS_TIMEOUT_SECONDS = 600
45+ _MACOS_TEST_PROCESS_TIMEOUT_SECONDS = 90
46+
47+
48+ def _test_process_timeout_seconds () -> int :
49+ """Return the outer runner timeout for the current platform.
50+
51+ Apple runners have their own 20-second watchdog. Keep a wider Python
52+ deadline so normal watchdog diagnostics can flush, while still bounding a
53+ pre-main sanitizer/dyld stall that cannot arm the in-process watchdog.
54+ """
55+ if sys .platform == "darwin" :
56+ return _MACOS_TEST_PROCESS_TIMEOUT_SECONDS
57+ return _DEFAULT_TEST_PROCESS_TIMEOUT_SECONDS
58+
59+
60+ def _wait_for_test_process (proc : RunningProcess ) -> TestResult :
61+ """Wait for a runner and retain its captured output on every failure.
62+
63+ ``RunningProcess.wait()`` raises on timeout after killing the child. The
64+ captured stream remains available on ``proc.stdout``; include it in the
65+ returned failure so phase markers and sanitizer diagnostics reach CI logs.
66+ """
67+ try :
68+ returncode = proc .wait (echo = False )
69+ except KeyboardInterrupt as ki :
70+ handle_keyboard_interrupt (ki )
71+ raise
72+ except Exception as error :
73+ captured = str (proc .stdout )
74+ output = f"[MESON] Test execution error: { error } "
75+ if captured :
76+ output += f"\n [MESON] Captured runner output:\n { captured } "
77+ return TestResult (success = False , output = output )
78+
79+ captured = str (proc .stdout )
80+ return TestResult (success = returncode == 0 , output = captured )
81+
82+
4383def validate_test_artifact (
4484 test_path : Path , build_start_time : float
4585) -> Optional [TestResult ]:
@@ -298,7 +338,7 @@ def test_callback(test_path: Path) -> TestResult:
298338 proc = RunningProcess (
299339 cmd ,
300340 cwd = ctx .source_dir ,
301- timeout = 600 ,
341+ timeout = _test_process_timeout_seconds () ,
302342 auto_run = True ,
303343 check = False ,
304344 env = env ,
@@ -308,17 +348,16 @@ def test_callback(test_path: Path) -> TestResult:
308348 with active_procs_lock :
309349 active_procs .add (proc )
310350 try :
311- returncode = proc . wait ( echo = False )
351+ result = _wait_for_test_process ( proc )
312352 finally :
313353 with active_procs_lock :
314354 active_procs .discard (proc )
315- captured = str (proc .stdout )
316355
317- if returncode != 0 :
356+ if not result . success :
318357 with failed_outputs_lock :
319- failed_test_outputs [test_path .stem ] = captured
358+ failed_test_outputs [test_path .stem ] = result . output
320359
321- return TestResult ( success = returncode == 0 , output = captured )
360+ return result
322361
323362 except KeyboardInterrupt as ki :
324363 handle_keyboard_interrupt (ki )
@@ -327,10 +366,13 @@ def test_callback(test_path: Path) -> TestResult:
327366 output = "[MESON] Test interrupted by user" ,
328367 )
329368 except Exception as e :
330- return TestResult (
369+ result = TestResult (
331370 success = False ,
332371 output = f"[MESON] Test execution error: { e } " ,
333372 )
373+ with failed_outputs_lock :
374+ failed_test_outputs [test_path .stem ] = result .output
375+ return result
334376
335377 def _kill_active_procs () -> None :
336378 """Kill all running test subprocesses (called on halt)."""
0 commit comments