@@ -1833,6 +1833,11 @@ function run_test(string $php, $file, array $env): string
1833
1833
/** @var JUnit */
1834
1834
global $ junit ;
1835
1835
1836
+ static $ skipCache ;
1837
+ if (!$ skipCache ) {
1838
+ $ skipCache = new SkipCache ($ cfg ['keep ' ]['skip ' ]);
1839
+ }
1840
+
1836
1841
$ temp_filenames = null ;
1837
1842
$ org_file = $ file ;
1838
1843
@@ -2156,9 +2161,8 @@ function run_test(string $php, $file, array $env): string
2156
2161
$ ext_params = [];
2157
2162
settings2array ($ ini_overwrites , $ ext_params );
2158
2163
$ ext_params = settings2params ($ ext_params );
2159
- $ ext_dir = `$ php $ pass_options $ extra_options $ ext_params $ no_file_cache -d display_errors=0 -r "echo ini_get('extension_dir');" `;
2160
2164
$ extensions = preg_split ("/[ \n\r]+/ " , trim ($ section_text ['EXTENSIONS ' ]));
2161
- $ loaded = explode ( " , " , ` $ php $ pass_options $ extra_options $ ext_params $ no_file_cache -d display_errors=0 -r "echo implode(',', get_loaded_extensions());" ` );
2165
+ [ $ ext_dir , $ loaded] = $ skipCache -> getExtensions ( " $ php $ pass_options $ extra_options $ ext_params $ no_file_cache" );
2162
2166
$ ext_prefix = IS_WINDOWS ? "php_ " : "" ;
2163
2167
foreach ($ extensions as $ req_ext ) {
2164
2168
if (!in_array ($ req_ext , $ loaded )) {
@@ -2218,7 +2222,6 @@ function run_test(string $php, $file, array $env): string
2218
2222
if (array_key_exists ('SKIPIF ' , $ section_text )) {
2219
2223
if (trim ($ section_text ['SKIPIF ' ])) {
2220
2224
show_file_block ('skip ' , $ section_text ['SKIPIF ' ]);
2221
- save_text ($ test_skipif , $ section_text ['SKIPIF ' ], $ temp_skipif );
2222
2225
$ extra = !IS_WINDOWS ?
2223
2226
"unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD; " : "" ;
2224
2227
@@ -2230,8 +2233,9 @@ function run_test(string $php, $file, array $env): string
2230
2233
$ junit ->startTimer ($ shortname );
2231
2234
2232
2235
$ startTime = microtime (true );
2233
- $ output = system_with_timeout ("$ extra $ php $ pass_options $ extra_options -q $ orig_ini_settings $ no_file_cache -d display_errors=1 -d display_startup_errors=0 \"$ test_skipif \"" , $ env );
2234
- $ output = trim ($ output );
2236
+ $ commandLine = "$ extra $ php $ pass_options $ extra_options -q $ orig_ini_settings $ no_file_cache -d display_errors=1 -d display_startup_errors=0 " ;
2237
+ $ output = $ skipCache ->checkSkip ($ commandLine , $ section_text ['SKIPIF ' ], $ test_skipif , $ temp_skipif , $ env );
2238
+
2235
2239
$ time = microtime (true ) - $ startTime ;
2236
2240
2237
2241
$ junit ->stopTimer ($ shortname );
@@ -2246,21 +2250,13 @@ function run_test(string $php, $file, array $env): string
2246
2250
];
2247
2251
}
2248
2252
2249
- if (!$ cfg ['keep ' ]['skip ' ]) {
2250
- @unlink ($ test_skipif );
2251
- }
2252
-
2253
2253
if (!strncasecmp ('skip ' , $ output , 4 )) {
2254
2254
if (preg_match ('/^skip\s*(.+)/i ' , $ output , $ m )) {
2255
2255
show_result ('SKIP ' , $ tested , $ tested_file , "reason: $ m [1 ]" , $ temp_filenames );
2256
2256
} else {
2257
2257
show_result ('SKIP ' , $ tested , $ tested_file , '' , $ temp_filenames );
2258
2258
}
2259
2259
2260
- if (!$ cfg ['keep ' ]['skip ' ]) {
2261
- @unlink ($ test_skipif );
2262
- }
2263
-
2264
2260
$ message = !empty ($ m [1 ]) ? $ m [1 ] : '' ;
2265
2261
$ junit ->markTestAs ('SKIP ' , $ shortname , $ tested , null , $ message );
2266
2262
return 'SKIPPED ' ;
@@ -3716,6 +3712,80 @@ private function mergeSuites(array &$dest, array $source): void
3716
3712
}
3717
3713
}
3718
3714
3715
+ class SkipCache
3716
+ {
3717
+ private bool $ keepFile ;
3718
+
3719
+ private array $ skips = [];
3720
+ private array $ extensions = [];
3721
+
3722
+ private int $ hits = 0 ;
3723
+ private int $ misses = 0 ;
3724
+ private int $ extHits = 0 ;
3725
+ private int $ extMisses = 0 ;
3726
+
3727
+ public function __construct (bool $ keepFile )
3728
+ {
3729
+ $ this ->keepFile = $ keepFile ;
3730
+ }
3731
+
3732
+ public function checkSkip (string $ php , string $ code , string $ checkFile , string $ tempFile , array $ env ): string
3733
+ {
3734
+ $ key = $ php ;
3735
+
3736
+ // HACK: extension tests frequently use something like <?php require 'skipif.inc';
3737
+ // for skip checks. These have to be cached separately.
3738
+ if (preg_match ('/require|include|__FILE__|__LINE__/ ' , $ code )) {
3739
+ $ dir = dirname ($ checkFile );
3740
+ $ key = "$ php => $ dir " ;
3741
+ }
3742
+
3743
+ if (isset ($ this ->skips [$ key ][$ code ])) {
3744
+ $ this ->hits ++;
3745
+ return $ this ->skips [$ key ][$ code ];
3746
+ }
3747
+
3748
+ save_text ($ checkFile , $ code , $ tempFile );
3749
+ $ result = trim (system_with_timeout ("$ php \"$ checkFile \"" , $ env ));
3750
+ $ this ->skips [$ key ][$ code ] = $ result ;
3751
+ $ this ->misses ++;
3752
+
3753
+ if (!$ this ->keepFile ) {
3754
+ @unlink ($ checkFile );
3755
+ }
3756
+
3757
+ return $ result ;
3758
+ }
3759
+
3760
+ public function getExtensions (string $ php ): array
3761
+ {
3762
+ if (isset ($ this ->extensions [$ php ])) {
3763
+ $ this ->extHits ++;
3764
+ return $ this ->extensions [$ php ];
3765
+ }
3766
+
3767
+ $ extDir = `$ php -d display_errors=0 -r "echo ini_get('extension_dir');" `;
3768
+ $ extensions = explode (", " , `$ php -d display_errors=0 -r "echo implode(',', get_loaded_extensions());" `);
3769
+
3770
+ $ result = [$ extDir , $ extensions ];
3771
+ $ this ->extensions [$ php ] = $ result ;
3772
+ $ this ->extMisses ++;
3773
+
3774
+ return $ result ;
3775
+ }
3776
+
3777
+ // public function __destruct()
3778
+ // {
3779
+ // echo "Skips: {$this->hits} hits, {$this->misses} misses.\n";
3780
+ // echo "Extensions: {$this->extHits} hits, {$this->extMisses} misses.\n";
3781
+ // echo "Cache distribution:\n";
3782
+ //
3783
+ // foreach ($this->skips as $php => $cache) {
3784
+ // echo "$php: " . count($cache) . "\n";
3785
+ // }
3786
+ // }
3787
+ }
3788
+
3719
3789
class RuntestsValgrind
3720
3790
{
3721
3791
protected $ version = '' ;
0 commit comments