Stream test compilation and execution with overlap. Tests start executing as soon as they finish linking, while remaining tests continue compiling. This reduces total wall-clock time compared to a sequential compile-then-run approach. Args: build_dir: Meson build direc
(
build_dir: Path,
test_callback: Callable[[Path], TestResult],
target: Optional[str] = None,
verbose: bool = False,
compile_timeout: int = 600,
build_optimizer: Optional[BuildOptimizer] = None,
test_file_filter: Optional[str] = None,
build_timer=None,
max_failures: int = 10,
)
| 545 | |
| 546 | |
| 547 | def stream_compile_and_run_tests( |
| 548 | build_dir: Path, |
| 549 | test_callback: Callable[[Path], TestResult], |
| 550 | target: Optional[str] = None, |
| 551 | verbose: bool = False, |
| 552 | compile_timeout: int = 600, |
| 553 | build_optimizer: Optional[BuildOptimizer] = None, |
| 554 | test_file_filter: Optional[str] = None, |
| 555 | build_timer=None, |
| 556 | max_failures: int = 10, |
| 557 | ) -> StreamingResult: |
| 558 | """ |
| 559 | Stream test compilation and execution with overlap. |
| 560 | |
| 561 | Tests start executing as soon as they finish linking, while remaining |
| 562 | tests continue compiling. This reduces total wall-clock time compared |
| 563 | to a sequential compile-then-run approach. |
| 564 | |
| 565 | Args: |
| 566 | build_dir: Meson build directory |
| 567 | test_callback: Function called with each completed test path. |
| 568 | Returns a TestResult indicating pass/fail and captured output. |
| 569 | target: Specific target to build (None = all) |
| 570 | verbose: Show detailed progress messages (default: False) |
| 571 | compile_timeout: Timeout in seconds for compilation (default: 600) |
| 572 | build_optimizer: Optional BuildOptimizer for DLL relink suppression. |
| 573 | test_file_filter: Optional .hpp filename to filter test execution (e.g., "backbeat.hpp") |
| 574 | build_timer: Optional BuildTimer for recording test_execution_done checkpoint. |
| 575 | max_failures: Maximum number of test failures before halting (default: 10, 0 = unlimited). |
| 576 | """ |
| 577 | # Pass test file filter to the callback via an attribute so it can |
| 578 | # inject it into the subprocess environment (os.environ is stale after |
| 579 | # _streaming_env was copied). |
| 580 | if test_file_filter: |
| 581 | setattr(test_callback, "_test_file_filter", test_file_filter) |
| 582 | |
| 583 | # Prepare concurrent test execution infrastructure. |
| 584 | # Tests are submitted to the executor as they finish linking (during |
| 585 | # compilation), overlapping test execution with ongoing compilation. |
| 586 | max_workers = min(os.cpu_count() or 4, 16) |
| 587 | halt_event = threading.Event() |
| 588 | _kill_all = getattr(test_callback, "kill_all", None) |
| 589 | |
| 590 | @dataclass |
| 591 | class _WorkerResult: |
| 592 | """Internal result from a worker thread.""" |
| 593 | |
| 594 | test_path: Path |
| 595 | test_result: TestResult |
| 596 | error_msg: str = "" |
| 597 | |
| 598 | def _run_one_test(test_path: Path) -> _WorkerResult: |
| 599 | """Run a single test in a worker thread.""" |
| 600 | if halt_event.is_set(): |
| 601 | return _WorkerResult(test_path, TestResult(success=False)) |
| 602 | try: |
| 603 | return _WorkerResult(test_path, test_callback(test_path)) |
| 604 | except KeyboardInterrupt as ki: |
no test coverage detected