From 41c73632e0932f4c184ba9cdbfd4095e0951c71f Mon Sep 17 00:00:00 2001 From: NickSdot Date: Tue, 28 Jul 2026 20:29:30 +0700 Subject: [PATCH 1/4] Account for redirected tests in parallel progress --- run-tests.php | 23 ++++- tests/run-test/redirected_parallel.phpt | 107 ++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 tests/run-test/redirected_parallel.phpt diff --git a/run-tests.php b/run-tests.php index 998e7e24c337..bcb3e092cb36 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1307,7 +1307,12 @@ function run_all_tests(array $test_files, array $env, ?string $redir_tested = nu } /* Ignore -jN if there is only one file to analyze. */ - if ($workers !== null && count($test_files) > 1 && !$workerID) { + if ( + $workers !== null + && count($test_files) > 1 + && !$workerID + && $redir_tested === null + ) { run_all_tests_parallel($test_files, $env, $redir_tested); return; } @@ -1362,7 +1367,7 @@ function run_all_tests(array $test_files, array $env, ?string $redir_tested = nu function run_all_tests_parallel(array $test_files, array $env, ?string $redir_tested): void { - global $workers, $test_idx, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $valgrind, $show_progress; + global $workers, $test_cnt, $test_idx, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $valgrind, $show_progress; global $junit; @@ -1544,6 +1549,9 @@ function run_all_tests_parallel(array $test_files, array $env, ?string $redir_te } switch ($message["type"]) { + case "test_count_delta": + $test_cnt += $message["delta"]; + break; case "tests_finished": $testsInProgress--; foreach ($activeConflicts as $key => $workerId) { @@ -1846,7 +1854,7 @@ function run_test(string $php, $file, array $env): string global $preload, $file_cache; global $num_repeats; // Parallel testing - global $workerID; + global $workerID, $workerSock; global $show_progress; // Temporary @@ -2255,7 +2263,14 @@ function run_test(string $php, $file, array $env): string $test_files[] = [$f, $file]; } } - $test_cnt += count($test_files) - 1; + $testCountDelta = count($test_files) - 1; + $test_cnt += $testCountDelta; + if ($workerID && $testCountDelta !== 0) { + send_message($workerSock, [ + "type" => "test_count_delta", + "delta" => $testCountDelta, + ]); + } $test_idx--; show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file); diff --git a/tests/run-test/redirected_parallel.phpt b/tests/run-test/redirected_parallel.phpt new file mode 100644 index 000000000000..692fe0a19e75 --- /dev/null +++ b/tests/run-test/redirected_parallel.phpt @@ -0,0 +1,107 @@ +--TEST-- +Redirected tests work in parallel runs and update the progress total +--ENV-- +TEST_PHP_FORK_SERVER=0 +--FILE-- + + --EXPECT-- + ok + PHPT); +} + +function runRedirectedTests(array $testFiles): array +{ + $command = [ + getenv('TEST_PHP_EXECUTABLE'), + '-n', + dirname(__DIR__, 2) . '/run-tests.php', + '-n', + '-q', + '-j2', + '--progress', + ...$testFiles, + ]; + $environment = [ + 'PATH' => getenv('PATH'), + 'TEST_PHP_EXECUTABLE' => getenv('TEST_PHP_EXECUTABLE'), + 'TEST_PHP_FORK_SERVER' => '0', + ]; + foreach (['SystemRoot', 'TEMP', 'TMPDIR'] as $name) { + if (($value = getenv($name)) !== false) { + $environment[$name] = $value; + } + } + + $process = proc_open( + $command, + [ + 0 => ['pipe', 'r'], + 1 => ['pipe', 'w'], + 2 => ['redirect', 1], + ], + $pipes, + null, + $environment, + ); + fclose($pipes[0]); + $output = stream_get_contents($pipes[1]); + fclose($pipes[1]); + return [proc_close($process), str_replace("\r", "\n", $output)]; +} + +$root = __DIR__ . '/redirected_parallel_' . getmypid(); +$targets = $root . '/targets'; +mkdir($targets, recursive: true); + +writeRedirectedTest($targets . '/one.phpt', 'redirected one'); +writeRedirectedTest($targets . '/two.phpt', 'redirected two'); + +$targetExpression = var_export($targets, true); +$redirect = $root . '/redirect.phpt'; +file_put_contents($redirect, << [], 'TESTS' => $targetExpression]; + PHPT); +writeRedirectedTest($root . '/companion.phpt', 'companion'); + +[$singleExitCode, $singleOutput] = runRedirectedTests([$redirect]); +if ($singleExitCode !== 0) { + echo $singleOutput; +} +var_dump($singleExitCode); +var_dump(str_contains($singleOutput, 'Fatal error')); + +[$parallelExitCode, $parallelOutput] = runRedirectedTests([ + $redirect, + $root . '/companion.phpt', +]); +if ($parallelExitCode !== 0) { + echo $parallelOutput; +} +var_dump($parallelExitCode); +var_dump(str_contains($parallelOutput, 'TEST 3/3')); +var_dump(str_contains($parallelOutput, 'TEST 3/2')); + +foreach (glob($targets . '/*') as $file) { + unlink($file); +} +rmdir($targets); +unlink($root . '/redirect.phpt'); +unlink($root . '/companion.phpt'); +rmdir($root); +?> +--EXPECT-- +int(0) +bool(false) +int(0) +bool(true) +bool(false) From c777d617599f44fd7832cafd33ff16c35175cb42 Mon Sep 17 00:00:00 2001 From: NickSdot Date: Thu, 30 Jul 2026 22:40:14 +0700 Subject: [PATCH 2/4] review: switched redirected test cleanup to --CLEAN-- --- tests/run-test/redirected_parallel.phpt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/run-test/redirected_parallel.phpt b/tests/run-test/redirected_parallel.phpt index 692fe0a19e75..47830f341253 100644 --- a/tests/run-test/redirected_parallel.phpt +++ b/tests/run-test/redirected_parallel.phpt @@ -90,14 +90,18 @@ if ($parallelExitCode !== 0) { var_dump($parallelExitCode); var_dump(str_contains($parallelOutput, 'TEST 3/3')); var_dump(str_contains($parallelOutput, 'TEST 3/2')); - -foreach (glob($targets . '/*') as $file) { - unlink($file); +?> +--CLEAN-- + --EXPECT-- int(0) From 70726940b001a9c94d0511846d8bf9b79fb75df3 Mon Sep 17 00:00:00 2001 From: NickSdot Date: Fri, 31 Jul 2026 17:36:26 +0700 Subject: [PATCH 3/4] review: style nit Co-authored-by: Arnaud Le Blanc <365207+arnaud-lb@users.noreply.github.com> --- run-tests.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/run-tests.php b/run-tests.php index bcb3e092cb36..42507c0d6435 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1307,12 +1307,8 @@ function run_all_tests(array $test_files, array $env, ?string $redir_tested = nu } /* Ignore -jN if there is only one file to analyze. */ - if ( - $workers !== null - && count($test_files) > 1 - && !$workerID - && $redir_tested === null - ) { + if ($workers !== null && count($test_files) > 1 && !$workerID + && $redir_tested === null) { run_all_tests_parallel($test_files, $env, $redir_tested); return; } From 16e7cc82d4459d23aa87307bb69a26c3265f3c2d Mon Sep 17 00:00:00 2001 From: NickSdot Date: Fri, 31 Jul 2026 17:39:30 +0700 Subject: [PATCH 4/4] review: style nit --- run-tests.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/run-tests.php b/run-tests.php index 42507c0d6435..81e108270125 100755 --- a/run-tests.php +++ b/run-tests.php @@ -2259,12 +2259,12 @@ function run_test(string $php, $file, array $env): string $test_files[] = [$f, $file]; } } - $testCountDelta = count($test_files) - 1; - $test_cnt += $testCountDelta; - if ($workerID && $testCountDelta !== 0) { + $test_count_delta = count($test_files) - 1; + $test_cnt += $test_count_delta; + if ($workerID && $test_count_delta !== 0) { send_message($workerSock, [ "type" => "test_count_delta", - "delta" => $testCountDelta, + "delta" => $test_count_delta, ]); } $test_idx--;