PageRenderTime 71ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/opensource.apple.com/source/apache_mod_php/apache_mod_php-44.1/php/run-tests.php

#
PHP | 2029 lines | 1834 code | 122 blank | 73 comment | 213 complexity | b9b90548fe5a3ed676bdd6fb6f75c328 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD

Large files files are truncated, but you can click here to view the full file

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>run-tests.php</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">run-tests.php&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. #!/usr/bin/php
  24. &lt;?php
  25. /*
  26. +----------------------------------------------------------------------+
  27. | PHP Version 5 |
  28. +----------------------------------------------------------------------+
  29. | Copyright (c) 1997-2008 The PHP Group |
  30. +----------------------------------------------------------------------+
  31. | This source file is subject to version 3.01 of the PHP license, |
  32. | that is bundled with this package in the file LICENSE, and is |
  33. | available through the world-wide-web at the following url: |
  34. | <a href="http://www.php.net/license/3_01.txt">http://www.php.net/license/3_01.txt</a> |
  35. | If you did not receive a copy of the PHP license and are unable to |
  36. | obtain it through the world-wide-web, please send a note to |
  37. | <a href="mailto:license@php.net">license@php.net</a> so we can mail you a copy immediately. |
  38. +----------------------------------------------------------------------+
  39. | Authors: Ilia Alshanetsky &lt;<a href="mailto:iliaa@php.net">iliaa@php.net</a>&gt; |
  40. | Preston L. Bannister &lt;<a href="mailto:pbannister@php.net">pbannister@php.net</a>&gt; |
  41. | Marcus Boerger &lt;<a href="mailto:helly@php.net">helly@php.net</a>&gt; |
  42. | Derick Rethans &lt;<a href="mailto:derick@php.net">derick@php.net</a>&gt; |
  43. | Sander Roobol &lt;<a href="mailto:sander@php.net">sander@php.net</a>&gt; |
  44. | (based on version by: Stig Bakken &lt;<a href="mailto:ssb@php.net">ssb@php.net</a>&gt;) |
  45. | (based on the PHP 3 test framework by Rasmus Lerdorf) |
  46. +----------------------------------------------------------------------+
  47. */
  48. /* $Id: run-tests.php,v 1.226.2.37.2.45 2008/03/13 13:51:40 felipe Exp $ */
  49. /* Sanity check to ensure that pcre extension needed by this script is available.
  50. * In the event it is not, print a nice error message indicating that this script will
  51. * not run without it.
  52. */
  53. if (!extension_loaded(&quot;pcre&quot;)) {
  54. echo &lt;&lt;&lt;NO_PCRE_ERROR
  55. +-----------------------------------------------------------+
  56. | ! ERROR ! |
  57. | The test-suite requires that you have pcre extension |
  58. | enabled. To enable this extension either compile your PHP |
  59. | with --with-pcre-regex or if you've compiled pcre as a |
  60. | shared module load it via php.ini. |
  61. +-----------------------------------------------------------+
  62. NO_PCRE_ERROR;
  63. exit;
  64. }
  65. if (!function_exists(&quot;proc_open&quot;)) {
  66. echo &lt;&lt;&lt;NO_PROC_OPEN_ERROR
  67. +-----------------------------------------------------------+
  68. | ! ERROR ! |
  69. | The test-suite requires that proc_open() is available. |
  70. | Please check if you disabled it in php.ini. |
  71. +-----------------------------------------------------------+
  72. NO_PROC_OPEN_ERROR;
  73. exit;
  74. }
  75. // store current directory
  76. $CUR_DIR = getcwd();
  77. // change into the PHP source directory.
  78. if (getenv('TEST_PHP_SRCDIR')) {
  79. @chdir(getenv('TEST_PHP_SRCDIR'));
  80. }
  81. // Delete some security related environment variables
  82. putenv('SSH_CLIENT=deleted');
  83. putenv('SSH_AUTH_SOCK=deleted');
  84. putenv('SSH_TTY=deleted');
  85. putenv('SSH_CONNECTION=deleted');
  86. $cwd = getcwd();
  87. set_time_limit(0);
  88. $valgrind_version = 0;
  89. // delete as much output buffers as possible
  90. while(@ob_end_clean());
  91. if (ob_get_level()) echo &quot;Not all buffers were deleted.\n&quot;;
  92. error_reporting(E_ALL);
  93. ini_set('magic_quotes_runtime',0); // this would break tests by modifying EXPECT sections
  94. if (ini_get('safe_mode')) {
  95. echo &lt;&lt;&lt; SAFE_MODE_WARNING
  96. +-----------------------------------------------------------+
  97. | ! WARNING ! |
  98. | You are running the test-suite with &quot;safe_mode&quot; ENABLED ! |
  99. | |
  100. | Chances are high that no test will work at all, |
  101. | depending on how you configured &quot;safe_mode&quot; ! |
  102. +-----------------------------------------------------------+
  103. SAFE_MODE_WARNING;
  104. }
  105. $environment = isset($_ENV) ? $_ENV : array();
  106. // Don't ever guess at the PHP executable location.
  107. // Require the explicit specification.
  108. // Otherwise we could end up testing the wrong file!
  109. $php = NULL;
  110. $php_cgi = NULL;
  111. if (getenv('TEST_PHP_EXECUTABLE')) {
  112. $php = getenv('TEST_PHP_EXECUTABLE');
  113. if ($php=='auto') {
  114. $php = $cwd.'/sapi/cli/php';
  115. putenv(&quot;TEST_PHP_EXECUTABLE=$php&quot;);
  116. if (!getenv('TEST_PHP_CGI_EXECUTABLE')) {
  117. $php_cgi = $cwd.'/sapi/cgi/php-cgi';
  118. if (file_exists($php_cgi)) {
  119. putenv(&quot;TEST_PHP_CGI_EXECUTABLE=$php_cgi&quot;);
  120. } else {
  121. $php_cgi = NULL;
  122. }
  123. }
  124. }
  125. $environment['TEST_PHP_EXECUTABLE'] = $php;
  126. }
  127. if (getenv('TEST_PHP_CGI_EXECUTABLE')) {
  128. $php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE');
  129. if ($php_cgi=='auto') {
  130. $php_cgi = $cwd.'/sapi/cgi/php-cgi';
  131. putenv(&quot;TEST_PHP_CGI_EXECUTABLE=$php_cgi&quot;);
  132. }
  133. $environment['TEST_PHP_CGI_EXECUTABLE'] = $php_cgi;
  134. }
  135. if ($argc !=2 || ($argv[1] != '-h' &amp;&amp; $argv[1] != '-help' &amp;&amp; $argv != '--help'))
  136. {
  137. if (empty($php) || !file_exists($php)) {
  138. error(&quot;environment variable TEST_PHP_EXECUTABLE must be set to specify PHP executable!&quot;);
  139. }
  140. if (function_exists('is_executable') &amp;&amp; !@is_executable($php)) {
  141. error(&quot;invalid PHP executable specified by TEST_PHP_EXECUTABLE = &quot; . $php);
  142. }
  143. }
  144. if (getenv('TEST_PHP_LOG_FORMAT')) {
  145. $log_format = strtoupper(getenv('TEST_PHP_LOG_FORMAT'));
  146. } else {
  147. $log_format = 'LEOD';
  148. }
  149. // Check whether a detailed log is wanted.
  150. if (getenv('TEST_PHP_DETAILED')) {
  151. $DETAILED = getenv('TEST_PHP_DETAILED');
  152. } else {
  153. $DETAILED = 0;
  154. }
  155. // Check whether user test dirs are requested.
  156. if (getenv('TEST_PHP_USER')) {
  157. $user_tests = explode (',', getenv('TEST_PHP_USER'));
  158. } else {
  159. $user_tests = array();
  160. }
  161. $exts_to_test = array();
  162. $ini_overwrites = array(
  163. 'output_handler=',
  164. 'open_basedir=',
  165. 'safe_mode=0',
  166. 'disable_functions=',
  167. 'output_buffering=Off',
  168. 'error_reporting=8191',
  169. 'display_errors=1',
  170. 'display_startup_errors=1',
  171. 'log_errors=0',
  172. 'html_errors=0',
  173. 'track_errors=1',
  174. 'report_memleaks=1',
  175. 'report_zend_debug=0',
  176. 'docref_root=',
  177. 'docref_ext=.html',
  178. 'error_prepend_string=',
  179. 'error_append_string=',
  180. 'auto_prepend_file=',
  181. 'auto_append_file=',
  182. 'magic_quotes_runtime=0',
  183. 'ignore_repeated_errors=0',
  184. );
  185. function write_information($show_html)
  186. {
  187. global $cwd, $php, $php_cgi, $php_info, $user_tests, $ini_overwrites, $pass_options, $exts_to_test;
  188. // Get info from php
  189. $info_file = realpath(dirname(__FILE__)) . '/run-test-info.php';
  190. @unlink($info_file);
  191. $php_info = '&lt;?php echo &quot;
  192. PHP_SAPI : &quot; . PHP_SAPI . &quot;
  193. PHP_VERSION : &quot; . phpversion() . &quot;
  194. ZEND_VERSION: &quot; . zend_version() . &quot;
  195. PHP_OS : &quot; . PHP_OS . &quot; - &quot; . php_uname() . &quot;
  196. INI actual : &quot; . realpath(get_cfg_var(&quot;cfg_file_path&quot;)) . &quot;
  197. More .INIs : &quot; . (function_exists(\'php_ini_scanned_files\') ? str_replace(&quot;\n&quot;,&quot;&quot;, php_ini_scanned_files()) : &quot;** not determined **&quot;); ?&gt;';
  198. save_text($info_file, $php_info);
  199. $info_params = array();
  200. settings2array($ini_overwrites,$info_params);
  201. settings2params($info_params);
  202. $php_info = `$php $pass_options $info_params &quot;$info_file&quot;`;
  203. if ($php_cgi &amp;&amp; $php != $php_cgi) {
  204. $php_info_cgi = `$php_cgi $pass_options $info_params -q &quot;$info_file&quot;`;
  205. $php_info_sep = &quot;\n---------------------------------------------------------------------&quot;;
  206. $php_cgi_info = &quot;$php_info_sep\nPHP : $php_cgi $php_info_cgi$php_info_sep&quot;;
  207. } else {
  208. $php_cgi_info = '';
  209. }
  210. @unlink($info_file);
  211. define('TESTED_PHP_VERSION', `$php -r &quot;echo PHP_VERSION;&quot;`);
  212. // load list of enabled extensions
  213. save_text($info_file, '&lt;?php echo join(&quot;,&quot;,get_loaded_extensions()); ?&gt;');
  214. $exts_to_test = explode(',',`$php $pass_options $info_params &quot;$info_file&quot;`);
  215. // check for extensions that need special handling and regenerate
  216. $info_params_ex = array(
  217. 'session' =&gt; array('session.auto_start=0'),
  218. 'tidy' =&gt; array('tidy.clean_output=0'),
  219. 'zlib' =&gt; array('zlib.output_compression=Off'),
  220. 'xdebug' =&gt; array('xdebug.default_enable=0'),
  221. );
  222. foreach($info_params_ex as $ext =&gt; $ini_overwrites_ex) {
  223. if (in_array($ext, $exts_to_test)) {
  224. $ini_overwrites = array_merge($ini_overwrites, $ini_overwrites_ex);
  225. }
  226. }
  227. @unlink($info_file);
  228. // Write test context information.
  229. echo &quot;
  230. =====================================================================
  231. PHP : $php $php_info $php_cgi_info
  232. CWD : $cwd
  233. Extra dirs : &quot;;
  234. foreach ($user_tests as $test_dir) {
  235. echo &quot;{$test_dir}\n &quot;;
  236. }
  237. echo &quot;
  238. =====================================================================
  239. &quot;;
  240. }
  241. // Determine the tests to be run.
  242. $test_files = array();
  243. $redir_tests = array();
  244. $test_results = array();
  245. $PHP_FAILED_TESTS = array('BORKED' =&gt; array(), 'FAILED' =&gt; array(), 'WARNED' =&gt; array(), 'LEAKED' =&gt; array());
  246. // If parameters given assume they represent selected tests to run.
  247. $failed_tests_file= false;
  248. $pass_option_n = false;
  249. $pass_options = '';
  250. $compression = 0;
  251. $output_file = $CUR_DIR . '/php_test_results_' . @date('Ymd_Hi') . '.txt';
  252. if ($compression) {
  253. $output_file = 'compress.zlib://' . $output_file . '.gz';
  254. }
  255. $just_save_results = false;
  256. $leak_check = false;
  257. $html_output = false;
  258. $html_file = null;
  259. $temp_source = null;
  260. $temp_target = null;
  261. $temp_urlbase = null;
  262. $conf_passed = null;
  263. $no_clean = false;
  264. $cfgtypes = array('show', 'keep');
  265. $cfgfiles = array('skip', 'php', 'clean');
  266. $cfg = array();
  267. foreach($cfgtypes as $type) {
  268. $cfg[$type] = array();
  269. foreach($cfgfiles as $file) {
  270. $cfg[$type][$file] = false;
  271. }
  272. }
  273. if (getenv('TEST_PHP_ARGS'))
  274. {
  275. if (!isset($argc) || !$argc || !isset($argv))
  276. {
  277. $argv = array(__FILE__);
  278. }
  279. $argv = array_merge($argv, split(' ', getenv('TEST_PHP_ARGS')));
  280. $argc = count($argv);
  281. }
  282. if (isset($argc) &amp;&amp; $argc &gt; 1) {
  283. for ($i=1; $i&lt;$argc; $i++) {
  284. $is_switch = false;
  285. $switch = substr($argv[$i],1,1);
  286. $repeat = substr($argv[$i],0,1) == '-';
  287. while ($repeat) {
  288. $repeat = false;
  289. if (!$is_switch) {
  290. $switch = substr($argv[$i],1,1);
  291. }
  292. $is_switch = true;
  293. switch($switch) {
  294. case 'r':
  295. case 'l':
  296. $test_list = @file($argv[++$i]);
  297. if ($test_list) {
  298. foreach($test_list as $test) {
  299. $matches = array();
  300. if (preg_match('/^#.*\[(.*)\]\:\s+(.*)$/', $test, $matches)) {
  301. $redir_tests[] = array($matches[1], $matches[2]);
  302. } else if (strlen($test)) {
  303. $test_files[] = trim($test);
  304. }
  305. }
  306. }
  307. if ($switch != 'l') {
  308. break;
  309. }
  310. $i--;
  311. // break left intentionally
  312. case 'w':
  313. $failed_tests_file = fopen($argv[++$i], 'w+t');
  314. break;
  315. case 'a':
  316. $failed_tests_file = fopen($argv[++$i], 'a+t');
  317. break;
  318. case 'c':
  319. $conf_passed = $argv[++$i];
  320. break;
  321. case 'd':
  322. $ini_overwrites[] = $argv[++$i];
  323. break;
  324. //case 'h'
  325. case '--keep-all':
  326. foreach($cfgfiles as $file) {
  327. $cfg['keep'][$file] = true;
  328. }
  329. break;
  330. case '--keep-skip':
  331. $cfg['keep']['skip'] = true;
  332. break;
  333. case '--keep-php':
  334. $cfg['keep']['php'] = true;
  335. break;
  336. case '--keep-clean':
  337. $cfg['keep']['clean'] = true;
  338. break;
  339. //case 'l'
  340. case 'm':
  341. $leak_check = true;
  342. break;
  343. case 'n':
  344. if (!$pass_option_n) {
  345. $pass_options .= ' -n';
  346. }
  347. $pass_option_n = true;
  348. break;
  349. case 'N':
  350. // this is always native
  351. break;
  352. case '--no-clean':
  353. $no_clean = true;
  354. break;
  355. case 'q':
  356. putenv('NO_INTERACTION=1');
  357. break;
  358. //case 'r'
  359. case 's':
  360. $output_file = $argv[++$i];
  361. $just_save_results = true;
  362. break;
  363. case '--show-all':
  364. foreach($cfgfiles as $file) {
  365. $cfg['show'][$file] = true;
  366. }
  367. break;
  368. case '--show-skip':
  369. $cfg['show']['skip'] = true;
  370. break;
  371. case '--show-php':
  372. $cfg['show']['php'] = true;
  373. break;
  374. case '--show-clean':
  375. $cfg['show']['clean'] = true;
  376. break;
  377. case '--temp-source':
  378. $temp_source = $argv[++$i];
  379. break;
  380. case '--temp-target':
  381. $temp_target = $argv[++$i];
  382. if ($temp_urlbase) {
  383. $temp_urlbase = $temp_target;
  384. }
  385. break;
  386. case '--temp-urlbase':
  387. $temp_urlbase = $argv[++$i];
  388. break;
  389. case 'v':
  390. case '--verbose':
  391. $DETAILED = true;
  392. break;
  393. //case 'w'
  394. case '-':
  395. // repeat check with full switch
  396. $switch = $argv[$i];
  397. if ($switch != '-') {
  398. $repeat = true;
  399. }
  400. break;
  401. case '--html':
  402. $html_file = @fopen($argv[++$i], 'wt');
  403. $html_output = is_resource($html_file);
  404. break;
  405. case '--version':
  406. echo '$Revision: 1.226.2.37.2.45 $'.&quot;\n&quot;;
  407. exit(1);
  408. case 'u':
  409. case 'U':
  410. // Allow using u or U for forward compatibility
  411. break;
  412. default:
  413. echo &quot;Illegal switch '$switch' specified!\n&quot;;
  414. case 'h':
  415. case '-help':
  416. case '--help':
  417. echo &lt;&lt;&lt;HELP
  418. Synopsis:
  419. php run-tests.php [options] [files] [directories]
  420. Options:
  421. -l &lt;file&gt; Read the testfiles to be executed from &lt;file&gt;. After the test
  422. has finished all failed tests are written to the same &lt;file&gt;.
  423. If the list is empty and no further test is specified then
  424. all tests are executed (same as: -r &lt;file&gt; -w &lt;file&gt;).
  425. -r &lt;file&gt; Read the testfiles to be executed from &lt;file&gt;.
  426. -w &lt;file&gt; Write a list of all failed tests to &lt;file&gt;.
  427. -a &lt;file&gt; Same as -w but append rather then truncating &lt;file&gt;.
  428. -c &lt;file&gt; Look for php.ini in directory &lt;file&gt; or use &lt;file&gt; as ini.
  429. -n Pass -n option to the php binary (Do not use a php.ini).
  430. -d foo=bar Pass -d option to the php binary (Define INI entry foo
  431. with value 'bar').
  432. -m Test for memory leaks with Valgrind.
  433. -N Always set (Test with unicode_semantics set off in PHP 6).
  434. -s &lt;file&gt; Write output to &lt;file&gt;.
  435. -q Quiet, no user interaction (same as environment NO_INTERACTION).
  436. --verbose
  437. -v Verbose mode.
  438. --help
  439. -h This Help.
  440. --html &lt;file&gt; Generate HTML output.
  441. --temp-source &lt;sdir&gt; --temp-target &lt;tdir&gt; [--temp-urlbase &lt;url&gt;]
  442. Write temporary files to &lt;tdir&gt; by replacing &lt;sdir&gt; from the
  443. filenames to generate with &lt;tdir&gt;. If --html is being used and
  444. &lt;url&gt; given then the generated links are relative and prefixed
  445. with the given url. In general you want to make &lt;sdir&gt; the path
  446. to your source files and &lt;tdir&gt; some pach in your web page
  447. hierarchy with &lt;url&gt; pointing to &lt;tdir&gt;.
  448. --keep-[all|php|skip|clean]
  449. Do not delete 'all' files, 'php' test file, 'skip' or 'clean'
  450. file.
  451. --show-[all|php|skip|clean]
  452. Show 'all' files, 'php' test file, 'skip' or 'clean' file.
  453. --no-clean Do not execute clean section if any.
  454. HELP;
  455. exit(1);
  456. }
  457. }
  458. if (!$is_switch) {
  459. $testfile = realpath($argv[$i]);
  460. if (!$testfile &amp;&amp; strpos($argv[$i], '*') !== false &amp;&amp; function_exists('glob')) {
  461. if (preg_match(&quot;/\.phpt$/&quot;, $argv[$i])) {
  462. $pattern_match = glob($argv[$i]);
  463. } else if (preg_match(&quot;/\*$/&quot;, $argv[$i])) {
  464. $pattern_match = glob($argv[$i] . '.phpt');
  465. } else {
  466. die(&quot;bogus test name &quot; . $argv[$i] . &quot;\n&quot;);
  467. }
  468. if (is_array($pattern_match)) {
  469. $test_files = array_merge($test_files, $pattern_match);
  470. }
  471. } else if (is_dir($testfile)) {
  472. find_files($testfile);
  473. } else if (preg_match(&quot;/\.phpt$/&quot;, $testfile)) {
  474. $test_files[] = $testfile;
  475. } else {
  476. die(&quot;bogus test name &quot; . $argv[$i] . &quot;\n&quot;);
  477. }
  478. }
  479. }
  480. if (strlen($conf_passed))
  481. {
  482. $pass_options .= &quot; -c '$conf_passed'&quot;;
  483. }
  484. $test_files = array_unique($test_files);
  485. $test_files = array_merge($test_files, $redir_tests);
  486. // Run selected tests.
  487. $test_cnt = count($test_files);
  488. if ($test_cnt) {
  489. write_information($html_output);
  490. usort($test_files, &quot;test_sort&quot;);
  491. $start_time = time();
  492. if (!$html_output) {
  493. echo &quot;Running selected tests.\n&quot;;
  494. } else {
  495. show_start($start_time);
  496. }
  497. $test_idx = 0;
  498. run_all_tests($test_files, $environment);
  499. $end_time = time();
  500. if ($html_output) {
  501. show_end($end_time);
  502. }
  503. if ($failed_tests_file) {
  504. fclose($failed_tests_file);
  505. }
  506. if (count($test_files) || count($test_results)) {
  507. compute_summary();
  508. if ($html_output) {
  509. fwrite($html_file, &quot;&lt;hr/&gt;\n&quot; . get_summary(false, true));
  510. }
  511. echo &quot;=====================================================================&quot;;
  512. echo get_summary(false, false);
  513. }
  514. if ($html_output) {
  515. fclose($html_file);
  516. }
  517. if (getenv('REPORT_EXIT_STATUS') == 1 and preg_match('/FAILED(?: |$)/', implode(' ', $test_results))) {
  518. exit(1);
  519. }
  520. exit(0);
  521. }
  522. }
  523. write_information($html_output);
  524. // Compile a list of all test files (*.phpt).
  525. $test_files = array();
  526. $exts_tested = count($exts_to_test);
  527. $exts_skipped = 0;
  528. $ignored_by_ext = 0;
  529. sort($exts_to_test);
  530. $test_dirs = array();
  531. $optionals = array('tests', 'ext', 'Zend', 'ZendEngine2', 'sapi/cli', 'sapi/cgi');
  532. foreach($optionals as $dir) {
  533. if (@filetype($dir) == 'dir') {
  534. $test_dirs[] = $dir;
  535. }
  536. }
  537. // Convert extension names to lowercase
  538. foreach ($exts_to_test as $key =&gt; $val) {
  539. $exts_to_test[$key] = strtolower($val);
  540. }
  541. foreach ($test_dirs as $dir) {
  542. find_files(&quot;{$cwd}/{$dir}&quot;, ($dir == 'ext'));
  543. }
  544. foreach ($user_tests as $dir) {
  545. find_files($dir, ($dir == 'ext'));
  546. }
  547. function find_files($dir,$is_ext_dir=FALSE,$ignore=FALSE)
  548. {
  549. global $test_files, $exts_to_test, $ignored_by_ext, $exts_skipped, $exts_tested;
  550. $o = opendir($dir) or error(&quot;cannot open directory: $dir&quot;);
  551. while (($name = readdir($o)) !== FALSE) {
  552. if (is_dir(&quot;{$dir}/{$name}&quot;) &amp;&amp; !in_array($name, array('.', '..', 'CVS'))) {
  553. $skip_ext = ($is_ext_dir &amp;&amp; !in_array(strtolower($name), $exts_to_test));
  554. if ($skip_ext) {
  555. $exts_skipped++;
  556. }
  557. find_files(&quot;{$dir}/{$name}&quot;, FALSE, $ignore || $skip_ext);
  558. }
  559. // Cleanup any left-over tmp files from last run.
  560. if (substr($name, -4) == '.tmp') {
  561. @unlink(&quot;$dir/$name&quot;);
  562. continue;
  563. }
  564. // Otherwise we're only interested in *.phpt files.
  565. if (substr($name, -5) == '.phpt') {
  566. if ($ignore) {
  567. $ignored_by_ext++;
  568. } else {
  569. $testfile = realpath(&quot;{$dir}/{$name}&quot;);
  570. $test_files[] = $testfile;
  571. }
  572. }
  573. }
  574. closedir($o);
  575. }
  576. function test_name($name)
  577. {
  578. if (is_array($name)) {
  579. return $name[0] . ':' . $name[1];
  580. } else {
  581. return $name;
  582. }
  583. }
  584. function test_sort($a, $b)
  585. {
  586. global $cwd;
  587. $a = test_name($a);
  588. $b = test_name($b);
  589. $ta = strpos($a, &quot;{$cwd}/tests&quot;)===0 ? 1 + (strpos($a, &quot;{$cwd}/tests/run-test&quot;)===0 ? 1 : 0) : 0;
  590. $tb = strpos($b, &quot;{$cwd}/tests&quot;)===0 ? 1 + (strpos($b, &quot;{$cwd}/tests/run-test&quot;)===0 ? 1 : 0) : 0;
  591. if ($ta == $tb) {
  592. return strcmp($a, $b);
  593. } else {
  594. return $tb - $ta;
  595. }
  596. }
  597. $test_files = array_unique($test_files);
  598. usort($test_files, &quot;test_sort&quot;);
  599. $start_time = time();
  600. show_start($start_time);
  601. $test_cnt = count($test_files);
  602. $test_idx = 0;
  603. run_all_tests($test_files, $environment);
  604. $end_time = time();
  605. if ($failed_tests_file) {
  606. fclose($failed_tests_file);
  607. }
  608. // Summarize results
  609. if (0 == count($test_results)) {
  610. echo &quot;No tests were run.\n&quot;;
  611. return;
  612. }
  613. compute_summary();
  614. show_end($end_time);
  615. show_summary();
  616. if ($html_output) {
  617. fclose($html_file);
  618. }
  619. define('PHP_QA_EMAIL', '<a href="mailto:qa-reports@lists.php.net">qa-reports@lists.php.net</a>');
  620. define('QA_SUBMISSION_PAGE', '<a href="http://qa.php.net/buildtest-process.php">http://qa.php.net/buildtest-process.php</a>');
  621. /* We got failed Tests, offer the user to send an e-mail to QA team, unless NO_INTERACTION is set */
  622. if (!getenv('NO_INTERACTION')) {
  623. $fp = fopen(&quot;php://stdin&quot;, &quot;r+&quot;);
  624. if ($sum_results['FAILED'] || $sum_results['BORKED'] || $sum_results['WARNED'] || $sum_results['LEAKED']) {
  625. echo &quot;\nYou may have found a problem in PHP.&quot;;
  626. }
  627. echo &quot;\nWe would like to send this report automatically to the\n&quot;;
  628. echo &quot;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&quot;;
  629. echo &quot;immediately, you can choose \&quot;s\&quot; to save the report to\na file that you can send us later.\n&quot;;
  630. echo &quot;Do you want to send this report now? [Yns]: &quot;;
  631. flush();
  632. $user_input = fgets($fp, 10);
  633. $just_save_results = (strtolower($user_input[0]) == 's');
  634. }
  635. if ($just_save_results || !getenv('NO_INTERACTION')) {
  636. if ($just_save_results || strlen(trim($user_input)) == 0 || strtolower($user_input[0]) == 'y') {
  637. /*
  638. * Collect information about the host system for our report
  639. * Fetch phpinfo() output so that we can see the PHP enviroment
  640. * Make an archive of all the failed tests
  641. * Send an email
  642. */
  643. if ($just_save_results)
  644. {
  645. $user_input = 's';
  646. }
  647. /* Ask the user to provide an email address, so that QA team can contact the user */
  648. if (!strncasecmp($user_input, 'y', 1) || strlen(trim($user_input)) == 0) {
  649. echo &quot;\nPlease enter your email address.\n(Your address will be mangled so that it will not go out on any\nmailinglist in plain text): &quot;;
  650. flush();
  651. $user_email = trim(fgets($fp, 1024));
  652. $user_email = str_replace(&quot;@&quot;, &quot; at &quot;, str_replace(&quot;.&quot;, &quot; dot &quot;, $user_email));
  653. }
  654. $failed_tests_data = '';
  655. $sep = &quot;\n&quot; . str_repeat('=', 80) . &quot;\n&quot;;
  656. $failed_tests_data .= $failed_test_summary . &quot;\n&quot;;
  657. $failed_tests_data .= get_summary(true, false) . &quot;\n&quot;;
  658. if ($sum_results['FAILED']) {
  659. foreach ($PHP_FAILED_TESTS['FAILED'] as $test_info) {
  660. $failed_tests_data .= $sep . $test_info['name'] . $test_info['info'];
  661. $failed_tests_data .= $sep . file_get_contents(realpath($test_info['output']));
  662. $failed_tests_data .= $sep . file_get_contents(realpath($test_info['diff']));
  663. $failed_tests_data .= $sep . &quot;\n\n&quot;;
  664. }
  665. $status = &quot;failed&quot;;
  666. } else {
  667. $status = &quot;success&quot;;
  668. }
  669. $failed_tests_data .= &quot;\n&quot; . $sep . 'BUILD ENVIRONMENT' . $sep;
  670. $failed_tests_data .= &quot;OS:\n&quot; . PHP_OS . &quot; - &quot; . php_uname() . &quot;\n\n&quot;;
  671. $ldd = $autoconf = $sys_libtool = $libtool = $compiler = 'N/A';
  672. if (substr(PHP_OS, 0, 3) != &quot;WIN&quot;) {
  673. /* If PHP_AUTOCONF is set, use it; otherwise, use 'autoconf'. */
  674. if (getenv('PHP_AUTOCONF')) {
  675. $autoconf = shell_exec(getenv('PHP_AUTOCONF') . ' --version');
  676. } else {
  677. $autoconf = shell_exec('autoconf --version');
  678. }
  679. /* Always use the generated libtool - Mac OSX uses 'glibtool' */
  680. $libtool = shell_exec($CUR_DIR . '/libtool --version');
  681. /* Use shtool to find out if there is glibtool present (MacOSX) */
  682. $sys_libtool_path = shell_exec(dirname(__FILE__) . '/build/shtool path glibtool libtool');
  683. if ($sys_libtool_path) {
  684. $sys_libtool = shell_exec(str_replace(&quot;\n&quot;, &quot;&quot;, $sys_libtool_path) . ' --version');
  685. }
  686. /* Try the most common flags for 'version' */
  687. $flags = array('-v', '-V', '--version');
  688. $cc_status=0;
  689. foreach($flags AS $flag) {
  690. system(getenv('CC').&quot; $flag &gt;/dev/null 2&gt;&amp;1&quot;, $cc_status);
  691. if ($cc_status == 0) {
  692. $compiler = shell_exec(getenv('CC').&quot; $flag 2&gt;&amp;1&quot;);
  693. break;
  694. }
  695. }
  696. $ldd = shell_exec(&quot;ldd $php 2&gt;/dev/null&quot;);
  697. }
  698. $failed_tests_data .= &quot;Autoconf:\n$autoconf\n&quot;;
  699. $failed_tests_data .= &quot;Bundled Libtool:\n$libtool\n&quot;;
  700. $failed_tests_data .= &quot;System Libtool:\n$sys_libtool\n&quot;;
  701. $failed_tests_data .= &quot;Compiler:\n$compiler\n&quot;;
  702. $failed_tests_data .= &quot;Bison:\n&quot;. @shell_exec('bison --version 2&gt;/dev/null'). &quot;\n&quot;;
  703. $failed_tests_data .= &quot;Libraries:\n$ldd\n&quot;;
  704. $failed_tests_data .= &quot;\n&quot;;
  705. if (isset($user_email)) {
  706. $failed_tests_data .= &quot;User's E-mail: &quot;.$user_email.&quot;\n\n&quot;;
  707. }
  708. $failed_tests_data .= $sep . &quot;PHPINFO&quot; . $sep;
  709. $failed_tests_data .= shell_exec($php.' -dhtml_errors=0 -i');
  710. if ($just_save_results || !mail_qa_team($failed_tests_data, $compression, $status)) {
  711. file_put_contents($output_file, $failed_tests_data);
  712. if (!$just_save_results) {
  713. echo &quot;\nThe test script was unable to automatically send the report to PHP's QA Team\n&quot;;
  714. }
  715. echo &quot;Please send &quot;.$output_file.&quot; to &quot;.PHP_QA_EMAIL.&quot; manually, thank you.\n&quot;;
  716. } else {
  717. fwrite($fp, &quot;\nThank you for helping to make PHP better.\n&quot;);
  718. fclose($fp);
  719. }
  720. }
  721. }
  722. if (getenv('REPORT_EXIT_STATUS') == 1 and $sum_results['FAILED']) {
  723. exit(1);
  724. }
  725. exit(0);
  726. //
  727. // Send Email to QA Team
  728. //
  729. function mail_qa_team($data, $compression, $status = FALSE)
  730. {
  731. $url_bits = parse_url(QA_SUBMISSION_PAGE);
  732. if (empty($url_bits['port'])) $url_bits['port'] = 80;
  733. $data = &quot;php_test_data=&quot; . urlencode(base64_encode(str_replace(&quot;\00&quot;, '[0x0]', $data)));
  734. $data_length = strlen($data);
  735. $fs = fsockopen($url_bits['host'], $url_bits['port'], $errno, $errstr, 10);
  736. if (!$fs) {
  737. return FALSE;
  738. }
  739. $php_version = urlencode(TESTED_PHP_VERSION);
  740. echo &quot;\nPosting to {$url_bits['host']} {$url_bits['path']}\n&quot;;
  741. fwrite($fs, &quot;POST &quot;.$url_bits['path'].&quot;?status=$status&amp;version=$php_version HTTP/1.1\r\n&quot;);
  742. fwrite($fs, &quot;Host: &quot;.$url_bits['host'].&quot;\r\n&quot;);
  743. fwrite($fs, &quot;User-Agent: QA Browser 0.1\r\n&quot;);
  744. fwrite($fs, &quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;);
  745. fwrite($fs, &quot;Content-Length: &quot;.$data_length.&quot;\r\n\r\n&quot;);
  746. fwrite($fs, $data);
  747. fwrite($fs, &quot;\r\n\r\n&quot;);
  748. fclose($fs);
  749. return 1;
  750. }
  751. //
  752. // Write the given text to a temporary file, and return the filename.
  753. //
  754. function save_text($filename, $text, $filename_copy = null)
  755. {
  756. global $DETAILED;
  757. if ($filename_copy &amp;&amp; $filename_copy != $filename) {
  758. if (@file_put_contents($filename_copy, $text) === false) {
  759. error(&quot;Cannot open file '&quot; . $filename_copy . &quot;' (save_text)&quot;);
  760. }
  761. }
  762. if (@file_put_contents($filename, $text) === false) {
  763. error(&quot;Cannot open file '&quot; . $filename . &quot;' (save_text)&quot;);
  764. }
  765. if (1 &lt; $DETAILED) echo &quot;
  766. FILE $filename {{{
  767. $text
  768. }}}
  769. &quot;;
  770. }
  771. //
  772. // Write an error in a format recognizable to Emacs or MSVC.
  773. //
  774. function error_report($testname, $logname, $tested)
  775. {
  776. $testname = realpath($testname);
  777. $logname = realpath($logname);
  778. switch (strtoupper(getenv('TEST_PHP_ERROR_STYLE'))) {
  779. case 'MSVC':
  780. echo $testname . &quot;(1) : $tested\n&quot;;
  781. echo $logname . &quot;(1) : $tested\n&quot;;
  782. break;
  783. case 'EMACS':
  784. echo $testname . &quot;:1: $tested\n&quot;;
  785. echo $logname . &quot;:1: $tested\n&quot;;
  786. break;
  787. }
  788. }
  789. function system_with_timeout($commandline, $env = null, $stdin = null)
  790. {
  791. global $leak_check;
  792. $data = &quot;&quot;;
  793. $proc = proc_open($commandline, array(
  794. 0 =&gt; array('pipe', 'r'),
  795. 1 =&gt; array('pipe', 'w'),
  796. 2 =&gt; array('pipe', 'w')
  797. ), $pipes, null, $env, array(&quot;suppress_errors&quot; =&gt; true));
  798. if (!$proc)
  799. return false;
  800. if (is_string($stdin)) {
  801. fwrite($pipes[0], $stdin);
  802. }
  803. fclose($pipes[0]);
  804. while (true) {
  805. /* hide errors from interrupted syscalls */
  806. $r = $pipes;
  807. $w = null;
  808. $e = null;
  809. $n = @stream_select($r, $w, $e, $leak_check ? 300 : 60);
  810. if ($n === 0) {
  811. /* timed out */
  812. $data .= &quot;\n ** ERROR: process timed out **\n&quot;;
  813. proc_terminate($proc);
  814. return $data;
  815. } else if ($n &gt; 0) {
  816. $line = fread($pipes[1], 8192);
  817. if (strlen($line) == 0) {
  818. /* EOF */
  819. break;
  820. }
  821. $data .= $line;
  822. }
  823. }
  824. $stat = proc_get_status($proc);
  825. if ($stat['signaled']) {
  826. $data .= &quot;\nTermsig=&quot;.$stat['stopsig'];
  827. }
  828. $code = proc_close($proc);
  829. return $data;
  830. }
  831. function run_all_tests($test_files, $env, $redir_tested = NULL)
  832. {
  833. global $test_results, $failed_tests_file, $php, $test_cnt, $test_idx;
  834. foreach($test_files as $name)
  835. {
  836. if (is_array($name))
  837. {
  838. $index = &quot;# $name[1]: $name[0]&quot;;
  839. if ($redir_tested)
  840. {
  841. $name = $name[0];
  842. }
  843. }
  844. else if ($redir_tested)
  845. {
  846. $index = &quot;# $redir_tested: $name&quot;;
  847. }
  848. else
  849. {
  850. $index = $name;
  851. }
  852. $test_idx++;
  853. $result = run_test($php, $name, $env);
  854. if (!is_array($name) &amp;&amp; $result != 'REDIR')
  855. {
  856. $test_results[$index] = $result;
  857. if ($failed_tests_file &amp;&amp; ($result == 'FAILED' || $result == 'WARNED' || $result == 'LEAKED'))
  858. {
  859. fwrite($failed_tests_file, &quot;$index\n&quot;);
  860. }
  861. }
  862. }
  863. }
  864. //
  865. // Run an individual test case.
  866. //
  867. function run_test($php, $file, $env)
  868. {
  869. global $log_format, $info_params, $ini_overwrites, $cwd, $PHP_FAILED_TESTS;
  870. global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx;
  871. global $leak_check, $temp_source, $temp_target, $cfg, $environment;
  872. global $no_clean;
  873. global $valgrind_version;
  874. $temp_filenames = null;
  875. $org_file = $file;
  876. if (isset($env['TEST_PHP_CGI_EXECUTABLE'])) {
  877. $php_cgi = $env['TEST_PHP_CGI_EXECUTABLE'];
  878. }
  879. if (is_array($file)) $file = $file[0];
  880. if ($DETAILED) echo &quot;
  881. =================
  882. TEST $file
  883. &quot;;
  884. // Load the sections of the test file.
  885. $section_text = array(
  886. 'TEST' =&gt; '',
  887. 'SKIPIF' =&gt; '',
  888. 'GET' =&gt; '',
  889. 'COOKIE' =&gt; '',
  890. 'POST_RAW' =&gt; '',
  891. 'POST' =&gt; '',
  892. 'UPLOAD' =&gt; '',
  893. 'ARGS' =&gt; '',
  894. );
  895. $fp = fopen($file, &quot;rt&quot;) or error(&quot;Cannot open test file: $file&quot;);
  896. $borked = false;
  897. $bork_info = '';
  898. if (!feof($fp)) {
  899. $line = fgets($fp);
  900. } else {
  901. $bork_info = &quot;empty test [$file]&quot;;
  902. $borked = true;
  903. }
  904. if (strncmp('--TEST--', $line, 8)) {
  905. $bork_info = &quot;tests must start with --TEST-- [$file]&quot;;
  906. $borked = true;
  907. }
  908. $section = 'TEST';
  909. $secfile = false;
  910. $secdone = false;
  911. while (!feof($fp)) {
  912. $line = fgets($fp);
  913. // Match the beginning of a section.
  914. if (preg_match('/^--([_A-Z]+)--/', $line, $r)) {
  915. $section = $r[1];
  916. $section_text[$section] = '';
  917. $secfile = $section == 'FILE' || $section == 'FILEEOF' || $section == 'FILE_EXTERNAL';
  918. $secdone = false;
  919. continue;
  920. }
  921. // Add to the section text.
  922. if (!$secdone) {
  923. $section_text[$section] .= $line;
  924. }
  925. // End of actual test?
  926. if ($secfile &amp;&amp; preg_match('/^===DONE===$/', $line)) {
  927. $secdone = true;
  928. }
  929. }
  930. // the redirect section allows a set of tests to be reused outside of
  931. // a given test dir
  932. if (@count($section_text['REDIRECTTEST']) == 1) {
  933. if ($IN_REDIRECT) {
  934. $borked = true;
  935. $bork_info = &quot;Can't redirect a test from within a redirected test&quot;;
  936. } else {
  937. $borked = false;
  938. }
  939. } else {
  940. if (@count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) {
  941. $bork_info = &quot;missing section --FILE--&quot;;
  942. $borked = true;
  943. }
  944. if (@count($section_text['FILEEOF']) == 1) {
  945. $section_text['FILE'] = preg_replace(&quot;/[\r\n]+$/&quot;, '', $section_text['FILEEOF']);
  946. unset($section_text['FILEEOF']);
  947. }
  948. if (@count($section_text['FILE_EXTERNAL']) == 1) {
  949. // don't allow tests to retrieve files from anywhere but this subdirectory
  950. $section_text['FILE_EXTERNAL'] = dirname($file) . '/' . trim(str_replace('..', '', $section_text['FILE_EXTERNAL']));
  951. if (@file_exists($section_text['FILE_EXTERNAL'])) {
  952. $section_text['FILE'] = file_get_contents($section_text['FILE_EXTERNAL']);
  953. unset($section_text['FILE_EXTERNAL']);
  954. } else {
  955. $bork_info = &quot;could not load --FILE_EXTERNAL-- &quot; . dirname($file) . '/' . trim($section_text['FILE_EXTERNAL']);
  956. $borked = true;
  957. }
  958. }
  959. if ((@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX'])) != 1) {
  960. $bork_info = &quot;missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--&quot;;
  961. $borked = true;
  962. }
  963. }
  964. fclose($fp);
  965. $shortname = str_replace($cwd.'/', '', $file);
  966. $tested_file = $shortname;
  967. if ($borked) {
  968. show_result(&quot;BORK&quot;, $bork_info, $tested_file);
  969. $PHP_FAILED_TESTS['BORKED'][] = array (
  970. 'name' =&gt; $file,
  971. 'test_name' =&gt; '',
  972. 'output' =&gt; '',
  973. 'diff' =&gt; '',
  974. 'info' =&gt; &quot;$bork_info [$file]&quot;,
  975. );
  976. return 'BORKED';
  977. }
  978. $tested = trim($section_text['TEST']);
  979. /* For GET/POST tests, check if cgi sapi is available and if it is, use it. */
  980. if (!empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) {
  981. if (isset($php_cgi)) {
  982. $old_php = $php;
  983. $php = $php_cgi .' -C ';
  984. } elseif (!strncasecmp(PHP_OS, &quot;win&quot;, 3) &amp;&amp; file_exists(dirname($php) .&quot;/php-cgi.exe&quot;)) {
  985. $old_php = $php;
  986. $php = realpath(dirname($php) .&quot;/php-cgi.exe&quot;) .' -C ';
  987. } else {
  988. if (file_exists(dirname($php).&quot;/../../sapi/cgi/php-cgi&quot;)) {
  989. $old_php = $php;
  990. $php = realpath(dirname($php).&quot;/../../sapi/cgi/php-cgi&quot;) . ' -C ';
  991. } else if (file_exists(&quot;./sapi/cgi/php-cgi&quot;)) {
  992. $old_php = $php;
  993. $php = realpath(&quot;./sapi/cgi/php-cgi&quot;) . ' -C ';
  994. } else {
  995. show_result(&quot;SKIP&quot;, $tested, $tested_file, &quot;reason: CGI not available&quot;);
  996. return 'SKIPPED';
  997. }
  998. }
  999. }
  1000. show_test($test_idx, $shortname);
  1001. if (is_array($IN_REDIRECT)) {
  1002. $temp_dir = $test_dir = $IN_REDIRECT['dir'];
  1003. } else {
  1004. $temp_dir = $test_dir = realpath(dirname($file));
  1005. }
  1006. if ($temp_source &amp;&amp; $temp_target) {
  1007. $temp_dir = str_replace($temp_source, $temp_target, $temp_dir);
  1008. }
  1009. $main_file_name = basename($file,'phpt');
  1010. $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'diff';
  1011. $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'log';
  1012. $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'exp';
  1013. $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'out';
  1014. $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'mem';
  1015. $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'php';
  1016. $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'php';
  1017. $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php';
  1018. $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php';
  1019. $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php';
  1020. $test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php';
  1021. $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('/phpt.');
  1022. $tmp_relative_file = str_replace(dirname(__FILE__).DIRECTORY_SEPARATOR, '', $test_file) . 't';
  1023. if ($temp_source &amp;&amp; $temp_target) {
  1024. $temp_skipif .= 's';
  1025. $temp_file .= 's';
  1026. $temp_clean .= 's';
  1027. $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file[1] : $file).'.phps';
  1028. if (!is_dir(dirname($copy_file))) {
  1029. @mkdir(dirname($copy_file), 0777, true) or error(&quot;Cannot create output directory - &quot; . dirname($copy_file));
  1030. }
  1031. if (isset($section_text['FILE'])) {
  1032. save_text($copy_file, $section_text['FILE']);
  1033. }
  1034. $temp_filenames = array(
  1035. 'file' =&gt; $copy_file,
  1036. 'diff' =&gt; $diff_filename,
  1037. 'log' =&gt; $log_filename,
  1038. 'exp' =&gt; $exp_filename,
  1039. 'out' =&gt; $output_filename,
  1040. 'mem' =&gt; $memcheck_filename,
  1041. 'php' =&gt; $temp_file,
  1042. 'skip' =&gt; $temp_skipif,
  1043. 'clean'=&gt; $temp_clean);
  1044. }
  1045. if (is_array($IN_REDIRECT)) {
  1046. $tested = $IN_REDIRECT['prefix'] . ' ' . trim($section_text['TEST']);
  1047. $tested_file = $tmp_relative_file;
  1048. $section_text['FILE'] = &quot;# original source file: $shortname\n&quot; . $section_text['FILE'];
  1049. }
  1050. // unlink old test results
  1051. @unlink($diff_filename);
  1052. @unlink($log_filename);
  1053. @unlink($exp_filename);
  1054. @unlink($output_filename);
  1055. @unlink($memcheck_filename);
  1056. @unlink($temp_file);
  1057. @unlink($test_file);
  1058. @unlink($temp_skipif);
  1059. @unlink($test_skipif);
  1060. @unlink($tmp_post);
  1061. @unlink($temp_clean);
  1062. @unlink($test_clean);
  1063. // Reset environment from any previous test.
  1064. $env['REDIRECT_STATUS']='';
  1065. $env['QUERY_STRING']='';
  1066. $env['PATH_TRANSLATED']='';
  1067. $env['SCRIPT_FILENAME']='';
  1068. $env['REQUEST_METHOD']='';
  1069. $env['CONTENT_TYPE']='';
  1070. $env['CONTENT_LENGTH']='';
  1071. if (!empty($section_text['ENV'])) {
  1072. foreach(explode(&quot;\n&quot;, trim($section_text['ENV'])) as $e) {
  1073. $e = explode('=',trim($e),2);
  1074. if (!empty($e[0]) &amp;&amp; isset($e[1])) {
  1075. $env[$e[0]] = $e[1];
  1076. }
  1077. }
  1078. }
  1079. // Default ini settings
  1080. $ini_settings = array();
  1081. // additional ini overwrites
  1082. //$ini_overwrites[] = 'setting=value';
  1083. settings2array($ini_overwrites, $ini_settings);
  1084. // Any special ini settings
  1085. // these may overwrite the test defaults...
  1086. if (array_key_exists('INI', $section_text)) {
  1087. if (strpos($section_text['INI'], '{PWD}') !== false) {
  1088. $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']);
  1089. }
  1090. settings2array(preg_split( &quot;/[\n\r]+/&quot;, $section_text['INI']), $ini_settings);
  1091. }
  1092. settings2params($ini_settings);
  1093. // Check if test should be skipped.
  1094. $info = '';
  1095. $warn = false;
  1096. if (array_key_exists('SKIPIF', $section_text)) {
  1097. if (trim($section_text['SKIPIF'])) {
  1098. if ($cfg['show']['skip']) {
  1099. echo &quot;\n========SKIP========\n&quot;;
  1100. echo $section_text['SKIPIF'];
  1101. echo &quot;========DONE========\n&quot;;
  1102. }
  1103. save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif);
  1104. $extra = substr(PHP_OS, 0, 3) !== &quot;WIN&quot; ?
  1105. &quot;unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;&quot;: &quot;&quot;;
  1106. if ($leak_check) {
  1107. $env['USE_ZEND_ALLOC'] = '0';
  1108. } else {
  1109. $env['USE_ZEND_ALLOC'] = '1';
  1110. }
  1111. $output = system_with_timeout(&quot;$extra $php $pass_options -q $ini_settings $test_skipif&quot;, $env);
  1112. if (!$cfg['keep']['skip']) {
  1113. @unlink($test_skipif);
  1114. }
  1115. if (!strncasecmp('skip', ltrim($output), 4)) {
  1116. if (preg_match('/^\s*skip\s*(.+)\s*/i', $output, $m)) {
  1117. show_result(&quot;SKIP&quot;, $tested, $tested_file, &quot;reason: $m[1]&quot;, $temp_filenames);
  1118. } else {
  1119. show_result(&quot;SKIP&quot;, $tested, $tested_file, '', $temp_filenames);
  1120. }
  1121. if (isset($old_php)) {
  1122. $php = $old_php;
  1123. }
  1124. if (!$cfg['keep']['skip']) {
  1125. @unlink($test_skipif);
  1126. }
  1127. return 'SKIPPED';
  1128. }
  1129. if (!strncasecmp('info', ltrim($output), 4)) {
  1130. if (preg_match('/^\s*info\s*(.+)\s*/i', $output, $m)) {
  1131. $info = &quot; (info: $m[1])&quot;;
  1132. }
  1133. }
  1134. if (!strncasecmp('warn', ltrim($output), 4)) {
  1135. if (preg_match('/^\s*warn\s*(.+)\s*/i', $output, $m)) {
  1136. $warn = true; /* only if there is a reason */
  1137. $info = &quot; (warn: $m[1])&quot;;
  1138. }
  1139. }
  1140. }
  1141. }
  1142. if (@count($section_text['REDIRECTTEST']) == 1) {
  1143. $test_files = array();
  1144. $IN_REDIRECT = eval($section_text['REDIRECTTEST']);
  1145. $IN_REDIRECT['via'] = &quot;via [$shortname]\n\t&quot;;
  1146. $IN_REDIRECT['dir'] = realpath(dirname($file));
  1147. $IN_REDIRECT['prefix'] = trim($section_text['TEST']);
  1148. if (@count($IN_REDIRECT['TESTS']) == 1) {
  1149. if (is_array($org_file)) {
  1150. $test_files[] = $org_file[1];
  1151. } else {
  1152. $GLOBALS['test_files'] = $test_files;
  1153. find_files($IN_REDIRECT['TESTS']);
  1154. foreach($GLOBALS['test_files'] as $f) {
  1155. $test_files[] = array($f, $file);
  1156. }
  1157. }
  1158. $test_cnt += count($test_files) - 1;
  1159. $test_idx--;
  1160. show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file);
  1161. // set up environment
  1162. $redirenv = array_merge($environment, $IN_REDIRECT['ENV']);
  1163. $redirenv['REDIR_TEST_DIR'] = realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR;
  1164. usort($test_files, &quot;test_sort&quot;);
  1165. run_all_tests($test_files, $redirenv, $tested);
  1166. show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file);
  1167. // a redirected test never fails
  1168. $IN_REDIRECT = false;
  1169. return 'REDIR';
  1170. } else {
  1171. $bork_info = &quot;Redirect info must contain exactly one TEST string to be used as redirect directory.&quot;;
  1172. show_result(&quot;BORK&quot;, $bork_info, '', $temp_filenames);
  1173. $PHP_FAILED_TESTS['BORKED'][] = array (
  1174. 'name' =&gt; $file,
  1175. 'test_name' =&gt; '',
  1176. 'output' =&gt; '',
  1177. 'diff' =&gt; '',
  1178. 'info' =&gt; &quot;$bork_info [$file]&quot;,
  1179. 'unicode'=&gt; $unicode_semantics,
  1180. );
  1181. }
  1182. }
  1183. if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) {
  1184. if (is_array($org_file)) $file = $org_file[0];
  1185. $bork_info = &quot;Redirected test did not contain redirection info&quot;;
  1186. show_result(&quot;BORK&quot;, $bork_info, '', $temp_filenames);
  1187. $PHP_FAILED_TESTS['BORKED'][] = array (
  1188. 'name' =&gt; $file,
  1189. 'test_name' =&gt; '',
  1190. 'output' =&gt; '',
  1191. 'diff' =&gt; '',
  1192. 'info' =&gt; &quot;$bork_info [$file]&quot;,
  1193. );
  1194. //$test_cnt -= 1; // Only if is_array($org_file) ?
  1195. //$test_idx--;
  1196. return 'BORKED';
  1197. }
  1198. // We've satisfied the preconditions - run the test!
  1199. if ($cfg['show']['php']) {
  1200. echo &quot;\n========TEST========\n&quot;;
  1201. echo $section_text['FILE'];
  1202. echo &quot;========DONE========\n&quot;;
  1203. }
  1204. save_text($test_file, $section_text['FILE'], $temp_file);
  1205. if (array_key_exists('GET', $section_text)) {
  1206. $query_string = trim($section_text['GET']);
  1207. } else {
  1208. $query_string = '';
  1209. }
  1210. $env['REDIRECT_STATUS'] = '1';
  1211. $env['QUERY_STRING'] = $query_string;
  1212. $env['PATH_TRANSLATED'] = $test_file;
  1213. $env['SCRIPT_FILENAME'] = $test_file;
  1214. if (array_key_exists('COOKIE', $section_text)) {
  1215. $env['HTTP_COOKIE'] = trim($section_text['COOKIE']);
  1216. } else {
  1217. $env['HTTP_COOKIE'] = '';
  1218. }
  1219. $args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : '';
  1220. if (array_key_exists('POST_RAW', $section_text) &amp;&amp; !empty($section_text['POST_RAW'])) {
  1221. $post = trim($section_text['POST_RAW']);
  1222. $raw_lines = explode(&quot;\n&quot;, $post);
  1223. $request = '';
  1224. $started = false;
  1225. foreach ($raw_lines as $line) {
  1226. if (empty($env['CONTENT_TYPE']) &amp;&amp; preg_match('/^Content-Type:(.*)/i', $line, $res)) {
  1227. $env['CONTENT_TYPE'] = trim(str_replace(&quot;\r&quot;, '', $res[1]));
  1228. continue;
  1229. }
  1230. if ($started) $request .= &quot;\n&quot;;
  1231. $started = true;
  1232. $request .= $line;
  1233. }
  1234. $env['CONTENT_LENGTH'] = strlen($request);
  1235. $env['REQUEST_METHOD'] = 'POST';
  1236. if (empty($request)) {
  1237. return 'BORKED';
  1238. }
  1239. save_text($tmp_post, $request);
  1240. $cmd = &quot;$php$pass_options$ini_settings -f \&quot;$test_file\&quot; 2&gt;&amp;1 &lt; $tmp_post&quot;;
  1241. } elseif (array_key_exists('POST', $section_text) &amp;&amp; !empty($section_text['POST'])) {
  1242. $post = trim($section_text['POST']);
  1243. if (array_key_exists('GZIP_POST', $section_text) &amp;&amp; function_exists('gzencode')) {
  1244. $post = gzencode($post, 9, FORCE_GZIP);
  1245. $env['HTTP_CONTENT_ENCODING'] = 'gzip';
  1246. } else if (array_key_exists('DEFLATE_POST', $section_text) &amp;&amp; function_exists('gzcompress')) {
  1247. $post = gzcompress($post, 9);
  1248. $env['HTTP_CONTENT_ENCODING'] = 'deflate';
  1249. }
  1250. save_text($tmp_post, $post);
  1251. $content_length = strlen($post);
  1252. $env['REQUEST_METHOD'] = 'POST';
  1253. $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
  1254. $env['CONTENT_LENGTH'] = $content_length;
  1255. $cmd = &quot;$php$pass_options$ini_settings -f \&quot;$test_file\&quot; 2&gt;&amp;1 &lt; $tmp_post&quot;;
  1256. } else {
  1257. $env['REQUEST_METHOD'] = 'GET';
  1258. $env['CONTENT_TYPE'] = '';
  1259. $env['CONTENT_LENGTH'] = '';
  1260. $cmd = &quot;$php$pass_options$ini_settings -f \&quot;$test_file\&quot; $args 2&gt;&amp;1&quot;;
  1261. }
  1262. if ($leak_check) {
  1263. $env['USE_ZEND_ALLOC'] = '0';
  1264. if (!$valgrind_version) {
  1265. $valgrind_cmd = &quot;valgrind --version&quot;;
  1266. $out = system_with_timeout($valgrind_cmd);
  1267. $replace_count = 0;
  1268. if (!$out) {
  1269. error(&quot;Valgrind returned no version info, cannot proceed.\nPlease check if Valgrind is installed.&quot;);
  1270. } else {
  1271. $valgrind_version = preg_replace(&quot;/valgrind-([0-9])\.([0-9])\.([0-9]+)(?:-\w+)?\s*/&quot;, '$1$2$3', $out, 1, $replace_count);
  1272. if ($replace_count != 1 || !is_numeric($valgrind_version)) {
  1273. error(&quot;Valgrind returned invalid version info (\&quot;$out\&quot;), cannot proceed.&quot;);
  1274. }
  1275. }
  1276. }
  1277. if ($valgrind_version &lt; 330) {
  1278. $cmd = &quot;valgrind -q --tool=memcheck --trace-children=yes --log-file-exactly=$memcheck_filename $cmd&quot;;
  1279. } else {
  1280. /* valgrind 3.3.0+ doesn't have --log-file-exactly option */
  1281. $cmd = &quot;valgrind -q --tool=memcheck --trace-children=yes --log-file=$memcheck_filename $cmd&quot;;
  1282. }
  1283. } else {
  1284. $env['USE_ZEND_ALLOC'] = '1';
  1285. }
  1286. if ($DETAILED) echo &quot;
  1287. CONTENT_LENGTH = &quot; . $env['CONTENT_LENGTH'] . &quot;
  1288. CONTENT_TYPE = &quot; . $env['CONTENT_TYPE'] . &quot;
  1289. PATH_TRANSLATED = &quot; . $env['PATH_TRANSLATED'] . &quot;
  1290. QUERY_STRING = &quot; . $env['QUERY_STRING'] . &quot;
  1291. REDIRECT_STATUS = &quot; . $env['REDIRECT_STATUS'] . &quot;
  1292. REQUEST_METHOD = &quot; . $env['REQUEST_METHOD'] . &quot;
  1293. SCRIPT_FILENAME = &quot; . $env['SCRIPT_FILENAME'] . &quot;
  1294. HTTP_COOKIE = &quot; . $env['HTTP_COOKIE'] . &quot;
  1295. COMMAND $cmd
  1296. &quot;;
  1297. $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null);
  1298. if (array_key_exists('CLEAN', $section_text) &amp;&amp; (!$no_clean || $cfg['keep']['clean'])) {
  1299. if (trim($section_text['CLEAN'])) {
  1300. if ($cfg['show']['clean']) {
  1301. echo &quot;\n========CLEAN=======\n&quot;;
  1302. echo $section_text['CLEAN'];
  1303. echo &quot;========DONE========\n&quot;;
  1304. }
  1305. save_text($test_clean, trim($section_text['CLEAN']), $temp_clean);
  1306. if (!$no_clean) {
  1307. $clean_params = array();
  1308. settings2array($ini_overwrites,$clean_params);
  1309. settings2params($clean_params);
  1310. $extra = substr(PHP_OS, 0, 3) !== &quot;WIN&quot; ?
  1311. &quot;unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;&quot;: &quot;&quot;;
  1312. system_with_timeout(&quot;$extra $php $pass_options -q $clean_params $test_clean&quot;, $env);
  1313. }
  1314. if (!$cfg['keep']['clean']) {
  1315. @unlink($test_clean);
  1316. }
  1317. }
  1318. }
  1319. @unlink($tmp_post);
  1320. $leaked = false;
  1321. $passed = false;
  1322. if ($leak_check) { // leak check
  1323. $leaked = @filesize($memcheck_filename) &gt; 0;
  1324. if (!$leaked) {
  1325. @unlink($memcheck_filename);
  1326. }
  1327. }
  1328. // Does the output match what is expected?
  1329. $output = str_replace(&quot;\r\n&quot;, &quot;\n&quot;, trim($out));
  1330. /* when using CGI, strip the headers from the output */
  1331. $headers = &quot;&quot;;
  1332. if (isset($old_php) &amp;&amp; preg_match(&quot;/^(.*?)\r?\n\r?\n(.*)/s&quot;, $out, $match)) {
  1333. $output = trim($match[2]);
  1334. $rh = preg_split(&quot;/[\n\r]+/&quot;,$match[1]);
  1335. $headers = array();
  1336. foreach ($rh as $line) {
  1337. if (strpos($line, ':')!==false) {
  1338. $line = explode(':', $line, 2);
  1339. $headers[trim($line[0])] = trim($line[1]);
  1340. }
  1341. }
  1342. }
  1343. $failed_headers = false;
  1344. if (isset($section_text['EXPECTHEADERS'])) {
  1345. $want = array();
  1346. $wanted_headers = array();
  1347. $lines = preg_split(&quot;/[\n\r]+/&quot;,$section_text['EXPECTHEADERS']);
  1348. foreach($lines as $line) {
  1349. if (strpos($line, ':') !== false) {
  1350. $line = explode(':', $line, 2);
  1351. $want[trim($line[0])] = trim($line[1]);
  1352. $wanted_headers[] = trim($line[0]) . ': ' . trim($line[1]);
  1353. }
  1354. }
  1355. $org_headers = $headers;
  1356. $headers = array();
  1357. $output_headers = array();
  1358. foreach($want as $k =&gt; $v) {
  1359. if (isset($org_headers[$k])) {
  1360. $headers = $org_headers[$k];
  1361. $output_headers[] = $k . ': ' . $org_headers[$k];
  1362. }
  1363. if (!isset($org_headers[$k]) || $org_headers[$k] != $v) {
  1364. $failed_headers = true;
  1365. }
  1366. }
  1367. ksort($wanted_headers);
  1368. $wanted_he

Large files files are truncated, but you can click here to view the full file