Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38144 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55066 invoked from network); 10 Jun 2008 15:30:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jun 2008 15:30:58 -0000 Authentication-Results: pb1.pair.com header.from=steph@phparch.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=steph@phparch.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain phparch.com from 64.99.136.158 cause and error) X-PHP-List-Original-Sender: steph@phparch.com X-Host-Fingerprint: 64.99.136.158 smtprelay-virgin0158.hostedemail.com Linux 2.5 (sometimes 2.4) (4) Received: from [64.99.136.158] ([64.99.136.158:56025] helo=smtprelay-virgin.hostedemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6C/9A-15621-E2E9E484 for ; Tue, 10 Jun 2008 11:30:56 -0400 Received: from filter.hostedemail.com (ff-bigip1 [10.5.19.254]) by smtprelay08.hostedemail.com (Postfix) with SMTP id B67E81423CB for ; Tue, 10 Jun 2008 15:30:50 +0000 (UTC) X-SpamScore: 1 Received: from foxbox (host86-143-244-1.range86-143.btcentralplus.com [86.143.244.1]) (Authenticated sender: steph.fox) by omf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Jun 2008 15:30:47 +0000 (UTC) Message-ID: <005001c8cb0f$250a2930$4401a8c0@foxbox> Reply-To: "Steph Fox" To: "internals" Date: Tue, 10 Jun 2008 16:32:05 +0100 Organization: php|architect MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_004D_01C8CB17.84DAD780" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-session-marker: 73746570682E666F78 X-Spam-Summary: 2,0,0,66a6355a545008d7,24818cd219c23139,steph@phparch.com,,RULES_HIT:152:355:379:539:540:541:542:543:567:973:982:988:989:1000:1155:1156:1260:1308:1309:1313:1314:1345:1437:1487:1515:1516:1518:1540:1575:1587:1594:1676:1711:1730:1747:1764:1766:1792:2073:2075:2078:2393:2559:2562:2899:3352:3622:3865:3866:3867:3868:3869:3870:3871:3872:3873:3874:4250:4362:4699:5007:6117:6119:6261:7281:7875:7903,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:none,DNSBL:none Subject: binary-safe run-tests script for HEAD From: steph@phparch.com ("Steph Fox") ------=_NextPart_000_004D_01C8CB17.84DAD780 Content-Type: text/plain; format=flowed; charset="utf-8"; reply-type=original Content-Transfer-Encoding: 7bit Hi all, I've been fiddling a bit too much, so the attached is the full script rather than a patch (think ws, cs etc - you wouldn't be able to read the diffs as-is). As far as I can work out, the results it's giving are accurate. I ran a random selection of the failed .php output scripts directly and obtained the same results. However, there are over 100 extra fails in ext/standard alone, mostly (apparently) due to some whitespace confusion. I haven't time to go through all of them, perhaps someone else would like to take over at this point? There's also a preg_match() compilation failure in ext\standard\tests\array\bug34066.phpt that I haven't time to investigate, and 22 scripts saved in ANSI encoding (at least, I _think_ they're all ANSI encoded) can't be read and are considered BORKED. So - please play, fix, consider putting into CVS etc. Thanks, - Steph ------=_NextPart_000_004D_01C8CB17.84DAD780 Content-Type: text/plain; format=flowed; name="run-tests-bs.php.txt"; reply-type=original Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="run-tests-bs.php.txt" #!/usr/bin/php=0A= = |=0A= | Preston L. Bannister = |=0A= | Marcus Boerger = |=0A= | Derick Rethans = |=0A= | Sander Roobol = |=0A= | (based on version by: Stig Bakken ) = |=0A= | (based on the PHP 3 test framework by Rasmus Lerdorf) = |=0A= = +----------------------------------------------------------------------+=0A= */=0A= =0A= /* $Id: run-tests.php, v 1.349 2008/05/27 19:20:39 felipe Exp $ */=0A= =0A= /* Sanity check to ensure that pcre extension needed by this script is = available.=0A= * In the event it is not, print a nice error message indicating that = this script will=0A= * not run without it.=0A= */=0A= if (!extension_loaded("pcre")) {=0A= echo <<';=0A= save_text($info_file, $php_info);=0A= $info_params =3D array();=0A= settings2array($ini_overwrites, $info_params);=0A= settings2params($info_params);=0A= $php_info =3D `$php $pass_options $info_params "$info_file"`;=0A= define('TESTED_PHP_VERSION', `$php -r "echo PHP_VERSION;"`);=0A= =0A= if ($php_cgi && $php !=3D $php_cgi) {=0A= $php_info_cgi =3D `$php_cgi $pass_options $info_params -q = "$info_file"`;=0A= $php_info_sep =3D = "\n---------------------------------------------------------------------"= ;=0A= $php_cgi_info =3D "$php_info_sep\nPHP : $php_cgi = $php_info_cgi$php_info_sep";=0A= } else {=0A= $php_cgi_info =3D '';=0A= }=0A= =0A= @unlink($info_file);=0A= =0A= // load list of enabled extensions=0A= save_text($info_file, '');=0A= $exts_to_test =3D explode(', ',`$php $pass_options $info_params = "$info_file"`);=0A= // check for extensions that need special handling and regenerate=0A= $info_params_ex =3D array(=0A= 'session' =3D> array('session.auto_start=3D0'),=0A= 'tidy' =3D> array('tidy.clean_output=3D0'),=0A= 'zlib' =3D> array('zlib.output_compression=3DOff'),=0A= 'xdebug' =3D> array('xdebug.default_enable=3D0'),=0A= );=0A= =0A= foreach($info_params_ex as $ext =3D> $ini_overwrites_ex) {=0A= if (in_array($ext, $exts_to_test)) {=0A= $ini_overwrites =3D array_merge($ini_overwrites, $ini_overwrites_ex);=0A= }=0A= }=0A= =0A= @unlink($info_file);=0A= =0A= // Write test context information.=0A= echo "=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= PHP : $php $php_info $php_cgi_info=0A= CWD : $cwd=0A= Extra dirs : ";=0A= foreach ($user_tests as $test_dir) {=0A= echo "{$test_dir}\n ";=0A= }=0A= echo "=0A= VALGRIND : " . ($leak_check ? $valgrind_header : 'Not used') . "=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= ";=0A= }=0A= =0A= // Determine the tests to be run.=0A= =0A= $test_files =3D array();=0A= $redir_tests =3D array();=0A= $test_results =3D array();=0A= $PHP_FAILED_TESTS =3D array('BORKED' =3D> array(), 'FAILED' =3D> = array(), 'WARNED' =3D> array(), 'LEAKED' =3D> array(), 'XFAILED' =3D> = array());=0A= =0A= // If parameters given assume they represent selected tests to run.=0A= $failed_tests_file=3D false;=0A= $pass_option_n =3D false;=0A= $pass_options =3D '';=0A= $compression =3D 0;=0A= $output_file =3D $CUR_DIR . '/php_test_results_' . @date('Ymd_Hi') . = '.txt';=0A= =0A= if ($compression) {=0A= $output_file =3D 'compress.zlib://' . $output_file . '.gz';=0A= }=0A= =0A= $just_save_results =3D false;=0A= $leak_check =3D false;=0A= $html_output =3D false;=0A= $html_file =3D null;=0A= $temp_source =3D null;=0A= $temp_target =3D null;=0A= $temp_urlbase =3D null;=0A= $conf_passed =3D null;=0A= $no_clean =3D false;=0A= =0A= $cfgtypes =3D array('show', 'keep');=0A= $cfgfiles =3D array('skip', 'php', 'clean', 'out', 'diff', 'exp');=0A= $cfg =3D array();=0A= =0A= foreach($cfgtypes as $type) {=0A= $cfg[$type] =3D array();=0A= foreach($cfgfiles as $file) {=0A= $cfg[$type][$file] =3D false;=0A= }=0A= }=0A= =0A= if (getenv('TEST_PHP_ARGS'))=0A= {=0A= if (!isset($argc) || !$argc || !isset($argv)) {=0A= $argv =3D array(__FILE__);=0A= }=0A= =0A= $argv =3D array_merge($argv, split(' ', getenv('TEST_PHP_ARGS')));=0A= $argc =3D count($argv);=0A= }=0A= =0A= if (isset($argc) && $argc > 1) {=0A= =0A= for ($i=3D1; $i<$argc; $i++) {=0A= $is_switch =3D false;=0A= $switch =3D substr($argv[$i],1,1);=0A= $repeat =3D substr($argv[$i],0,1) =3D=3D '-';=0A= =0A= while ($repeat) {=0A= =0A= if (!$is_switch) {=0A= $switch =3D substr($argv[$i],1,1);=0A= }=0A= =0A= $is_switch =3D true;=0A= =0A= if ($repeat) {=0A= foreach($cfgtypes as $type) {=0A= if (strpos($switch, '--' . $type) =3D=3D=3D 0) {=0A= foreach($cfgfiles as $file) {=0A= if ($switch =3D=3D '--' . $type.'-' . $file) {=0A= $cfg[$type][$file] =3D true;=0A= $is_switch =3D false;=0A= break;=0A= }=0A= }=0A= }=0A= }=0A= }=0A= =0A= if (!$is_switch) {=0A= $is_switch =3D true;=0A= break;=0A= }=0A= =0A= $repeat =3D false;=0A= =0A= switch($switch) {=0A= case 'r':=0A= case 'l':=0A= $test_list =3D @file($argv[++$i]);=0A= if ($test_list) {=0A= foreach($test_list as $test) {=0A= $matches =3D array();=0A= if (preg_match('/^#.*\[(.*)\]\:\s+(.*)$/', $test, $matches)) {=0A= $redir_tests[] =3D array($matches[1], $matches[2]);=0A= } else if (strlen($test)) {=0A= $test_files[] =3D trim($test);=0A= }=0A= }=0A= }=0A= if ($switch !=3D 'l') {=0A= break;=0A= }=0A= $i--;=0A= // break left intentionally=0A= case 'w':=0A= $failed_tests_file =3D fopen($argv[++$i], 'w+t');=0A= break;=0A= case 'a':=0A= $failed_tests_file =3D fopen($argv[++$i], 'a+t');=0A= break;=0A= case 'c':=0A= $conf_passed =3D $argv[++$i];=0A= break;=0A= case 'd':=0A= $ini_overwrites[] =3D $argv[++$i];=0A= break;=0A= //case 'h'=0A= case '--keep-all':=0A= foreach($cfgfiles as $file) {=0A= $cfg['keep'][$file] =3D true;=0A= }=0A= break;=0A= //case 'l'=0A= case 'm':=0A= $leak_check =3D true;=0A= $valgrind_cmd =3D "valgrind --version";=0A= $valgrind_header =3D system_with_timeout($valgrind_cmd);=0A= $replace_count =3D 0;=0A= if (!$valgrind_header) {=0A= error("Valgrind returned no version info, cannot proceed.\nPlease = check if Valgrind is installed.");=0A= } else {=0A= $valgrind_version =3D = preg_replace("/valgrind-([0-9])\.([0-9])\.([0-9]+)(-\w+)?(\s+)/", = '$1$2$3', $valgrind_header, 1, $replace_count);=0A= if ($replace_count !=3D 1 || !is_numeric($valgrind_version)) {=0A= error("Valgrind returned invalid version info = (\"$valgrind_header\"), cannot proceed.");=0A= }=0A= $valgrind_header =3D trim($valgrind_header);=0A= }=0A= break;=0A= case 'n':=0A= if (!$pass_option_n) {=0A= $pass_options .=3D ' -n';=0A= }=0A= $pass_option_n =3D true;=0A= break;=0A= case '--no-clean':=0A= $no_clean =3D true;=0A= break;=0A= case 'p':=0A= $php =3D $argv[++$i];=0A= putenv("TEST_PHP_EXECUTABLE=3D$php");=0A= break;=0A= case 'q':=0A= putenv('NO_INTERACTION=3D1');=0A= break;=0A= //case 'r'=0A= case 's':=0A= $output_file =3D $argv[++$i];=0A= $just_save_results =3D true;=0A= break;=0A= case '--show-all':=0A= foreach($cfgfiles as $file) {=0A= $cfg['show'][$file] =3D true;=0A= }=0A= break;=0A= case '--temp-source':=0A= $temp_source =3D $argv[++$i];=0A= break;=0A= case '--temp-target':=0A= $temp_target =3D $argv[++$i];=0A= if ($temp_urlbase) {=0A= $temp_urlbase =3D $temp_target;=0A= }=0A= break;=0A= case '--temp-urlbase':=0A= $temp_urlbase =3D $argv[++$i];=0A= break;=0A= case 'v':=0A= case '--verbose':=0A= $DETAILED =3D true;=0A= break;=0A= //case 'w'=0A= case '-':=0A= // repeat check with full switch=0A= $switch =3D $argv[$i];=0A= if ($switch !=3D '-') {=0A= $repeat =3D true;=0A= }=0A= break;=0A= case '--html':=0A= $html_file =3D @fopen($argv[++$i], 'wt');=0A= $html_output =3D is_resource($html_file);=0A= break;=0A= case '--version':=0A= echo '$Revision: 1.349 $'."\n";=0A= exit(1);=0A= default:=0A= echo "Illegal switch specified!\n";=0A= //break=0A= case 'h':=0A= case '-help':=0A= case '--help':=0A= echo << Read the testfiles to be executed from . After the = test=0A= has finished all failed tests are written to the same = .=0A= If the list is empty and no further test is specified = then=0A= all tests are executed (same as: -r -w ).=0A= =0A= -r Read the testfiles to be executed from .=0A= =0A= -w Write a list of all failed tests to .=0A= =0A= -a Same as -w but append rather then truncating .=0A= =0A= -c Look for php.ini in directory or use as = ini.=0A= =0A= -n Pass -n option to the php binary (Do not use a php.ini).=0A= =0A= -d foo=3Dbar Pass -d option to the php binary (Define INI entry foo=0A= with value 'bar').=0A= =0A= -m Test for memory leaks with Valgrind.=0A= =0A= -p Specify PHP executable to run.=0A= =0A= -q Quiet, no user interaction (same as environment = NO_INTERACTION).=0A= =0A= -s Write output to .=0A= =0A= --verbose=0A= -v Verbose mode.=0A= =0A= --help=0A= -h This Help.=0A= =0A= --html Generate HTML output.=0A= =0A= --temp-source --temp-target [--temp-urlbase ]=0A= Write temporary files to by replacing from = the=0A= filenames to generate with . If --html is being = used and=0A= given then the generated links are relative and = prefixed=0A= with the given url. In general you want to make = the path=0A= to your source files and some pach in your web = page=0A= hierarchy with pointing to .=0A= =0A= --keep-[all|php|skip|clean]=0A= Do not delete 'all' files, 'php' test file, 'skip' or = 'clean'=0A= file.=0A= =0A= --show-[all|php|skip|clean|exp|diff|out]=0A= Show 'all' files, 'php' test file, 'skip' or 'clean' = file. You=0A= can also use this to show the output 'out', the expected = result=0A= 'exp' or the difference between them 'diff'. The result = types=0A= get written independent of the log format, however = 'diff' only=0A= exists when a test fails.=0A= =0A= --no-clean Do not execute clean section if any.=0A= =0A= HELP;=0A= exit(1);=0A= }=0A= }=0A= =0A= if (!$is_switch) {=0A= $testfile =3D realpath($argv[$i]);=0A= =0A= if (!$testfile && strpos($argv[$i], '*') !=3D=3D false && = function_exists('glob')) {=0A= =0A= if (preg_match("/\.phpt$/", $argv[$i])) {=0A= $pattern_match =3D glob($argv[$i]);=0A= } else if (preg_match("/\*$/", $argv[$i])) {=0A= $pattern_match =3D glob($argv[$i] . '.phpt');=0A= } else {=0A= die("bogus test name " . $argv[$i] . "\n");=0A= }=0A= =0A= if (is_array($pattern_match)) {=0A= $test_files =3D array_merge($test_files, $pattern_match);=0A= }=0A= =0A= } else if (is_dir($testfile)) {=0A= find_files($testfile);=0A= } else if (preg_match("/\.phpt$/", $testfile)) {=0A= $test_files[] =3D $testfile;=0A= } else {=0A= die("bogus test name " . $argv[$i] . "\n");=0A= }=0A= }=0A= }=0A= =0A= if (strlen($conf_passed)) {=0A= $pass_options .=3D " -c '$conf_passed'";=0A= }=0A= =0A= $test_files =3D array_unique($test_files);=0A= $test_files =3D array_merge($test_files, $redir_tests);=0A= =0A= // Run selected tests.=0A= $test_cnt =3D count($test_files);=0A= =0A= if ($test_cnt) {=0A= verify_config();=0A= write_information($html_output);=0A= usort($test_files, "test_sort");=0A= $start_time =3D time();=0A= =0A= if (!$html_output) {=0A= echo "Running selected tests.\n";=0A= } else {=0A= show_start($start_time);=0A= }=0A= =0A= $test_idx =3D 0;=0A= run_all_tests($test_files, $environment);=0A= $end_time =3D time();=0A= =0A= if ($html_output) {=0A= show_end($end_time);=0A= }=0A= =0A= if ($failed_tests_file) {=0A= fclose($failed_tests_file);=0A= }=0A= =0A= if (count($test_files) || count($test_results)) {=0A= compute_summary();=0A= if ($html_output) {=0A= fwrite($html_file, "
\n" . get_summary(false, true));=0A= }=0A= echo = "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D";=0A= echo get_summary(false, false);=0A= }=0A= =0A= if ($html_output) {=0A= fclose($html_file);=0A= }=0A= =0A= if (getenv('REPORT_EXIT_STATUS') =3D=3D 1 and preg_match('/FAILED(?: = |$)/', implode(' ', $test_results))) {=0A= exit(1);=0A= }=0A= =0A= exit(0);=0A= }=0A= }=0A= =0A= verify_config();=0A= write_information($html_output);=0A= =0A= // Compile a list of all test files (*.phpt).=0A= $test_files =3D array();=0A= $exts_tested =3D count($exts_to_test);=0A= $exts_skipped =3D 0;=0A= $ignored_by_ext =3D 0;=0A= sort($exts_to_test);=0A= $test_dirs =3D array();=0A= $optionals =3D array('tests', 'ext', 'Zend', 'ZendEngine2', 'sapi/cli', = 'sapi/cgi');=0A= =0A= foreach($optionals as $dir) {=0A= if (@filetype($dir) =3D=3D 'dir') {=0A= $test_dirs[] =3D $dir;=0A= }=0A= }=0A= =0A= // Convert extension names to lowercase=0A= foreach ($exts_to_test as $key =3D> $val) {=0A= $exts_to_test[$key] =3D strtolower($val);=0A= }=0A= =0A= foreach ($test_dirs as $dir) {=0A= find_files("{$cwd}/{$dir}", ($dir =3D=3D 'ext'));=0A= }=0A= =0A= foreach ($user_tests as $dir) {=0A= find_files($dir, ($dir =3D=3D 'ext'));=0A= }=0A= =0A= function find_files($dir, $is_ext_dir =3D false, $ignore =3D false)=0A= {=0A= global $test_files, $exts_to_test, $ignored_by_ext, $exts_skipped, = $exts_tested;=0A= =0A= $o =3D opendir($dir) or error("cannot open directory: $dir");=0A= =0A= while (($name =3D readdir($o)) !=3D=3D false) {=0A= =0A= if (is_dir("{$dir}/{$name}") && !in_array($name, array('.', '..', = 'CVS'))) {=0A= $skip_ext =3D ($is_ext_dir && !in_array(strtolower($name), = $exts_to_test));=0A= if ($skip_ext) {=0A= $exts_skipped++;=0A= }=0A= find_files("{$dir}/{$name}", false, $ignore || $skip_ext);=0A= }=0A= =0A= // Cleanup any left-over tmp files from last run.=0A= if (substr($name, -4) =3D=3D '.tmp') {=0A= @unlink("$dir/$name");=0A= continue;=0A= }=0A= =0A= // Otherwise we're only interested in *.phpt files.=0A= if (substr($name, -5) =3D=3D '.phpt') {=0A= if ($ignore) {=0A= $ignored_by_ext++;=0A= } else {=0A= $testfile =3D realpath("{$dir}/{$name}");=0A= $test_files[] =3D $testfile;=0A= }=0A= }=0A= }=0A= =0A= closedir($o);=0A= }=0A= =0A= function test_name($name)=0A= {=0A= if (is_array($name)) {=0A= return $name[0] . ':' . $name[1];=0A= } else {=0A= return $name;=0A= }=0A= }=0A= =0A= function test_sort($a, $b)=0A= {=0A= global $cwd;=0A= =0A= $a =3D test_name($a);=0A= $b =3D test_name($b);=0A= =0A= $ta =3D strpos($a, "{$cwd}/tests") =3D=3D=3D 0 ? 1 + (strpos($a, = "{$cwd}/tests/run-test") =3D=3D=3D 0 ? 1 : 0) : 0;=0A= $tb =3D strpos($b, "{$cwd}/tests") =3D=3D=3D 0 ? 1 + (strpos($b, = "{$cwd}/tests/run-test") =3D=3D=3D 0 ? 1 : 0) : 0;=0A= =0A= if ($ta =3D=3D $tb) {=0A= return strcmp($a, $b);=0A= } else {=0A= return $tb - $ta;=0A= }=0A= }=0A= =0A= $test_files =3D array_unique($test_files);=0A= usort($test_files, "test_sort");=0A= =0A= $start_time =3D time();=0A= show_start($start_time);=0A= =0A= $test_cnt =3D count($test_files);=0A= $test_idx =3D 0;=0A= run_all_tests($test_files, $environment);=0A= $end_time =3D time();=0A= =0A= if ($failed_tests_file) {=0A= fclose($failed_tests_file);=0A= }=0A= =0A= // Summarize results=0A= =0A= if (0 =3D=3D count($test_results)) {=0A= echo "No tests were run.\n";=0A= return;=0A= }=0A= =0A= compute_summary();=0A= =0A= show_end($end_time);=0A= show_summary();=0A= =0A= if ($html_output) {=0A= fclose($html_file);=0A= }=0A= =0A= define('PHP_QA_EMAIL', 'qa-reports@lists.php.net');=0A= define('QA_SUBMISSION_PAGE', 'http://qa.php.net/buildtest-process.php');=0A= =0A= /* We got failed Tests, offer the user to send an e-mail to QA team, = unless NO_INTERACTION is set */=0A= if (!getenv('NO_INTERACTION')) {=0A= $fp =3D fopen("php://stdin", "r+");=0A= if ($sum_results['FAILED'] || $sum_results['BORKED'] || = $sum_results['WARNED'] || $sum_results['LEAKED']|| = $sum_results['XFAILED']) {=0A= echo "\nYou may have found a problem in PHP.";=0A= }=0A= echo "\nWe would like to send this report automatically to the\n";=0A= echo "PHP QA team, to give us a better understanding of how\nthe test = cases are doing. If you don't want to send it\n";=0A= echo "immediately, you can choose \"s\" to save the report to\na file = that you can send us later.\n";=0A= echo "Do you want to send this report now? [Yns]: ";=0A= flush();=0A= =0A= $user_input =3D fgets($fp, 10);=0A= $just_save_results =3D (strtolower($user_input[0]) =3D=3D 's');=0A= }=0A= =0A= if ($just_save_results || !getenv('NO_INTERACTION')) {=0A= if ($just_save_results || strlen(trim($user_input)) =3D=3D 0 || = strtolower($user_input[0]) =3D=3D 'y') {=0A= /*=0A= * Collect information about the host system for our report=0A= * Fetch phpinfo() output so that we can see the PHP enviroment=0A= * Make an archive of all the failed tests=0A= * Send an email=0A= */=0A= if ($just_save_results) {=0A= $user_input =3D 's';=0A= }=0A= =0A= /* Ask the user to provide an email address, so that QA team can = contact the user */=0A= if (!strncasecmp($user_input, 'y', 1) || strlen(trim($user_input)) = =3D=3D 0) {=0A= echo "\nPlease enter your email address.\n(Your address will be = mangled so that it will not go out on any\nmailinglist in plain text): ";=0A= flush();=0A= $user_email =3D trim(fgets($fp, 1024));=0A= $user_email =3D str_replace("@", " at ", str_replace(".", " dot ", = $user_email));=0A= }=0A= =0A= $failed_tests_data =3D '';=0A= $sep =3D "\n" . str_repeat('=3D', 80) . "\n";=0A= $failed_tests_data .=3D $failed_test_summary . "\n";=0A= $failed_tests_data .=3D get_summary(true, false) . "\n";=0A= =0A= if ($sum_results['FAILED']) {=0A= =0A= foreach ($PHP_FAILED_TESTS['FAILED'] as $test_info) {=0A= $failed_tests_data .=3D $sep . $test_info['name'] . = $test_info['info'];=0A= $failed_tests_data .=3D $sep . = file_get_contents(realpath($test_info['output']));=0A= $failed_tests_data .=3D $sep . = file_get_contents(realpath($test_info['diff']));=0A= $failed_tests_data .=3D $sep . "\n\n";=0A= }=0A= =0A= $status =3D "failed";=0A= } else {=0A= $status =3D "success";=0A= }=0A= =0A= $failed_tests_data .=3D "\n" . $sep . 'BUILD ENVIRONMENT' . $sep;=0A= $failed_tests_data .=3D "OS:\n" . PHP_OS . " - " . php_uname() . = "\n\n";=0A= $ldd =3D $autoconf =3D $sys_libtool =3D $libtool =3D $compiler =3D = 'N/A';=0A= =0A= if (substr(PHP_OS, 0, 3) !=3D "WIN") {=0A= /* If PHP_AUTOCONF is set, use it; otherwise, use 'autoconf'. */=0A= if (getenv('PHP_AUTOCONF')) {=0A= $autoconf =3D shell_exec(getenv('PHP_AUTOCONF') . ' --version');=0A= } else {=0A= $autoconf =3D shell_exec('autoconf --version');=0A= }=0A= =0A= /* Always use the generated libtool - Mac OSX uses 'glibtool' */=0A= $libtool =3D shell_exec($CUR_DIR . '/libtool --version');=0A= =0A= /* Use shtool to find out if there is glibtool present (MacOSX) */=0A= $sys_libtool_path =3D shell_exec(__DIR__ . '/build/shtool path = glibtool libtool');=0A= =0A= if ($sys_libtool_path) {=0A= $sys_libtool =3D shell_exec(str_replace("\n", "", $sys_libtool_path) = . ' --version');=0A= }=0A= =0A= /* Try the most common flags for 'version' */=0A= $flags =3D array('-v', '-V', '--version');=0A= $cc_status=3D0;=0A= =0A= foreach($flags AS $flag) {=0A= system(getenv('CC')." $flag >/dev/null 2>&1", $cc_status);=0A= if ($cc_status =3D=3D 0) {=0A= $compiler =3D shell_exec(getenv('CC')." $flag 2>&1");=0A= break;=0A= }=0A= }=0A= =0A= $ldd =3D shell_exec("ldd $php 2>/dev/null");=0A= }=0A= =0A= $failed_tests_data .=3D "Autoconf:\n$autoconf\n";=0A= $failed_tests_data .=3D "Bundled Libtool:\n$libtool\n";=0A= $failed_tests_data .=3D "System Libtool:\n$sys_libtool\n";=0A= $failed_tests_data .=3D "Compiler:\n$compiler\n";=0A= $failed_tests_data .=3D "Bison:\n". @shell_exec('bison --version = 2>/dev/null'). "\n";=0A= $failed_tests_data .=3D "Libraries:\n$ldd\n";=0A= $failed_tests_data .=3D "\n";=0A= =0A= if (isset($user_email)) {=0A= $failed_tests_data .=3D "User's E-mail: " . $user_email."\n\n";=0A= }=0A= =0A= $failed_tests_data .=3D $sep . "PHPINFO" . $sep;=0A= $failed_tests_data .=3D shell_exec($php.' -dhtml_errors=3D0 -i');=0A= =0A= if ($just_save_results || !mail_qa_team($failed_tests_data, = $compression, $status)) {=0A= file_put_contents($output_file, $failed_tests_data);=0A= =0A= if (!$just_save_results) {=0A= echo "\nThe test script was unable to automatically send the report = to PHP's QA Team\n";=0A= }=0A= =0A= echo "Please send " . $output_file." to ".PHP_QA_EMAIL." manually, = thank you.\n";=0A= } else {=0A= fwrite($fp, "\nThank you for helping to make PHP better.\n");=0A= fclose($fp);=0A= }=0A= }=0A= }=0A= =0A= if (getenv('REPORT_EXIT_STATUS') =3D=3D 1 and $sum_results['FAILED']) {=0A= exit(1);=0A= }=0A= exit(0);=0A= =0A= //=0A= // Send Email to QA Team=0A= //=0A= =0A= function mail_qa_team($data, $compression, $status =3D false)=0A= {=0A= $url_bits =3D parse_url(QA_SUBMISSION_PAGE);=0A= =0A= if (empty($url_bits['port'])) {=0A= $url_bits['port'] =3D 80;=0A= }=0A= =0A= $data =3D "php_test_data=3D" . = urlencode(base64_encode(str_replace("\00", '[0x0]', $data)));=0A= $data_length =3D strlen($data);=0A= =0A= $fs =3D fsockopen($url_bits['host'], $url_bits['port'], $errno, = $errstr, 10);=0A= =0A= if (!$fs) {=0A= return false;=0A= }=0A= =0A= $php_version =3D urlencode(TESTED_PHP_VERSION);=0A= =0A= echo "\nPosting to {$url_bits['host']} {$url_bits['path']}\n";=0A= fwrite($fs, "POST " . = $url_bits['path']."?status=3D$status&version=3D$php_version = HTTP/1.1\r\n");=0A= fwrite($fs, "Host: " . $url_bits['host']."\r\n");=0A= fwrite($fs, "User-Agent: QA Browser 0.1\r\n");=0A= fwrite($fs, "Content-Type: application/x-www-form-urlencoded\r\n");=0A= fwrite($fs, "Content-Length: " . $data_length."\r\n\r\n");=0A= fwrite($fs, $data);=0A= fwrite($fs, "\r\n\r\n");=0A= fclose($fs);=0A= =0A= return 1;=0A= } =0A= =0A= =0A= //=0A= // Write the given text to a temporary file, and return the filename.=0A= //=0A= =0A= function save_text($filename, $text, $filename_copy =3D null)=0A= {=0A= global $DETAILED;=0A= =0A= if ($filename_copy && $filename_copy !=3D $filename) {=0A= if (@file_put_contents($filename_copy, $text) =3D=3D=3D false) {=0A= error("Cannot open file '" . $filename_copy . "' (save_text)");=0A= }=0A= }=0A= =0A= if (@file_put_contents($filename, $text) =3D=3D=3D false) {=0A= error("Cannot open file '" . $filename . "' (save_text)");=0A= }=0A= =0A= if (1 < $DETAILED) echo "=0A= FILE $filename {{{=0A= $text=0A= }}} =0A= ";=0A= }=0A= =0A= //=0A= // Write an error in a format recognizable to Emacs or MSVC.=0A= //=0A= =0A= function error_report($testname, $logname, $tested) =0A= {=0A= $testname =3D realpath($testname);=0A= $logname =3D realpath($logname);=0A= =0A= switch (strtoupper(getenv('TEST_PHP_ERROR_STYLE'))) {=0A= case 'MSVC':=0A= echo $testname . "(1) : $tested\n";=0A= echo $logname . "(1) : $tested\n";=0A= break;=0A= case 'EMACS':=0A= echo $testname . ":1: $tested\n";=0A= echo $logname . ":1: $tested\n";=0A= break;=0A= }=0A= }=0A= =0A= function system_with_timeout($commandline, $env =3D null, $stdin =3D = null)=0A= {=0A= global $leak_check;=0A= =0A= $data =3D "";=0A= $proc =3D proc_open($commandline, array(=0A= 0 =3D> array('pipe', 'r'),=0A= 1 =3D> array('pipe', 'w'),=0A= 2 =3D> array('pipe', 'w')=0A= ), $pipes, null, $env, array("suppress_errors" =3D> true, = "binary_pipes" =3D> true));=0A= =0A= if (!$proc) {=0A= return false;=0A= }=0A= =0A= if (!is_null($stdin)) {=0A= @fwrite($pipes[0], $stdin);=0A= }=0A= =0A= fclose($pipes[0]);=0A= =0A= while (true) {=0A= /* hide errors from interrupted syscalls */=0A= $r =3D $pipes;=0A= $w =3D null;=0A= $e =3D null;=0A= $n =3D @stream_select($r, $w, $e, $leak_check ? 300 : 60);=0A= =0A= if ($n =3D=3D=3D false) {=0A= break;=0A= } else if ($n =3D=3D=3D 0) {=0A= /* timed out */=0A= $data .=3D "\n ** ERROR: process timed out **\n";=0A= proc_terminate($proc);=0A= return $data;=0A= } else if ($n > 0) {=0A= $line =3D fread($pipes[1], 8192);=0A= =0A= if ($line =3D=3D=3D false) {=0A= /* EOF */=0A= break;=0A= }=0A= =0A= if (is_binary($line)) {=0A= $data =3D (binary)$data;=0A= }=0A= =0A= $data .=3D $line;=0A= }=0A= }=0A= =0A= $stat =3D proc_get_status($proc);=0A= =0A= if ($stat['signaled']) {=0A= $data .=3D "\nTermsig=3D" . $stat['stopsig'];=0A= }=0A= =0A= $code =3D proc_close($proc);=0A= return $data;=0A= }=0A= =0A= function run_all_tests($test_files, $env, $redir_tested =3D null)=0A= {=0A= global $test_results, $failed_tests_file, $php, $test_cnt, $test_idx;=0A= =0A= foreach($test_files as $name) {=0A= =0A= if (is_array($name)) {=0A= $index =3D "# $name[1]: $name[0]";=0A= =0A= if ($redir_tested) {=0A= $name =3D $name[0];=0A= }=0A= }=0A= else if ($redir_tested) {=0A= $index =3D "# $redir_tested: $name";=0A= } else {=0A= $index =3D $name;=0A= }=0A= =0A= $test_idx++;=0A= $result =3D run_test($php, $name, $env);=0A= =0A= if (!is_array($name) && $result !=3D 'REDIR') {=0A= $test_results[$index] =3D $result;=0A= =0A= if ($failed_tests_file && ($result=3D=3D 'XFAILED' || $result =3D=3D = 'FAILED' || $result =3D=3D 'WARNED' || $result =3D=3D 'LEAKED')) {=0A= fwrite($failed_tests_file, "$index\n");=0A= }=0A= }=0A= }=0A= }=0A= =0A= //=0A= // Show file or result block=0A= //=0A= function show_file_block($file, $block, $section =3D null)=0A= {=0A= global $cfg;=0A= =0A= if ($cfg['show'][$file]) {=0A= =0A= if (is_null($section)) {=0A= $section =3D strtoupper($file);=0A= }=0A= =0A= echo "\n=3D=3D=3D=3D=3D=3D=3D=3D" . = $section."=3D=3D=3D=3D=3D=3D=3D=3D\n";=0A= echo rtrim($block);=0A= echo "\n=3D=3D=3D=3D=3D=3D=3D=3DDONE=3D=3D=3D=3D=3D=3D=3D=3D\n";=0A= }=0A= }=0A= =0A= //=0A= // Run an individual test case.=0A= //=0A= function run_test($php, $file, $env)=0A= {=0A= global $log_format, $info_params, $ini_overwrites, $cwd, = $PHP_FAILED_TESTS;=0A= global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx;=0A= global $leak_check, $temp_source, $temp_target, $cfg, $environment;=0A= global $no_clean;=0A= global $valgrind_version;=0A= =0A= $temp_filenames =3D null;=0A= $org_file =3D $file;=0A= =0A= if (isset($env['TEST_PHP_CGI_EXECUTABLE'])) {=0A= $php_cgi =3D $env['TEST_PHP_CGI_EXECUTABLE'];=0A= }=0A= =0A= if (is_array($file)) {=0A= $file =3D $file[0];=0A= }=0A= =0A= if ($DETAILED) echo "=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= TEST $file=0A= ";=0A= =0A= // Load the sections of the test file.=0A= $section_text =3D array('TEST' =3D> '');=0A= =0A= $fp =3D fopen($file, "rt") or error("Cannot open test file: $file");=0A= $borked =3D false;=0A= $bork_info =3D '';=0A= =0A= if (!feof($fp)) {=0A= $line =3D fgets($fp);=0A= =0A= if ($line =3D=3D=3D false) {=0A= $bork_info =3D "cannot read test";=0A= $borked =3D true;=0A= }=0A= } else {=0A= $bork_info =3D "empty test";=0A= $borked =3D true;=0A= }=0A= =0A= if (!$borked && strncmp('--TEST--', $line, 8)) {=0A= $bork_info =3D "tests must start with --TEST--";=0A= $borked =3D true;=0A= }=0A= =0A= $section =3D 'TEST';=0A= $secfile =3D false;=0A= $secdone =3D false;=0A= =0A= while (!feof($fp)) {=0A= $line =3D fgets($fp);=0A= =0A= // Match the beginning of a section.=0A= if (preg_match('/^--([_A-Z]+)--/', $line, $r)) {=0A= $section =3D $r[1];=0A= =0A= if (isset($section_text[$section])) {=0A= $bork_info =3D "duplicated $section section";=0A= $borked =3D true;=0A= }=0A= =0A= $section_text[$section] =3D '';=0A= $secfile =3D $section =3D=3D 'FILE' || $section =3D=3D 'FILEEOF' || = $section =3D=3D 'FILE_EXTERNAL';=0A= $secdone =3D false;=0A= continue;=0A= }=0A= =0A= // Add to the section text.=0A= if (!$secdone) {=0A= $section_text[$section] .=3D $line;=0A= }=0A= =0A= // End of actual test?=0A= if ($secfile && preg_match('/^=3D=3D=3DDONE=3D=3D=3D\s*$/', $line)) {=0A= $secdone =3D true;=0A= }=0A= }=0A= =0A= // the redirect section allows a set of tests to be reused outside of=0A= // a given test dir=0A= if (!$borked) {=0A= if (@count($section_text['REDIRECTTEST']) =3D=3D 1) {=0A= =0A= if ($IN_REDIRECT) {=0A= $borked =3D true;=0A= $bork_info =3D "Can't redirect a test from within a redirected test";=0A= } else {=0A= $borked =3D false;=0A= }=0A= =0A= } else {=0A= =0A= if (@count($section_text['FILE']) + @count($section_text['FILEEOF']) = + @count($section_text['FILE_EXTERNAL']) !=3D 1) {=0A= $bork_info =3D "missing section --FILE--";=0A= $borked =3D true;=0A= }=0A= =0A= if (@count($section_text['FILEEOF']) =3D=3D 1) {=0A= $section_text['FILE'] =3D preg_replace("/[\r\n]+$/", '', = $section_text['FILEEOF']);=0A= unset($section_text['FILEEOF']);=0A= }=0A= =0A= if (@count($section_text['FILE_EXTERNAL']) =3D=3D 1) {=0A= // don't allow tests to retrieve files from anywhere but this = subdirectory=0A= $section_text['FILE_EXTERNAL'] =3D dirname($file) . '/' . = trim(str_replace('..', '', $section_text['FILE_EXTERNAL']));=0A= =0A= if (@file_exists($section_text['FILE_EXTERNAL'])) {=0A= $section_text['FILE'] =3D = file_get_contents($section_text['FILE_EXTERNAL']);=0A= unset($section_text['FILE_EXTERNAL']);=0A= } else {=0A= $bork_info =3D "could not load --FILE_EXTERNAL-- " . dirname($file) = . '/' . trim($section_text['FILE_EXTERNAL']);=0A= $borked =3D true;=0A= }=0A= }=0A= =0A= if ((@count($section_text['EXPECT']) + = @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX'])) = !=3D 1) {=0A= $bork_info =3D "missing section --EXPECT--, --EXPECTF-- or = --EXPECTREGEX--";=0A= $borked =3D true;=0A= }=0A= }=0A= }=0A= fclose($fp);=0A= =0A= $shortname =3D str_replace($cwd.'/', '', $file);=0A= $tested_file =3D $shortname;=0A= =0A= if ($borked) {=0A= show_result("BORK", $bork_info, $tested_file);=0A= $PHP_FAILED_TESTS['BORKED'][] =3D array (=0A= 'name' =3D> $file,=0A= 'test_name' =3D> '',=0A= 'output' =3D> '',=0A= 'diff' =3D> '',=0A= 'info' =3D> "$bork_info [$file]",=0A= );=0A= return 'BORKED';=0A= }=0A= =0A= $tested =3D trim($section_text['TEST']);=0A= =0A= /* For GET/POST tests, check if cgi sapi is available and if it is, use = it. */=0A= if (!empty($section_text['GET']) || !empty($section_text['POST']) || = !empty($section_text['POST_RAW']) || !empty($section_text['COOKIE']) || = !empty($section_text['EXPECTHEADERS'])) {=0A= =0A= if (isset($php_cgi)) {=0A= $old_php =3D $php;=0A= $php =3D $php_cgi .' -C ';=0A= =0A= } else if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) = ."/php-cgi.exe")) {=0A= $old_php =3D $php;=0A= $php =3D realpath(dirname($php) ."/php-cgi.exe") .' -C ';=0A= =0A= } else {=0A= =0A= if (file_exists(dirname($php)."/../../sapi/cgi/php-cgi")) {=0A= $old_php =3D $php;=0A= $php =3D realpath(dirname($php)."/../../sapi/cgi/php-cgi") . ' -C ';=0A= } else if (file_exists("./sapi/cgi/php-cgi")) {=0A= $old_php =3D $php;=0A= $php =3D realpath("./sapi/cgi/php-cgi") . ' -C ';=0A= } else {=0A= show_result("SKIP", $tested, $tested_file, "reason: CGI not = available");=0A= return 'SKIPPED';=0A= }=0A= }=0A= }=0A= =0A= show_test($test_idx, $shortname);=0A= =0A= if (is_array($IN_REDIRECT)) {=0A= $temp_dir =3D $test_dir =3D $IN_REDIRECT['dir'];=0A= } else {=0A= $temp_dir =3D $test_dir =3D realpath(dirname($file));=0A= }=0A= =0A= if ($temp_source && $temp_target) {=0A= $temp_dir =3D str_replace($temp_source, $temp_target, $temp_dir);=0A= }=0A= =0A= $diff_filename =3D $temp_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'diff';=0A= $log_filename =3D $temp_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'log';=0A= $exp_filename =3D $temp_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'exp';=0A= $output_filename =3D $temp_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'out';=0A= $memcheck_filename =3D $temp_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'mem';=0A= $temp_file =3D $temp_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'php';=0A= $test_file =3D $test_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'php';=0A= $temp_skipif =3D $temp_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'skip.php';=0A= $test_skipif =3D $test_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'skip.php';=0A= $temp_clean =3D $temp_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'clean.php';=0A= $test_clean =3D $test_dir . DIRECTORY_SEPARATOR . = basename($file, 'phpt') . 'clean.php';=0A= $tmp_post =3D $temp_dir . DIRECTORY_SEPARATOR . = uniqid('/phpt.');=0A= $tmp_relative_file =3D str_replace(__DIR__ . DIRECTORY_SEPARATOR, '', = $test_file) . 't';=0A= =0A= if ($temp_source && $temp_target) {=0A= $temp_skipif .=3D 's';=0A= $temp_file .=3D 's';=0A= $temp_clean .=3D 's';=0A= $copy_file =3D $temp_dir . DIRECTORY_SEPARATOR . = basename(is_array($file) ? $file[1] : $file) . '.phps';=0A= =0A= if (!is_dir(dirname($copy_file))) {=0A= @mkdir(dirname($copy_file), 0777, true) or error("Cannot create = output directory - " . dirname($copy_file));=0A= }=0A= =0A= if (isset($section_text['FILE'])) {=0A= save_text($copy_file, $section_text['FILE']);=0A= }=0A= =0A= $temp_filenames =3D array(=0A= 'file' =3D> $copy_file,=0A= 'diff' =3D> $diff_filename,=0A= 'log' =3D> $log_filename,=0A= 'exp' =3D> $exp_filename,=0A= 'out' =3D> $output_filename,=0A= 'mem' =3D> $memcheck_filename,=0A= 'php' =3D> $temp_file,=0A= 'skip' =3D> $temp_skipif,=0A= 'clean'=3D> $temp_clean);=0A= }=0A= =0A= if (is_array($IN_REDIRECT)) {=0A= $tested =3D $IN_REDIRECT['prefix'] . ' ' . trim($section_text['TEST']);=0A= $tested_file =3D $tmp_relative_file;=0A= $section_text['FILE'] =3D "# original source file: $shortname\n" . = $section_text['FILE'];=0A= }=0A= =0A= // unlink old test results=0A= @unlink($diff_filename);=0A= @unlink($log_filename);=0A= @unlink($exp_filename);=0A= @unlink($output_filename);=0A= @unlink($memcheck_filename);=0A= @unlink($temp_file);=0A= @unlink($test_file);=0A= @unlink($temp_skipif);=0A= @unlink($test_skipif);=0A= @unlink($tmp_post);=0A= @unlink($temp_clean);=0A= @unlink($test_clean);=0A= =0A= // Reset environment from any previous test.=0A= $env['REDIRECT_STATUS'] =3D '';=0A= $env['QUERY_STRING'] =3D '';=0A= $env['PATH_TRANSLATED'] =3D '';=0A= $env['SCRIPT_FILENAME'] =3D '';=0A= $env['REQUEST_METHOD'] =3D '';=0A= $env['CONTENT_TYPE'] =3D '';=0A= $env['CONTENT_LENGTH'] =3D '';=0A= =0A= if (!empty($section_text['ENV'])) {=0A= =0A= foreach(explode("\n", trim($section_text['ENV'])) as $e) {=0A= $e =3D explode('=3D', trim($e),2);=0A= =0A= if (!empty($e[0]) && isset($e[1])) {=0A= $env[$e[0]] =3D $e[1];=0A= }=0A= }=0A= }=0A= =0A= // Default ini settings=0A= $ini_settings =3D array();=0A= // additional ini overwrites=0A= //$ini_overwrites[] =3D 'setting=3Dvalue';=0A= settings2array($ini_overwrites, $ini_settings);=0A= // Any special ini settings =0A= // these may overwrite the test defaults...=0A= if (array_key_exists('INI', $section_text)) {=0A= if (strpos($section_text['INI'], '{PWD}') !=3D=3D false) {=0A= $section_text['INI'] =3D str_replace('{PWD}', dirname($file), = $section_text['INI']);=0A= }=0A= settings2array(preg_split( "/[\n\r]+/", $section_text['INI']), = $ini_settings);=0A= }=0A= =0A= settings2params($ini_settings);=0A= =0A= // Check if test should be skipped.=0A= $info =3D '';=0A= $warn =3D false;=0A= =0A= if (array_key_exists('SKIPIF', $section_text)) {=0A= =0A= if (trim($section_text['SKIPIF'])) {=0A= show_file_block('skip', $section_text['SKIPIF']);=0A= save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif);=0A= $extra =3D substr(PHP_OS, 0, 3) !=3D=3D "WIN" ?=0A= "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; = unset SCRIPT_FILENAME; unset REQUEST_METHOD;": "";=0A= =0A= if ($leak_check) {=0A= $env['USE_ZEND_ALLOC'] =3D '0';=0A= } else {=0A= $env['USE_ZEND_ALLOC'] =3D '1';=0A= }=0A= =0A= $output =3D system_with_timeout("$extra $php $pass_options -q = $ini_settings $test_skipif", $env);=0A= =0A= if (!$cfg['keep']['skip']) {=0A= @unlink($test_skipif);=0A= }=0A= =0A= if (!strncasecmp('skip', ltrim($output), 4)) {=0A= =0A= if (preg_match('/^\s*skip\s*(.+)\s*/i', $output, $m)) {=0A= show_result("SKIP", $tested, $tested_file, "reason: $m[1]", = $temp_filenames);=0A= } else {=0A= show_result("SKIP", $tested, $tested_file, '', $temp_filenames);=0A= }=0A= =0A= if (isset($old_php)) {=0A= $php =3D $old_php;=0A= }=0A= =0A= if (!$cfg['keep']['skip']) {=0A= @unlink($test_skipif);=0A= }=0A= =0A= return 'SKIPPED';=0A= }=0A= =0A= if (!strncasecmp('info', ltrim($output), 4)) {=0A= if (preg_match('/^\s*info\s*(.+)\s*/i', $output, $m)) {=0A= $info =3D " (info: $m[1])";=0A= }=0A= }=0A= =0A= if (!strncasecmp('warn', ltrim($output), 4)) {=0A= if (preg_match('/^\s*warn\s*(.+)\s*/i', $output, $m)) {=0A= $warn =3D true; /* only if there is a reason */=0A= $info =3D " (warn: $m[1])";=0A= }=0A= }=0A= }=0A= }=0A= =0A= if (@count($section_text['REDIRECTTEST']) =3D=3D 1) {=0A= $test_files =3D array();=0A= =0A= $IN_REDIRECT =3D eval($section_text['REDIRECTTEST']);=0A= $IN_REDIRECT['via'] =3D "via [$shortname]\n\t";=0A= $IN_REDIRECT['dir'] =3D realpath(dirname($file));=0A= $IN_REDIRECT['prefix'] =3D trim($section_text['TEST']);=0A= =0A= if (@count($IN_REDIRECT['TESTS']) =3D=3D 1) {=0A= =0A= if (is_array($org_file)) {=0A= $test_files[] =3D $org_file[1];=0A= } else {=0A= $GLOBALS['test_files'] =3D $test_files;=0A= find_files($IN_REDIRECT['TESTS']);=0A= =0A= foreach($GLOBALS['test_files'] as $f) {=0A= $test_files[] =3D array($f, $file);=0A= }=0A= }=0A= =0A= $test_cnt +=3D (count($test_files) - 1);=0A= $test_idx--;=0A= show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file);=0A= =0A= // set up environment=0A= $redirenv =3D array_merge($environment, $IN_REDIRECT['ENV']);=0A= $redirenv['REDIR_TEST_DIR'] =3D realpath($IN_REDIRECT['TESTS']) . = DIRECTORY_SEPARATOR;=0A= =0A= usort($test_files, "test_sort");=0A= run_all_tests($test_files, $redirenv, $tested);=0A= show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file);=0A= =0A= // a redirected test never fails=0A= $IN_REDIRECT =3D false;=0A= return 'REDIR';=0A= =0A= } else {=0A= =0A= $bork_info =3D "Redirect info must contain exactly one TEST string to = be used as redirect directory.";=0A= show_result("BORK", $bork_info, '', $temp_filenames);=0A= $PHP_FAILED_TESTS['BORKED'][] =3D array (=0A= 'name' =3D> $file,=0A= 'test_name' =3D> '',=0A= 'output' =3D> '',=0A= 'diff' =3D> '',=0A= 'info' =3D> "$bork_info [$file]",=0A= );=0A= }=0A= }=0A= =0A= if (is_array($org_file) || @count($section_text['REDIRECTTEST']) =3D=3D = 1) {=0A= =0A= if (is_array($org_file)) {=0A= $file =3D $org_file[0];=0A= }=0A= =0A= $bork_info =3D "Redirected test did not contain redirection info";=0A= show_result("BORK", $bork_info, '', $temp_filenames);=0A= $PHP_FAILED_TESTS['BORKED'][] =3D array (=0A= 'name' =3D> $file,=0A= 'test_name' =3D> '',=0A= 'output' =3D> '',=0A= 'diff' =3D> '',=0A= 'info' =3D> "$bork_info [$file]",=0A= );=0A= return 'BORKED';=0A= }=0A= =0A= // We've satisfied the preconditions - run the test!=0A= show_file_block('php', $section_text['FILE'], 'TEST');=0A= save_text($test_file, $section_text['FILE'], $temp_file);=0A= =0A= if (array_key_exists('GET', $section_text)) {=0A= $query_string =3D trim($section_text['GET']);=0A= } else {=0A= $query_string =3D '';=0A= }=0A= =0A= $env['REDIRECT_STATUS'] =3D '1';=0A= $env['QUERY_STRING'] =3D $query_string;=0A= $env['PATH_TRANSLATED'] =3D $test_file;=0A= $env['SCRIPT_FILENAME'] =3D $test_file;=0A= =0A= if (array_key_exists('COOKIE', $section_text)) {=0A= $env['HTTP_COOKIE'] =3D trim($section_text['COOKIE']);=0A= } else {=0A= $env['HTTP_COOKIE'] =3D '';=0A= }=0A= =0A= $args =3D isset($section_text['ARGS']) ? ' -- ' . $section_text['ARGS'] = : '';=0A= =0A= if (array_key_exists('POST_RAW', $section_text) && = !empty($section_text['POST_RAW'])) {=0A= =0A= $post =3D trim($section_text['POST_RAW']);=0A= $raw_lines =3D explode("\n", $post);=0A= =0A= $request =3D '';=0A= $started =3D false;=0A= =0A= foreach ($raw_lines as $line) {=0A= =0A= if (empty($env['CONTENT_TYPE']) && = preg_match('/^Content-Type:(.*)/i', $line, $res)) {=0A= $env['CONTENT_TYPE'] =3D trim(str_replace("\r", '', $res[1]));=0A= continue;=0A= }=0A= =0A= if ($started) {=0A= $request .=3D "\n";=0A= }=0A= =0A= $started =3D true;=0A= $request .=3D $line;=0A= }=0A= =0A= $env['CONTENT_LENGTH'] =3D strlen($request);=0A= $env['REQUEST_METHOD'] =3D 'POST';=0A= =0A= if (empty($request)) {=0A= return 'BORKED';=0A= }=0A= =0A= save_text($tmp_post, $request);=0A= $cmd =3D "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < = $tmp_post";=0A= =0A= } elseif (array_key_exists('POST', $section_text) && = !empty($section_text['POST'])) {=0A= =0A= $post =3D trim($section_text['POST']);=0A= =0A= if (array_key_exists('GZIP_POST', $section_text) && = function_exists('gzencode')) {=0A= $post =3D gzencode($post, 9, FORCE_GZIP);=0A= $env['HTTP_CONTENT_ENCODING'] =3D 'gzip';=0A= } else if (array_key_exists('DEFLATE_POST', $section_text) && = function_exists('gzcompress')) {=0A= $post =3D gzcompress($post, 9);=0A= $env['HTTP_CONTENT_ENCODING'] =3D 'deflate';=0A= }=0A= =0A= save_text($tmp_post, $post);=0A= $content_length =3D strlen($post);=0A= =0A= $env['REQUEST_METHOD'] =3D 'POST';=0A= $env['CONTENT_TYPE'] =3D 'application/x-www-form-urlencoded';=0A= $env['CONTENT_LENGTH'] =3D $content_length;=0A= =0A= $cmd =3D "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < = $tmp_post";=0A= =0A= } else {=0A= =0A= $env['REQUEST_METHOD'] =3D 'GET';=0A= $env['CONTENT_TYPE'] =3D '';=0A= $env['CONTENT_LENGTH'] =3D '';=0A= =0A= $cmd =3D "$php$pass_options$ini_settings -f \"$test_file\" $args 2>&1";=0A= }=0A= =0A= if ($leak_check) {=0A= $env['USE_ZEND_ALLOC'] =3D '0';=0A= =0A= if ($valgrind_version >=3D 330) {=0A= /* valgrind 3.3.0+ doesn't have --log-file-exactly option */=0A= $cmd =3D "valgrind -q --tool=3Dmemcheck --trace-children=3Dyes = --log-file=3D$memcheck_filename $cmd";=0A= } else {=0A= $cmd =3D "valgrind -q --tool=3Dmemcheck --trace-children=3Dyes = --log-file-exactly=3D$memcheck_filename $cmd";=0A= }=0A= =0A= } else {=0A= $env['USE_ZEND_ALLOC'] =3D '1';=0A= }=0A= =0A= if ($DETAILED) echo "=0A= CONTENT_LENGTH =3D " . $env['CONTENT_LENGTH'] . "=0A= CONTENT_TYPE =3D " . $env['CONTENT_TYPE'] . "=0A= PATH_TRANSLATED =3D " . $env['PATH_TRANSLATED'] . "=0A= QUERY_STRING =3D " . $env['QUERY_STRING'] . "=0A= REDIRECT_STATUS =3D " . $env['REDIRECT_STATUS'] . "=0A= REQUEST_METHOD =3D " . $env['REQUEST_METHOD'] . "=0A= SCRIPT_FILENAME =3D " . $env['SCRIPT_FILENAME'] . "=0A= HTTP_COOKIE =3D " . $env['HTTP_COOKIE'] . "=0A= COMMAND $cmd=0A= ";=0A= =0A= $out =3D system_with_timeout($cmd, $env, isset($section_text['STDIN']) = ? $section_text['STDIN'] : null);=0A= =0A= if (array_key_exists('CLEAN', $section_text) && (!$no_clean || = $cfg['keep']['clean'])) {=0A= =0A= if (trim($section_text['CLEAN'])) {=0A= show_file_block('clean', $section_text['CLEAN']);=0A= save_text($test_clean, trim($section_text['CLEAN']), $temp_clean);=0A= =0A= if (!$no_clean) {=0A= $clean_params =3D array();=0A= settings2array($ini_overwrites, $clean_params);=0A= settings2params($clean_params);=0A= $extra =3D substr(PHP_OS, 0, 3) !=3D=3D "WIN" ?=0A= "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; = unset SCRIPT_FILENAME; unset REQUEST_METHOD;": "";=0A= system_with_timeout("$extra $php $pass_options -q $clean_params = $test_clean", $env);=0A= }=0A= =0A= if (!$cfg['keep']['clean']) {=0A= @unlink($test_clean);=0A= }=0A= }=0A= }=0A= =0A= @unlink($tmp_post);=0A= =0A= $leaked =3D false;=0A= $passed =3D false;=0A= =0A= if ($leak_check) { // leak check=0A= $leaked =3D @filesize($memcheck_filename) > 0;=0A= =0A= if (!$leaked) {=0A= @unlink($memcheck_filename);=0A= }=0A= }=0A= =0A= // Does the output match what is expected?=0A= if (is_binary($out)) {=0A= $output =3D preg_replace(b'/\r\n/', b"\n", trim($out));=0A= } else {=0A= $output =3D str_replace("\r\n", "\n", trim($out));=0A= }=0A= =0A= /* when using CGI, strip the headers from the output */=0A= $headers =3D "";=0A= =0A= if (isset($old_php) && preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, = $match)) {=0A= $output =3D trim($match[2]);=0A= $rh =3D preg_split("/[\n\r]+/", $match[1]);=0A= $headers =3D array();=0A= =0A= foreach ($rh as $line) {=0A= if (strpos($line, ':') !=3D=3D false) {=0A= $line =3D explode(':', $line, 2);=0A= $headers[trim($line[0])] =3D trim($line[1]);=0A= }=0A= }=0A= }=0A= =0A= $failed_headers =3D false;=0A= =0A= if (isset($section_text['EXPECTHEADERS'])) {=0A= $want =3D array();=0A= $wanted_headers =3D array();=0A= $lines =3D preg_split("/[\n\r]+/", $section_text['EXPECTHEADERS']);=0A= =0A= foreach($lines as $line) {=0A= if (strpos($line, ':') !=3D=3D false) {=0A= $line =3D explode(':', $line, 2);=0A= $want[trim($line[0])] =3D trim($line[1]);=0A= $wanted_headers[] =3D trim($line[0]) . ': ' . trim($line[1]);=0A= }=0A= }=0A= =0A= $org_headers =3D $headers;=0A= $headers =3D array();=0A= $output_headers =3D array();=0A= =0A= foreach($want as $k =3D> $v) {=0A= =0A= if (isset($org_headers[$k])) {=0A= $headers =3D $org_headers[$k];=0A= $output_headers[] =3D $k . ': ' . $org_headers[$k];=0A= }=0A= =0A= if (!isset($org_headers[$k]) || $org_headers[$k] !=3D $v) {=0A= $failed_headers =3D true;=0A= }=0A= }=0A= =0A= ksort($wanted_headers);=0A= $wanted_headers =3D join("\n", $wanted_headers);=0A= ksort($output_headers);=0A= $output_headers =3D join("\n", $output_headers);=0A= }=0A= =0A= show_file_block('out', $output);=0A= =0A= if (isset($section_text['EXPECTF']) || = isset($section_text['EXPECTREGEX'])) {=0A= =0A= if (isset($section_text['EXPECTF'])) {=0A= $wanted =3D trim($section_text['EXPECTF']);=0A= } else {=0A= $wanted =3D trim($section_text['EXPECTREGEX']);=0A= }=0A= =0A= show_file_block('exp', $wanted);=0A= $wanted_re =3D preg_replace('/\r\n/',"\n", $wanted);=0A= =0A= if (isset($section_text['EXPECTF'])) {=0A= $wanted_re =3D preg_quote($wanted_re, '/');=0A= // Stick to basics=0A= $wanted_re =3D str_replace('%e', '\\' . DIRECTORY_SEPARATOR, = $wanted_re);=0A= $wanted_re =3D str_replace('%s', '[^\r\n]+', $wanted_re);=0A= $wanted_re =3D str_replace('%a', '.+', $wanted_re);=0A= $wanted_re =3D str_replace('%w', '\s*', $wanted_re);=0A= $wanted_re =3D str_replace('%i', '[+-]?\d+', $wanted_re);=0A= $wanted_re =3D str_replace('%d', '\d+', $wanted_re);=0A= $wanted_re =3D str_replace('%x', '[0-9a-fA-F]+', $wanted_re);=0A= $wanted_re =3D str_replace('%f', = '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', $wanted_re);=0A= $wanted_re =3D str_replace('%c', '.', $wanted_re);=0A= // %f allows two points "-.0.0" but that is the best *simple* = expression=0A= }=0A= /* DEBUG YOUR REGEX HERE=0A= var_dump($wanted_re);=0A= print(str_repeat('=3D', 80) . "\n");=0A= var_dump($output);=0A= */=0A= if (is_binary($output)) {=0A= if (preg_match((binary)"/^$wanted_re\$/s", $output)) {=0A= $passed =3D true;=0A= }=0A= } else {=0A= if (preg_match("/^$wanted_re\$/s", $output)) {=0A= $passed =3D true;=0A= }=0A= }=0A= =0A= if ($passed) {=0A= if (!$cfg['keep']['php']) {=0A= @unlink($test_file);=0A= }=0A= =0A= if (isset($old_php)) {=0A= $php =3D $old_php;=0A= }=0A= =0A= if (!$leaked && !$failed_headers) {=0A= show_result("PASS", $tested, $tested_file, '', $temp_filenames);=0A= return 'PASSED';=0A= }=0A= }=0A= =0A= } else {=0A= =0A= $wanted =3D trim($section_text['EXPECT']);=0A= =0A= if (is_binary($output)) {=0A= $wanted =3D preg_replace(b'/\r\n/', b"\n", (binary)$wanted);=0A= } else {=0A= $wanted =3D preg_replace('/\r\n/', "\n", (binary)$wanted);=0A= }=0A= =0A= show_file_block('exp', $wanted);=0A= =0A= // compare and leave on success=0A= if (!strcmp($output, $wanted)) {=0A= $passed =3D true;=0A= =0A= if (!$cfg['keep']['php']) {=0A= @unlink($test_file);=0A= }=0A= =0A= if (isset($old_php)) {=0A= $php =3D $old_php;=0A= }=0A= =0A= if (!$leaked && !$failed_headers) {=0A= show_result("PASS", $tested, $tested_file, '', $temp_filenames);=0A= return 'PASSED';=0A= }=0A= }=0A= =0A= $wanted_re =3D null;=0A= }=0A= =0A= // Test failed so we need to report details.=0A= if ($failed_headers) {=0A= $passed =3D false;=0A= $wanted =3D $wanted_headers . "\n--HEADERS--\n" . $wanted;=0A= $output =3D $output_headers . "\n--HEADERS--\n" . $output;=0A= =0A= if (isset($wanted_re)) {=0A= $wanted_re =3D preg_quote($wanted_headers . "\n--HEADERS--\n", '/') . = $wanted_re;=0A= }=0A= }=0A= =0A= if ($leaked) {=0A= $restype[] =3D 'LEAK';=0A= }=0A= =0A= if ($warn) {=0A= $restype[] =3D 'WARN';=0A= }=0A= =0A= if (!$passed) {=0A= if (isset($section_text['XFAIL'])) {=0A= $restype[] =3D 'XFAIL';=0A= } else {=0A= $restype[] =3D 'FAIL';=0A= }=0A= }=0A= =0A= if (!$passed) {=0A= =0A= // write .exp=0A= if (strpos($log_format, 'E') !=3D=3D false && = file_put_contents($exp_filename, $wanted) =3D=3D=3D false) {=0A= error("Cannot create expected test output - $exp_filename");=0A= }=0A= =0A= // write .out=0A= if (strpos($log_format, 'O') !=3D=3D false && = file_put_contents($output_filename, $output) =3D=3D=3D false) {=0A= error("Cannot create test output - $output_filename");=0A= }=0A= =0A= // write .diff=0A= $diff =3D generate_diff($wanted, $wanted_re, $output);=0A= show_file_block('diff', $diff);=0A= =0A= if (strpos($log_format, 'D') !=3D=3D false && = file_put_contents($diff_filename, $diff) =3D=3D=3D false) {=0A= error("Cannot create test diff - $diff_filename");=0A= }=0A= =0A= // write .log=0A= if (is_binary($output)) {=0A= $content =3D b"=0A= ---- EXPECTED OUTPUT=0A= $wanted=0A= ---- ACTUAL OUTPUT=0A= $output=0A= ---- FAILED=0A= ";=0A= } else {=0A= $content =3D "=0A= ---- EXPECTED OUTPUT=0A= $wanted=0A= ---- ACTUAL OUTPUT=0A= $output=0A= ---- FAILED=0A= ";=0A= }=0A= =0A= if (strpos($log_format, 'L') !=3D=3D false && = file_put_contents($log_filename, $content) =3D=3D=3D false) {=0A= error("Cannot create test log - $log_filename");=0A= error_report($file, $log_filename, $tested);=0A= }=0A= }=0A= =0A= show_result(implode('&', $restype), $tested, $tested_file, $info, = $temp_filenames);=0A= =0A= foreach ($restype as $type) {=0A= $PHP_FAILED_TESTS[$type.'ED'][] =3D array (=0A= 'name' =3D> $file,=0A= 'test_name' =3D> (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : = '') . $tested . " [$tested_file]",=0A= 'output' =3D> $output_filename,=0A= 'diff' =3D> $diff_filename,=0A= 'info' =3D> $info,=0A= );=0A= }=0A= =0A= if (isset($old_php)) {=0A= $php =3D $old_php;=0A= }=0A= =0A= return $restype[0].'ED';=0A= }=0A= =0A= function comp_line($l1, $l2, $is_reg)=0A= {=0A= if ($is_reg) {=0A= =0A= if (is_binary($l2)) {=0A= return preg_match((binary)"/^$l1\$/s", (binary)$l2);=0A= }=0A= =0A= return preg_match("/^$l1$/s", $l2);=0A= =0A= } else {=0A= =0A= if (is_binary($l2)) {=0A= return !strcmp((binary)$l1, (binary)$l2);=0A= }=0A= =0A= return !strcmp($l1, $l2);=0A= }=0A= }=0A= =0A= function count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $idx2, $cnt1, = $cnt2, $steps)=0A= {=0A= $equal =3D 0;=0A= =0A= while ($idx1 < $cnt1 && $idx2 < $cnt2 && comp_line($ar1[$idx1], = $ar2[$idx2], $is_reg)) {=0A= $idx1++;=0A= $idx2++;=0A= $equal++;=0A= $steps--;=0A= }=0A= if (--$steps > 0) {=0A= $eq1 =3D 0;=0A= $st =3D $steps / 2;=0A= =0A= for ($ofs1 =3D $idx1 + 1; $ofs1 < $cnt1 && $st-- > 0; $ofs1++) {=0A= $eq =3D count_array_diff($ar1, $ar2, $is_reg, $w, $ofs1, $idx2, = $cnt1, $cnt2, $st);=0A= =0A= if ($eq > $eq1) {=0A= $eq1 =3D $eq;=0A= }=0A= }=0A= =0A= $eq2 =3D 0;=0A= $st =3D $steps;=0A= =0A= for ($ofs2 =3D $idx2 + 1; $ofs2 < $cnt2 && $st-- > 0; $ofs2++) {=0A= $eq =3D count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $ofs2, = $cnt1, $cnt2, $st);=0A= if ($eq > $eq2) {=0A= $eq2 =3D $eq;=0A= }=0A= }=0A= =0A= if ($eq1 > $eq2) {=0A= $equal +=3D $eq1;=0A= } else if ($eq2 > 0) {=0A= $equal +=3D $eq2;=0A= }=0A= }=0A= =0A= return $equal;=0A= }=0A= =0A= function generate_array_diff($ar1, $ar2, $is_reg, $w)=0A= {=0A= $idx1 =3D 0; $ofs1 =3D 0; $cnt1 =3D count($ar1);=0A= $idx2 =3D 0; $ofs2 =3D 0; $cnt2 =3D count($ar2);=0A= $diff =3D array();=0A= $old1 =3D array();=0A= $old2 =3D array();=0A= =0A= while ($idx1 < $cnt1 && $idx2 < $cnt2) {=0A= =0A= if (comp_line($ar1[$idx1], $ar2[$idx2], $is_reg)) {=0A= $idx1++;=0A= $idx2++;=0A= continue;=0A= } else {=0A= =0A= $c1 =3D count_array_diff($ar1, $ar2, $is_reg, $w, $idx1+1, $idx2, = $cnt1, $cnt2, 10);=0A= $c2 =3D count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $idx2+1, = $cnt1, $cnt2, 10);=0A= =0A= if ($c1 > $c2) {=0A= =0A= if (is_binary($w[$idx1])) {=0A= $old1[$idx1] =3D (binary)sprintf("%03d- ", $idx1+1) . $w[$idx1++];=0A= } else {=0A= $old1[$idx1] =3D sprintf("%03d- ", $idx1+1) . $w[$idx1++];=0A= }=0A= =0A= $last =3D 1;=0A= =0A= } else if ($c2 > 0) {=0A= =0A= if (is_binary($ar2[$idx2])) {=0A= $old2[$idx2] =3D (binary)sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++];=0A= } else {=0A= $old2[$idx2] =3D sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++];=0A= }=0A= =0A= $last =3D 2;=0A= =0A= } else {=0A= =0A= if (is_binary($ar2[$idx2])) {=0A= $old1[$idx1] =3D (binary)sprintf("%03d- ", $idx1+1) . $w[$idx1++];=0A= $old2[$idx2] =3D (binary)sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++];=0A= } else {=0A= $old1[$idx1] =3D sprintf("%03d- ", $idx1+1) . $w[$idx1++];=0A= $old2[$idx2] =3D sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++];=0A= }=0A= }=0A= }=0A= }=0A= =0A= reset($old1); $k1 =3D key($old1); $l1 =3D -2;=0A= reset($old2); $k2 =3D key($old2); $l2 =3D -2;=0A= =0A= while ($k1 !=3D=3D null || $k2 !=3D=3D null) {=0A= =0A= if ($k1 =3D=3D $l1 + 1 || $k2 =3D=3D=3D null) {=0A= $l1 =3D $k1;=0A= $diff[] =3D current($old1);=0A= $k1 =3D next($old1) ? key($old1) : null;=0A= } else if ($k2 =3D=3D $l2 + 1 || $k1 =3D=3D=3D null) {=0A= $l2 =3D $k2;=0A= $diff[] =3D current($old2);=0A= $k2 =3D next($old2) ? key($old2) : null;=0A= } else if ($k1 < $k2) {=0A= $l1 =3D $k1;=0A= $diff[] =3D current($old1);=0A= $k1 =3D next($old1) ? key($old1) : null;=0A= } else {=0A= $l2 =3D $k2;=0A= $diff[] =3D current($old2);=0A= $k2 =3D next($old2) ? key($old2) : null;=0A= }=0A= }=0A= =0A= while ($idx1 < $cnt1) {=0A= $diff[] =3D sprintf("%03d- ", $idx1 + 1) . $w[$idx1++];=0A= }=0A= =0A= while ($idx2 < $cnt2) {=0A= $diff[] =3D sprintf("%03d+ ", $idx2 + 1) . $ar2[$idx2++];=0A= }=0A= =0A= return $diff;=0A= }=0A= =0A= function generate_diff($wanted, $wanted_re, $output)=0A= {=0A= if (is_binary($output)) {=0A= $w =3D explode(b"\n", $wanted);=0A= $o =3D explode(b"\n", $output);=0A= $r =3D is_null($wanted_re) ? $w : explode(b"\n", $wanted_re);=0A= } else {=0A= $w =3D explode("\n", $wanted);=0A= $o =3D explode("\n", $output);=0A= $r =3D is_null($wanted_re) ? $w : explode("\n", $wanted_re);=0A= }=0A= =0A= $diff =3D generate_array_diff($r, $o, !is_null($wanted_re), $w);=0A= =0A= if (is_binary($output)) {=0A= return implode(b"\r\n", $diff);=0A= }=0A= =0A= return implode("\r\n", $diff);=0A= }=0A= =0A= function error($message)=0A= {=0A= echo "ERROR: {$message}\n";=0A= exit(1);=0A= }=0A= =0A= function settings2array($settings, &$ini_settings)=0A= {=0A= foreach($settings as $setting) {=0A= =0A= if (strpos($setting, '=3D') !=3D=3D false) {=0A= $setting =3D explode("=3D", $setting, 2);=0A= $name =3D trim(strtolower($setting[0]));=0A= $value =3D trim($setting[1]);=0A= =0A= if ($name =3D=3D 'extension') {=0A= =0A= if (!isset($ini_settings[$name])) {=0A= $ini_settings[$name] =3D array();=0A= }=0A= =0A= $ini_settings[$name][] =3D $value;=0A= =0A= } else {=0A= $ini_settings[$name] =3D $value;=0A= }=0A= }=0A= }=0A= }=0A= =0A= function settings2params(&$ini_settings)=0A= {=0A= $settings =3D '';=0A= =0A= foreach($ini_settings as $name =3D> $value) {=0A= =0A= if (is_array($value)) {=0A= foreach($value as $val) {=0A= $val =3D addslashes($val);=0A= $settings .=3D " -d \"$name=3D$val\"";=0A= }=0A= } else {=0A= $value =3D addslashes($value);=0A= $settings .=3D " -d \"$name=3D$value\"";=0A= }=0A= }=0A= =0A= $ini_settings =3D $settings;=0A= }=0A= =0A= function compute_summary()=0A= {=0A= global $n_total, $test_results, $ignored_by_ext, $sum_results, = $percent_results;=0A= =0A= $n_total =3D count($test_results);=0A= $n_total +=3D $ignored_by_ext;=0A= $sum_results =3D array('PASSED' =3D> 0, 'WARNED' =3D> 0, 'SKIPPED' =3D> = 0, 'FAILED' =3D> 0, 'BORKED' =3D> 0, 'LEAKED' =3D> 0, 'XFAILED' =3D> 0);=0A= =0A= foreach ($test_results as $v) {=0A= $sum_results[$v]++;=0A= }=0A= =0A= $sum_results['SKIPPED'] +=3D $ignored_by_ext;=0A= $percent_results =3D array();=0A= =0A= while (list($v, $n) =3D each($sum_results)) {=0A= $percent_results[$v] =3D (100.0 * $n) / $n_total;=0A= }=0A= }=0A= =0A= function get_summary($show_ext_summary, $show_html)=0A= {=0A= global $exts_skipped, $exts_tested, $n_total, $sum_results, = $percent_results, $end_time, $start_time, $failed_test_summary, = $PHP_FAILED_TESTS, $leak_check;=0A= =0A= $x_total =3D $n_total - $sum_results['SKIPPED'] - = $sum_results['BORKED'];=0A= =0A= if ($x_total) {=0A= $x_warned =3D (100.0 * $sum_results['WARNED']) / $x_total;=0A= $x_failed =3D (100.0 * $sum_results['FAILED']) / $x_total;=0A= $x_xfailed =3D (100.0 * $sum_results['XFAILED']) / $x_total;=0A= $x_leaked =3D (100.0 * $sum_results['LEAKED']) / $x_total;=0A= $x_passed =3D (100.0 * $sum_results['PASSED']) / $x_total;=0A= } else {=0A= $x_warned =3D $x_failed =3D $x_passed =3D $x_leaked =3D $x_xfailed = =3D 0;=0A= }=0A= =0A= $summary =3D "";=0A= =0A= if ($show_html) {=0A= $summary .=3D "
\n";=0A=
	}=0A=
=0A=
	if ($show_ext_summary) {=0A=
		$summary .=3D "=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
TEST RESULT SUMMARY=0A=
---------------------------------------------------------------------=0A=
Exts skipped    : " . sprintf("%4d", $exts_skipped) . "=0A=
Exts tested     : " . sprintf("%4d", $exts_tested) . "=0A=
---------------------------------------------------------------------=0A=
";=0A=
	}=0A=
=0A=
	$summary .=3D "=0A=
Number of tests : " . sprintf("%4d", $n_total). "          " . =
sprintf("%8d", $x_total);=0A=
=0A=
	if ($sum_results['BORKED']) {=0A=
		$summary .=3D "=0A=
Tests borked    : " . sprintf("%4d (%5.1f%%)", $sum_results['BORKED'], =
$percent_results['BORKED']) . " --------";=0A=
	}=0A=
=0A=
	$summary .=3D "=0A=
Tests skipped   : " . sprintf("%4d (%5.1f%%)", $sum_results['SKIPPED'], =
$percent_results['SKIPPED']) . " --------=0A=
Tests warned    : " . sprintf("%4d (%5.1f%%)", $sum_results['WARNED'], =
$percent_results['WARNED']) . " " . sprintf("(%5.1f%%)", $x_warned) . "=0A=
Tests failed    : " . sprintf("%4d (%5.1f%%)", $sum_results['FAILED'], =
$percent_results['FAILED']) . " " . sprintf("(%5.1f%%)", $x_failed) . "=0A=
Expected fail   : " . sprintf("%4d (%5.1f%%)", $sum_results['XFAILED'], =
$percent_results['XFAILED']) . " " . sprintf("(%5.1f%%)", $x_xfailed);=0A=
=0A=
	if ($leak_check) {=0A=
		$summary .=3D "=0A=
Tests leaked    : " . sprintf("%4d (%5.1f%%)", $sum_results['LEAKED'], =
$percent_results['LEAKED']) . " " . sprintf("(%5.1f%%)", $x_leaked);=0A=
	}=0A=
=0A=
	$summary .=3D "=0A=
Tests passed    : " . sprintf("%4d (%5.1f%%)", $sum_results['PASSED'], =
$percent_results['PASSED']) . " " . sprintf("(%5.1f%%)", $x_passed) . "=0A=
---------------------------------------------------------------------=0A=
Time taken      : " . sprintf("%4d seconds", $end_time - $start_time) . "=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
";=0A=
	$failed_test_summary =3D '';=0A=
=0A=
	if (count($PHP_FAILED_TESTS['BORKED'])) {=0A=
		$failed_test_summary .=3D "=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
BORKED TEST SUMMARY=0A=
---------------------------------------------------------------------=0A=
";=0A=
		foreach ($PHP_FAILED_TESTS['BORKED'] as $test_data) {=0A=
			$failed_test_summary .=3D $test_data['info'] . "\n";=0A=
		}=0A=
=0A=
		$failed_test_summary .=3D  =
"=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n";=0A=
	}=0A=
=0A=
	if (count($PHP_FAILED_TESTS['FAILED'])) {=0A=
		$failed_test_summary .=3D "=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
FAILED TEST SUMMARY=0A=
---------------------------------------------------------------------=0A=
";=0A=
		foreach ($PHP_FAILED_TESTS['FAILED'] as $test_data) {=0A=
			$failed_test_summary .=3D $test_data['test_name'] . =
$test_data['info'] . "\n";=0A=
		}=0A=
=0A=
		$failed_test_summary .=3D  =
"=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n";=0A=
	}=0A=
=0A=
	if (count($PHP_FAILED_TESTS['XFAILED'])) {=0A=
		$failed_test_summary .=3D "=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
EXPECTED FAILED TEST SUMMARY=0A=
---------------------------------------------------------------------=0A=
";=0A=
		foreach ($PHP_FAILED_TESTS['XFAILED'] as $test_data) {=0A=
			$failed_test_summary .=3D $test_data['test_name'] . =
$test_data['info'] . "\n";=0A=
		}=0A=
=0A=
		$failed_test_summary .=3D  =
"=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n";=0A=
	}=0A=
=0A=
	if (count($PHP_FAILED_TESTS['LEAKED'])) {=0A=
		$failed_test_summary .=3D "=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
LEAKED TEST SUMMARY=0A=
---------------------------------------------------------------------=0A=
";=0A=
		foreach ($PHP_FAILED_TESTS['LEAKED'] as $test_data) {=0A=
			$failed_test_summary .=3D $test_data['test_name'] . =
$test_data['info'] . "\n";=0A=
		}=0A=
=0A=
		$failed_test_summary .=3D  =
"=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n";=0A=
	}=0A=
=0A=
	if ($failed_test_summary && !getenv('NO_PHPTEST_SUMMARY')) {=0A=
		$summary .=3D $failed_test_summary;=0A=
	}=0A=
=0A=
	if ($show_html) {=0A=
		$summary .=3D "
";=0A= }=0A= =0A= return $summary;=0A= }=0A= =0A= function show_start($start_time)=0A= {=0A= global $html_output, $html_file;=0A= =0A= if ($html_output) {=0A= fwrite($html_file, "

Time Start: " . @date('Y-m-d H:i:s', = $start_time) . "

\n");=0A= fwrite($html_file, "\n");=0A= }=0A= =0A= echo "TIME START " . @date('Y-m-d H:i:s', $start_time) . = "\n=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n";=0A= }=0A= =0A= function show_end($end_time)=0A= {=0A= global $html_output, $html_file;=0A= =0A= if ($html_output) {=0A= fwrite($html_file, "
\n");=0A= fwrite($html_file, "

Time End: " . @date('Y-m-d H:i:s', $end_time) = . "

\n");=0A= }=0A= =0A= echo = "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\nTIME END " = . @date('Y-m-d H:i:s', $end_time) . "\n";=0A= }=0A= =0A= function show_summary()=0A= {=0A= global $html_output, $html_file;=0A= =0A= if ($html_output) {=0A= fwrite($html_file, "
\n" . get_summary(true, true));=0A= }=0A= =0A= echo get_summary(true, false);=0A= }=0A= =0A= function show_redirect_start($tests, $tested, $tested_file)=0A= {=0A= global $html_output, $html_file;=0A= =0A= if ($html_output) {=0A= fwrite($html_file, "---> $tests ($tested = [$tested_file]) begin\n");=0A= }=0A= =0A= echo "---> $tests ($tested [$tested_file]) begin\n";=0A= }=0A= =0A= function show_redirect_ends($tests, $tested, $tested_file)=0A= {=0A= global $html_output, $html_file;=0A= =0A= if ($html_output) {=0A= fwrite($html_file, "---> $tests ($tested = [$tested_file]) done\n");=0A= }=0A= =0A= echo "---> $tests ($tested [$tested_file]) done\n";=0A= }=0A= =0A= function show_test($test_idx, $shortname)=0A= {=0A= global $test_cnt;=0A= =0A= echo "TEST $test_idx/$test_cnt [$shortname]\r";=0A= flush();=0A= }=0A= =0A= function show_result($result, $tested, $tested_file, $extra =3D '', = $temp_filenames =3D null)=0A= {=0A= global $html_output, $html_file, $temp_target, $temp_urlbase;=0A= =0A= echo "$result $tested [$tested_file] $extra\n";=0A= =0A= if ($html_output) {=0A= =0A= if (isset($temp_filenames['file']) && = @file_exists($temp_filenames['file'])) {=0A= $url =3D str_replace($temp_target, $temp_urlbase, = $temp_filenames['file']);=0A= $tested =3D "$tested";=0A= }=0A= =0A= if (isset($temp_filenames['skip']) && = @file_exists($temp_filenames['skip'])) {=0A= =0A= if (empty($extra)) {=0A= $extra =3D "skipif";=0A= }=0A= =0A= $url =3D str_replace($temp_target, $temp_urlbase, = $temp_filenames['skip']);=0A= $extra =3D "$extra";=0A= =0A= } else if (empty($extra)) {=0A= $extra =3D " ";=0A= }=0A= =0A= if (isset($temp_filenames['diff']) && = @file_exists($temp_filenames['diff'])) {=0A= $url =3D str_replace($temp_target, $temp_urlbase, = $temp_filenames['diff']);=0A= $diff =3D "diff";=0A= } else {=0A= $diff =3D " ";=0A= }=0A= =0A= if (isset($temp_filenames['mem']) && = @file_exists($temp_filenames['mem'])) {=0A= $url =3D str_replace($temp_target, $temp_urlbase, = $temp_filenames['mem']);=0A= $mem =3D "leaks";=0A= } else {=0A= $mem =3D " ";=0A= }=0A= =0A= fwrite($html_file, =0A= "" .=0A= "$result" .=0A= "$tested" .=0A= "$extra" .=0A= "$diff" . =0A= "$mem" .=0A= "\n");=0A= }=0A= }=0A= =0A= /*=0A= * Local variables:=0A= * tab-width: 4=0A= * c-basic-offset: 4=0A= * End:=0A= * vim: noet sw=3D4 ts=3D4=0A= */=0A= ?>=0A= ------=_NextPart_000_004D_01C8CB17.84DAD780--