[php-src] master: Fix run-tests.php --file-cache-prime with multiple workers (GH-22886)

Ilija Tovilo via GitHub <[email protected]> Sat, 25 Jul 2026 20:48:05 +0000
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Ilija Tovilo (iluuu1994)
Committer: GitHub (web-flow)
Pusher: iluuu1994
Date: 2026-07-25T22:48:02+02:00

Commit: https://github.com/php/php-src/commit/387a3afc6b0831ed65f66e191e9bf328466b87ed
Raw diff: https://github.com/php/php-src/commit/387a3afc6b0831ed65f66e191e9bf328466b87ed.diff

Fix run-tests.php --file-cache-prime with multiple workers (GH-22886)

* Fix run-tests.php --file-cache-prime with multiple workers

We want to remove the directory only before running tests, rather than for every
test. That causes races, but also defeats the purpose of priming the cache.

* Move opcache.opt_debug_level tests

These need to live in ext/opcache/tests to be skipped by run-tests.php for the
--file-cache-use tests, which won't compile the files and thus won't dump the
output.

* Mark preloading test as opcache.file_cache_only=0

Preloading requires shm.

Changed paths:
  A  ext/opcache/tests/array_map_foreach_optimization_007.phpt
  A  ext/opcache/tests/array_map_foreach_optimization_008.phpt
  D  ext/standard/tests/array/array_map_foreach_optimization_006.phpt
  D  ext/standard/tests/array/array_map_foreach_optimization_007.phpt
  M  Zend/tests/partial_application/preloading.phpt
  M  run-tests.php


Diff:

diff --git a/Zend/tests/partial_application/preloading.phpt b/Zend/tests/partial_application/preloading.phpt
index 23ad6edf2c4c..ccbbf2290811 100644
--- a/Zend/tests/partial_application/preloading.phpt
+++ b/Zend/tests/partial_application/preloading.phpt
@@ -4,6 +4,7 @@ PFA preloading
 opcache.enable=1
 opcache.enable_cli=1
 opcache.preload={PWD}/preloading.inc
+opcache.file_cache_only=0
 --SKIPIF--
 <?php
 if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
diff --git a/ext/standard/tests/array/array_map_foreach_optimization_006.phpt b/ext/opcache/tests/array_map_foreach_optimization_007.phpt
similarity index 100%
rename from ext/standard/tests/array/array_map_foreach_optimization_006.phpt
rename to ext/opcache/tests/array_map_foreach_optimization_007.phpt
diff --git a/ext/standard/tests/array/array_map_foreach_optimization_007.phpt b/ext/opcache/tests/array_map_foreach_optimization_008.phpt
similarity index 100%
rename from ext/standard/tests/array/array_map_foreach_optimization_007.phpt
rename to ext/opcache/tests/array_map_foreach_optimization_008.phpt
diff --git a/run-tests.php b/run-tests.php
index 1d8be660388d..998e7e24c337 100755
--- a/run-tests.php
+++ b/run-tests.php
@@ -700,6 +700,12 @@ function main(): void
     verify_config($php);
     write_information($user_tests, $phpdbg);
 
+    if ($file_cache === 'prime') {
+        $cache_dir = get_file_cache_dir();
+        rmdir_recursive($cache_dir);
+        mkdir($cache_dir, recursive: true);
+    }
+
     if ($test_cnt) {
         $exts_tested = [];
         $exts_skipped = [];
@@ -1054,6 +1060,11 @@ function find_files(string $dir, bool $is_ext_dir = false, bool $ignore = false)
     closedir($o);
 }
 
+function get_file_cache_dir(): string
+{
+    return sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php-run-tests-file-cache';
+}
+
 function rmdir_recursive($dir)
 {
     if (!file_exists($dir)) {
@@ -2091,11 +2102,7 @@ function run_test(string $php, $file, array $env): string
     $orig_ini_settings = settings2params($ini_settings);
 
     if ($file_cache !== null) {
-        $ini_settings['opcache.file_cache'] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php-run-tests-file-cache';
-        if ($file_cache === 'prime') {
-            rmdir_recursive($ini_settings['opcache.file_cache']);
-            mkdir($ini_settings['opcache.file_cache'], recursive: true);
-        }
+        $ini_settings['opcache.file_cache'] = get_file_cache_dir();
         // Make sure warnings still show up on the second run.
         $ini_settings['opcache.record_warnings'] = '1';
         // File cache is currently incompatible with JIT.