Locate and execute a single test executable; return its MesonTestResult.
(ctx: DirectTestContext)
| 447 | |
| 448 | |
| 449 | def run_direct_test(ctx: DirectTestContext) -> MesonTestResult: |
| 450 | """Locate and execute a single test executable; return its MesonTestResult.""" |
| 451 | test_cmd, artifact_path = _resolve_test_command( |
| 452 | ctx.build_dir, ctx.meson_test_name, ctx.verbose |
| 453 | ) |
| 454 | |
| 455 | if not test_cmd: |
| 456 | _ts_print( |
| 457 | f"[MESON] Error: test executable not found for: {ctx.meson_test_name}", |
| 458 | file=sys.stderr, |
| 459 | ) |
| 460 | return MesonTestResult( |
| 461 | success=False, |
| 462 | duration=time.time() - ctx.start_time, |
| 463 | num_tests_run=0, |
| 464 | num_tests_passed=0, |
| 465 | num_tests_failed=0, |
| 466 | ) |
| 467 | |
| 468 | print_banner("Test", "▶️", verbose=ctx.verbose) |
| 469 | print(f"Running: {ctx.meson_test_name}") |
| 470 | ctx.phase_tracker.set_phase( |
| 471 | "EXECUTE", test_name=ctx.meson_test_name, path="sequential" |
| 472 | ) |
| 473 | |
| 474 | try: |
| 475 | test_env = _make_direct_test_env(ctx.source_dir, ctx.build_dir, ctx.build_mode) |
| 476 | proc = RunningProcess( |
| 477 | test_cmd, |
| 478 | cwd=ctx.source_dir, |
| 479 | timeout=600, |
| 480 | auto_run=True, |
| 481 | check=False, |
| 482 | env=test_env, |
| 483 | output_formatter=TimestampFormatter(), |
| 484 | ) |
| 485 | is_profile_test = artifact_path and "profile" in str(artifact_path) |
| 486 | echo_callback = ctx.verbose or is_profile_test |
| 487 | test_start = time.time() |
| 488 | returncode = cast(int, proc.wait(echo=bool(echo_callback))) |
| 489 | test_duration = time.time() - test_start |
| 490 | duration = time.time() - ctx.start_time |
| 491 | ctx.build_timer.checkpoint("test_execution_done") |
| 492 | |
| 493 | if returncode != 0: |
| 494 | _print_direct_test_failure(ctx, proc, returncode) |
| 495 | if artifact_path is not None: |
| 496 | save_test_result_state( |
| 497 | ctx.build_dir, ctx.meson_test_name, artifact_path, passed=False |
| 498 | ) |
| 499 | if ctx.log_failures is not None and ctx.meson_test_name: |
| 500 | _write_failure_log( |
| 501 | ctx.log_failures, ctx.meson_test_name, "run", str(proc.stdout) |
| 502 | ) |
| 503 | return MesonTestResult( |
| 504 | success=False, |
| 505 | duration=duration, |
| 506 | num_tests_run=1, |
no test coverage detected