PageRenderTime 31ms CodeModel.GetById 45ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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