diff options
Diffstat (limited to 'run-tests.php')
-rwxr-xr-x | run-tests.php | 117 |
1 files changed, 77 insertions, 40 deletions
diff --git a/run-tests.php b/run-tests.php index 5a6ac531fc..1432cf1736 100755 --- a/run-tests.php +++ b/run-tests.php @@ -2,8 +2,6 @@ <?php /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -59,6 +57,8 @@ function main() // Parallel testing global $workers, $workerID; + define('IS_WINDOWS', substr(PHP_OS, 0, 3) == "WIN"); + $workerID = 0; if (getenv("TEST_PHP_WORKER")) { $workerID = intval(getenv("TEST_PHP_WORKER")); @@ -137,7 +137,7 @@ NO_PROC_OPEN_ERROR; } } // - if ((substr(PHP_OS, 0, 3) == "WIN") && empty($environment["SystemRoot"])) { + if (IS_WINDOWS && empty($environment["SystemRoot"])) { $environment["SystemRoot"] = getenv("SystemRoot"); } @@ -177,7 +177,7 @@ NO_PROC_OPEN_ERROR; } if (!getenv('TEST_PHPDBG_EXECUTABLE')) { - if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) . "/phpdbg.exe")) { + if (IS_WINDOWS && file_exists(dirname($php) . "/phpdbg.exe")) { $phpdbg = realpath(dirname($php) . "/phpdbg.exe"); } elseif (file_exists(dirname($php) . "/../../sapi/phpdbg/phpdbg")) { $phpdbg = realpath(dirname($php) . "/../../sapi/phpdbg/phpdbg"); @@ -254,6 +254,7 @@ NO_PROC_OPEN_ERROR; 'auto_append_file=', 'ignore_repeated_errors=0', 'precision=14', + 'serialize_precision=-1', 'memory_limit=128M', 'log_errors_max_len=0', 'opcache.fast_shutdown=0', @@ -261,6 +262,7 @@ NO_PROC_OPEN_ERROR; 'opcache.revalidate_freq=0', 'zend.assertions=1', 'zend.exception_ignore_args=0', + 'short_open_tag=0', ); $no_file_cache = '-d opcache.file_cache= -d opcache.file_cache_only=0'; @@ -534,7 +536,7 @@ Synopsis: php run-tests.php [options] [files] [directories] Options: - -j<workers> Run <workers> simultaneous testing processes in parallel for + -j<workers> Run up to <workers> simultaneous testing processes in parallel for quicker testing on systems with multiple logical processors. Note that this is experimental feature. @@ -660,7 +662,7 @@ HELP; } if (strlen($conf_passed)) { - if (substr(PHP_OS, 0, 3) == "WIN") { + if (IS_WINDOWS) { $pass_options .= " -c " . escapeshellarg($conf_passed); } else { $pass_options .= " -c '" . realpath($conf_passed) . "'"; @@ -977,7 +979,7 @@ function save_or_mail_results() $failed_tests_data .= "OS:\n" . PHP_OS . " - " . php_uname() . "\n\n"; $ldd = $autoconf = $sys_libtool = $libtool = $compiler = 'N/A'; - if (substr(PHP_OS, 0, 3) != "WIN") { + if (!IS_WINDOWS) { /* If PHP_AUTOCONF is set, use it; otherwise, use 'autoconf'. */ if (getenv('PHP_AUTOCONF')) { $autoconf = shell_exec(getenv('PHP_AUTOCONF') . ' --version'); @@ -1285,7 +1287,8 @@ function run_all_tests($test_files, $env, $redir_tested = null) // Parallel testing global $PHP_FAILED_TESTS, $workers, $workerID, $workerSock; - if ($workers !== null && !$workerID) { + /* Ignore -jN if there is only one file to analyze. */ + if ($workers !== null && count($test_files) > 1 && !$workerID) { run_all_tests_parallel($test_files, $env, $redir_tested); return; } @@ -1340,7 +1343,7 @@ function run_all_tests($test_files, $env, $redir_tested = null) /** The heart of parallel testing. */ function run_all_tests_parallel($test_files, $env, $redir_tested) { - global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $SHOW_ONLY_GROUPS; + global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $SHOW_ONLY_GROUPS, $valgrind; // The PHP binary running run-tests.php, and run-tests.php itself // This PHP executable is *not* necessarily the same as the tested version @@ -1397,6 +1400,8 @@ function run_all_tests_parallel($test_files, $env, $redir_tested) { if ($shuffle) { shuffle($test_files); } + /* Don't start more workers than test files */ + $workers = max(1, min($workers, count($test_files))); echo "Spawning workers… "; @@ -1412,6 +1417,7 @@ function run_all_tests_parallel($test_files, $env, $redir_tested) { } $sockPort = substr($sockName, $portPos + 1); $sockUri = "tcp://$sockHost:$sockPort"; + $totalFileCount = count($test_files); for ($i = 1; $i <= $workers; $i++) { $proc = proc_open( @@ -1546,8 +1552,14 @@ escape: $sequentialTests = []; } // Batch multiple tests to reduce communication overhead. + // - When valgrind is used, communication overhead is relatively small, + // so just use a batch size of 1. + // - If this is running a small enough number of tests, + // reduce the batch size to give batches to more workers. $files = []; - $batchSize = $shuffle ? 4 : 32; + $maxBatchSize = $valgrind ? 1 : ($shuffle ? 4 : 32); + $averageFilesPerWorker = max(1, (int)ceil($totalFileCount / count($workerProcs))); + $batchSize = min($maxBatchSize, $averageFilesPerWorker); while (count($files) <= $batchSize && $file = array_pop($test_files)) { foreach ($fileConflictsWith[$file] as $conflictKey) { if (isset($activeConflicts[$conflictKey])) { @@ -1931,7 +1943,7 @@ TEST $file if (array_key_exists('CGI', $section_text) || !empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['GZIP_POST']) || !empty($section_text['DEFLATE_POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['PUT']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) { if (isset($php_cgi)) { $php = $php_cgi . ' -C '; - } else if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) . "/php-cgi.exe")) { + } else if (IS_WINDOWS && file_exists(dirname($php) . "/php-cgi.exe")) { $php = realpath(dirname($php) . "/php-cgi.exe") . ' -C '; } else { if (file_exists(dirname($php) . "/../../sapi/cgi/php-cgi")) { @@ -2087,7 +2099,7 @@ TEST $file $ext_dir = `$php $pass_options $extra_options $ext_params -d display_errors=0 -r "echo ini_get('extension_dir');"`; $extensions = preg_split("/[\n\r]+/", trim($section_text['EXTENSIONS'])); $loaded = explode(",", `$php $pass_options $extra_options $ext_params -d display_errors=0 -r "echo implode(',', get_loaded_extensions());"`); - $ext_prefix = substr(PHP_OS, 0, 3) === "WIN" ? "php_" : ""; + $ext_prefix = IS_WINDOWS ? "php_" : ""; foreach ($extensions as $req_ext) { if (!in_array($req_ext, $loaded)) { if ($req_ext == 'opcache') { @@ -2110,6 +2122,8 @@ TEST $file if (array_key_exists('INI', $section_text)) { $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']); $section_text['INI'] = str_replace('{TMP}', sys_get_temp_dir(), $section_text['INI']); + $replacement = IS_WINDOWS ? '"' . PHP_BINARY . ' -r \"while ($in = fgets(STDIN)) echo $in;\" > $1"' : 'tee $1 >/dev/null'; + $section_text['INI'] = preg_replace('/{MAIL:(\S+)}/', $replacement, $section_text['INI']); settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings); } @@ -2126,7 +2140,7 @@ TEST $file if (trim($section_text['SKIPIF'])) { show_file_block('skip', $section_text['SKIPIF']); save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif); - $extra = substr(PHP_OS, 0, 3) !== "WIN" ? + $extra = !IS_WINDOWS ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; if ($valgrind) { @@ -2136,7 +2150,8 @@ TEST $file junit_start_timer($shortname); - $output = system_with_timeout("$extra $php $pass_options $extra_options -q $orig_ini_settings $no_file_cache -d display_errors=0 \"$test_skipif\"", $env); + $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); + $output = trim($output); junit_finish_timer($shortname); @@ -2144,9 +2159,9 @@ TEST $file @unlink($test_skipif); } - if (!strncasecmp('skip', ltrim($output), 4)) { + if (!strncasecmp('skip', $output, 4)) { - if (preg_match('/^\s*skip\s*(.+)\s*/i', $output, $m)) { + if (preg_match('/^skip\s*(.+)/i', $output, $m)) { show_result('SKIP', $tested, $tested_file, "reason: $m[1]", $temp_filenames); } else { show_result('SKIP', $tested, $tested_file, '', $temp_filenames); @@ -2161,22 +2176,26 @@ TEST $file return 'SKIPPED'; } - if (!strncasecmp('info', ltrim($output), 4)) { - if (preg_match('/^\s*info\s*(.+)\s*/i', $output, $m)) { - $info = " (info: $m[1])"; - } - } - - if (!strncasecmp('warn', ltrim($output), 4)) { - if (preg_match('/^\s*warn\s*(.+)\s*/i', $output, $m)) { - $warn = true; /* only if there is a reason */ - $info = " (warn: $m[1])"; - } - } - - if (!strncasecmp('xfail', ltrim($output), 5)) { + if (!strncasecmp('info', $output, 4) && preg_match('/^info\s*(.+)/i', $output, $m)) { + $info = " (info: $m[1])"; + } elseif (!strncasecmp('warn', $output, 4) && preg_match('/^warn\s+(.+)/i', $output, $m)) { + $warn = true; /* only if there is a reason */ + $info = " (warn: $m[1])"; + } elseif (!strncasecmp('xfail', $output, 5)) { // Pretend we have an XFAIL section - $section_text['XFAIL'] = trim(substr(ltrim($output), 5)); + $section_text['XFAIL'] = ltrim(substr($output, 5)); + } elseif ($output !== '') { + show_result("BORK", $output, $tested_file, 'reason: invalid output from SKIPIF', $temp_filenames); + $PHP_FAILED_TESTS['BORKED'][] = array( + 'name' => $file, + 'test_name' => '', + 'output' => '', + 'diff' => '', + 'info' => "$output [$file]", + ); + + junit_mark_test_as('BORK', $shortname, $tested, null, $output); + return 'BORKED'; } } } @@ -2233,7 +2252,7 @@ TEST $file } else { $bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory."; - show_result("BORK", $bork_info, '', $temp_filenames); + show_result("BORK", $bork_info, '', '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array( 'name' => $file, 'test_name' => '', @@ -2251,7 +2270,7 @@ TEST $file } $bork_info = "Redirected test did not contain redirection info"; - show_result("BORK", $bork_info, '', $temp_filenames); + show_result("BORK", $bork_info, '', '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array( 'name' => $file, 'test_name' => '', @@ -2473,9 +2492,12 @@ COMMAND $cmd save_text($test_clean, trim($section_text['CLEAN']), $temp_clean); if (!$no_clean) { - $extra = substr(PHP_OS, 0, 3) !== "WIN" ? + $extra = !IS_WINDOWS ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; - system_with_timeout("$extra $php $pass_options $extra_options -q $orig_ini_settings $no_file_cache \"$test_clean\"", $env); + $clean_output = system_with_timeout("$extra $php $pass_options $extra_options -q $orig_ini_settings $no_file_cache \"$test_clean\"", $env); + if (trim($clean_output) != '') { + echo "\nCLEAN OUTPUT: $file: $clean_output\n"; + } } if (!$cfg['keep']['clean']) { @@ -2726,10 +2748,25 @@ COMMAND $cmd } // write .sh - if (strpos($log_format, 'S') !== false && file_put_contents($sh_filename, "#!/bin/sh - -{$cmd} -", FILE_BINARY) === false) { + $sh_script = <<<SH +#!/bin/sh + +case "$1" in +"gdb") + gdb --args {$cmd} + ;; +"valgrind") + USE_ZEND_ALLOC=0 valgrind $2 ${cmd} + ;; +"rr") + rr record $2 ${cmd} + ;; +*) + {$cmd} + ;; +esac +SH; + if (strpos($log_format, 'S') !== false && file_put_contents($sh_filename, $sh_script, FILE_BINARY) === false) { error("Cannot create test shell script - $sh_filename"); } chmod($sh_filename, 0755); @@ -2944,7 +2981,7 @@ function settings2params($ini_settings) $settings .= " -d \"$name=$val\""; } } else { - if (substr(PHP_OS, 0, 3) == "WIN" && !empty($value) && $value[0] == '"') { + if (IS_WINDOWS && !empty($value) && $value[0] == '"') { $len = strlen($value); if ($value[$len - 1] == '"') { |