Skip to content

Commit 4a4eef4

Browse files
committed
WIP: run-tests: add skip cache
Executing PHP every time a test specifies a skip condition is kinda wasteful. Since skip conditions are often similar, just have a cache of them. On my machine, the gains are quite noticeable: 36s instead of 43s with -j16, 253s instead of 302s without concurrency. Cache stats are 3420 hits, 1066 misses in the latter case. Needs more work and a fix for a failing test. Future improvements could be also caching enabled extensions and normalizing skip code across tests to improve hit ratio.
1 parent f068954 commit 4a4eef4

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

run-tests.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,11 @@ function run_test(string $php, $file, array $env): string
18331833
/** @var JUnit */
18341834
global $junit;
18351835

1836+
static $skipChecker;
1837+
if (!$skipChecker) {
1838+
$skipChecker = new SkipChecker();
1839+
}
1840+
18361841
$temp_filenames = null;
18371842
$org_file = $file;
18381843

@@ -2218,7 +2223,7 @@ function run_test(string $php, $file, array $env): string
22182223
if (array_key_exists('SKIPIF', $section_text)) {
22192224
if (trim($section_text['SKIPIF'])) {
22202225
show_file_block('skip', $section_text['SKIPIF']);
2221-
save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif);
2226+
//save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif);
22222227
$extra = !IS_WINDOWS ?
22232228
"unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : "";
22242229

@@ -2230,7 +2235,10 @@ function run_test(string $php, $file, array $env): string
22302235
$junit->startTimer($shortname);
22312236

22322237
$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);
2238+
$commandLine = "$extra $php $pass_options $extra_options -q $orig_ini_settings $no_file_cache -d display_errors=1 -d display_startup_errors=0";
2239+
$output = $skipChecker->checkSkip($commandLine, $section_text['SKIPIF'], $test_skipif);
2240+
2241+
//$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);
22342242
$output = trim($output);
22352243
$time = microtime(true) - $startTime;
22362244

@@ -3716,6 +3724,36 @@ private function mergeSuites(array &$dest, array $source): void
37163724
}
37173725
}
37183726

3727+
class SkipChecker
3728+
{
3729+
private array $skips = [];
3730+
private array $extensions = [];
3731+
3732+
private int $hits = 0;
3733+
private int $misses = 0;
3734+
3735+
public function checkSkip(string $php, string $code, string $checkFile): string
3736+
{
3737+
if (isset($this->skips[$php][$code])) {
3738+
$this->hits++;
3739+
return $this->skips[$php][$code];
3740+
}
3741+
3742+
global $env;
3743+
save_text($checkFile, $code);
3744+
$result = system_with_timeout("$php \"$checkFile\"", $env);
3745+
$this->skips[$php][$code] = $result;
3746+
$this->misses++;
3747+
3748+
return $result;
3749+
}
3750+
3751+
// public function __destruct()
3752+
// {
3753+
// echo "{$this->hits} hits, {$this->misses} misses.\n";
3754+
// }
3755+
}
3756+
37193757
class RuntestsValgrind
37203758
{
37213759
protected $version = '';

0 commit comments

Comments
 (0)