You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1970 lines
58 KiB

24 years ago
21 years ago
24 years ago
23 years ago
20 years ago
24 years ago
21 years ago
20 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
24 years ago
21 years ago
20 years ago
20 years ago
21 years ago
20 years ago
20 years ago
20 years ago
20 years ago
22 years ago
22 years ago
24 years ago
24 years ago
24 years ago
24 years ago
23 years ago
22 years ago
24 years ago
21 years ago
24 years ago
23 years ago
24 years ago
20 years ago
24 years ago
24 years ago
24 years ago
21 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
20 years ago
24 years ago
24 years ago
24 years ago
20 years ago
24 years ago
20 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
20 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
24 years ago
24 years ago
23 years ago
23 years ago
21 years ago
24 years ago
  1. <?php
  2. /*
  3. +----------------------------------------------------------------------+
  4. | PHP Version 5 |
  5. +----------------------------------------------------------------------+
  6. | Copyright (c) 1997-2006 The PHP Group |
  7. +----------------------------------------------------------------------+
  8. | This source file is subject to version 3.01 of the PHP license, |
  9. | that is bundled with this package in the file LICENSE, and is |
  10. | available through the world-wide-web at the following url: |
  11. | http://www.php.net/license/3_01.txt |
  12. | If you did not receive a copy of the PHP license and are unable to |
  13. | obtain it through the world-wide-web, please send a note to |
  14. | license@php.net so we can mail you a copy immediately. |
  15. +----------------------------------------------------------------------+
  16. | Authors: Ilia Alshanetsky <iliaa@php.net> |
  17. | Preston L. Bannister <pbannister@php.net> |
  18. | Marcus Boerger <helly@php.net> |
  19. | Derick Rethans <derick@php.net> |
  20. | Sander Roobol <sander@php.net> |
  21. | (based on version by: Stig Bakken <ssb@php.net>) |
  22. | (based on the PHP 3 test framework by Rasmus Lerdorf) |
  23. +----------------------------------------------------------------------+
  24. */
  25. /* $Id$ */
  26. /* Sanity check to ensure that pcre extension needed by this script is available.
  27. * In the event it is not, print a nice error message indicating that this script will
  28. * not run without it.
  29. */
  30. if (!extension_loaded("pcre")) {
  31. echo <<<NO_PCRE_ERROR
  32. +-----------------------------------------------------------+
  33. | ! ERROR ! |
  34. | The test-suite requires that you have pcre extension |
  35. | enabled. To enable this extension either compile your PHP |
  36. | with --with-pcre-regex or if you've compiled pcre as a |
  37. | shared module load it via php.ini. |
  38. +-----------------------------------------------------------+
  39. NO_PCRE_ERROR;
  40. exit;
  41. }
  42. if (!function_exists("proc_open")) {
  43. echo <<<NO_PROC_OPEN_ERROR
  44. +-----------------------------------------------------------+
  45. | ! ERROR ! |
  46. | The test-suite requires that proc_open() is available. |
  47. | Please check if you disabled it in php.ini. |
  48. +-----------------------------------------------------------+
  49. NO_PROC_OPEN_ERROR;
  50. exit;
  51. }
  52. // store current directory
  53. $CUR_DIR = getcwd();
  54. // change into the PHP source directory.
  55. if (getenv('TEST_PHP_SRCDIR')) {
  56. @chdir(getenv('TEST_PHP_SRCDIR'));
  57. }
  58. // Delete some security related environment variables
  59. putenv('SSH_CLIENT=deleted');
  60. putenv('SSH_AUTH_SOCK=deleted');
  61. putenv('SSH_TTY=deleted');
  62. putenv('SSH_CONNECTION=deleted');
  63. $cwd = getcwd();
  64. set_time_limit(0);
  65. // delete as much output buffers as possible
  66. while(@ob_end_clean());
  67. if (ob_get_level()) echo "Not all buffers were deleted.\n";
  68. error_reporting(E_ALL);
  69. ini_set('magic_quotes_runtime',0); // this would break tests by modifying EXPECT sections
  70. $environment = isset($_ENV) ? $_ENV : array();
  71. // Don't ever guess at the PHP executable location.
  72. // Require the explicit specification.
  73. // Otherwise we could end up testing the wrong file!
  74. if (getenv('TEST_PHP_EXECUTABLE')) {
  75. $php = getenv('TEST_PHP_EXECUTABLE');
  76. if ($php=='auto') {
  77. $php = $cwd.'/sapi/cli/php';
  78. putenv("TEST_PHP_EXECUTABLE=$php");
  79. }
  80. $environment['TEST_PHP_EXECUTABLE'] = $php;
  81. }
  82. if (getenv('TEST_PHP_CGI_EXECUTABLE')) {
  83. $php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE');
  84. if ($php_cgi=='auto') {
  85. $php_cgi = $cwd.'/sapi/cgi/php';
  86. putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi");
  87. }
  88. $environment['TEST_PHP_CGI_EXECUTABLE'] = $php_cgi;
  89. }
  90. if ($argc !=2 || ($argv[1] != '-h' && $argv[1] != '-help' && $argv != '--help'))
  91. {
  92. if (empty($php) || !file_exists($php)) {
  93. error("environment variable TEST_PHP_EXECUTABLE must be set to specify PHP executable!");
  94. }
  95. if (function_exists('is_executable') && !@is_executable($php)) {
  96. error("invalid PHP executable specified by TEST_PHP_EXECUTABLE = " . $php);
  97. }
  98. }
  99. if (getenv('TEST_PHP_LOG_FORMAT')) {
  100. $log_format = strtoupper(getenv('TEST_PHP_LOG_FORMAT'));
  101. } else {
  102. $log_format = 'LEOD';
  103. }
  104. // Check whether a detailed log is wanted.
  105. if (getenv('TEST_PHP_DETAILED')) {
  106. $DETAILED = getenv('TEST_PHP_DETAILED');
  107. } else {
  108. $DETAILED = 0;
  109. }
  110. // Check whether user test dirs are requested.
  111. if (getenv('TEST_PHP_USER')) {
  112. $user_tests = explode (',', getenv('TEST_PHP_USER'));
  113. } else {
  114. $user_tests = array();
  115. }
  116. $exts_to_test = array();
  117. $ini_overwrites = array(
  118. 'output_handler=',
  119. 'open_basedir=',
  120. 'disable_functions=',
  121. 'output_buffering=Off',
  122. 'error_reporting=8191',
  123. 'display_errors=1',
  124. 'log_errors=0',
  125. 'html_errors=0',
  126. 'track_errors=1',
  127. 'report_memleaks=1',
  128. 'report_zend_debug=0',
  129. 'docref_root=',
  130. 'docref_ext=.html',
  131. 'error_prepend_string=',
  132. 'error_append_string=',
  133. 'auto_prepend_file=',
  134. 'auto_append_file=',
  135. 'magic_quotes_runtime=0',
  136. );
  137. function write_information($show_html)
  138. {
  139. global $cwd, $php, $php_info, $user_tests, $ini_overwrites, $pass_options, $exts_to_test;
  140. // Get info from php
  141. $info_file = realpath(dirname(__FILE__)) . '/run-test-info.php';
  142. @unlink($info_file);
  143. $php_info = '<?php echo "
  144. PHP_SAPI : " , PHP_SAPI , "
  145. PHP_VERSION : " , phpversion() , "
  146. ZEND_VERSION: " , zend_version() , "
  147. PHP_OS : " , PHP_OS , " - " , php_uname() , "
  148. UNICODE : " , (ini_get("unicode_semantics") ? "ON" : "OFF") , "
  149. INI actual : " , realpath(get_cfg_var("cfg_file_path")) , "
  150. More .INIs : " , (function_exists(\'php_ini_scanned_files\') ? str_replace("\n","", php_ini_scanned_files()) : "** not determined **"); ?>';
  151. save_text($info_file, $php_info);
  152. $info_params = array();
  153. settings2array($ini_overwrites,$info_params);
  154. settings2params($info_params);
  155. $php_info = `$php $pass_options $info_params $info_file`;
  156. @unlink($info_file);
  157. define('TESTED_PHP_VERSION', `$php -r 'echo PHP_VERSION;'`);
  158. $unicode = `$php $pass_options $info_params -r 'echo ini_get("unicode_semantics");'`;
  159. define('TESTED_UNICODE', strcasecmp($unicode,"on") == 0 || $unicode == 1);
  160. // load list of enabled extensions
  161. save_text($info_file, '<?php echo join(",",get_loaded_extensions()); ?>');
  162. $exts_to_test = explode(',',`$php $pass_options $info_params $info_file`);
  163. // check for extensions that need special handling and regenerate
  164. $info_params_ex = array(
  165. 'session' => array('session.auto_start=0'),
  166. 'zlib' => array('zlib.output_compression=Off'),
  167. 'xdebug' => array('xdebug.default_enable=0'),
  168. );
  169. foreach($info_params_ex as $ext => $ini_overwrites_ex) {
  170. if (in_array($ext, $exts_to_test)) {
  171. $ini_overwrites = array_merge($ini_overwrites, $ini_overwrites_ex);
  172. }
  173. }
  174. @unlink($info_file);
  175. // Write test context information.
  176. echo "
  177. =====================================================================
  178. CWD : $cwd
  179. PHP : $php $php_info
  180. Extra dirs : ";
  181. foreach ($user_tests as $test_dir) {
  182. echo "{$test_dir}\n ";
  183. }
  184. echo "
  185. =====================================================================
  186. ";
  187. }
  188. // Determine the tests to be run.
  189. $test_files = array();
  190. $redir_tests = array();
  191. $test_results = array();
  192. $PHP_FAILED_TESTS = array('BORKED' => array(), 'FAILED' => array(), 'WARNED' => array(), 'LEAKED' => array());
  193. // If parameters given assume they represent selected tests to run.
  194. $failed_tests_file= false;
  195. $pass_option_n = false;
  196. $pass_options = '';
  197. $compression = 0;
  198. $output_file = $CUR_DIR . '/php_test_results_' . date('Ymd_Hi') . '.txt';
  199. if ($compression) {
  200. $output_file = 'compress.zlib://' . $output_file . '.gz';
  201. }
  202. $just_save_results = false;
  203. $leak_check = false;
  204. $unicode_and_native = false;
  205. $unicode_testing = false;
  206. $html_output = false;
  207. $html_file = null;
  208. $temp_source = null;
  209. $temp_target = null;
  210. $temp_urlbase = null;
  211. $conf_passed = null;
  212. $no_clean = false;
  213. $cfgtypes = array('show', 'keep');
  214. $cfgfiles = array('skip', 'php', 'clean');
  215. $cfg = array();
  216. foreach($cfgtypes as $type) {
  217. $cfg[$type] = array();
  218. foreach($cfgfiles as $file) {
  219. $cfg[$type][$file] = false;
  220. }
  221. }
  222. if (getenv('TEST_PHP_ARGS'))
  223. {
  224. if (!isset($argc) || !$argc || !isset($argv))
  225. {
  226. $argv = array(__FILE__);
  227. }
  228. $argv = array_merge($argv, split(' ', getenv('TEST_PHP_ARGS')));
  229. $argc = count($argv);
  230. }
  231. if (isset($argc) && $argc > 1) {
  232. for ($i=1; $i<$argc; $i++) {
  233. $is_switch = false;
  234. $switch = substr($argv[$i],1,1);
  235. $repeat = substr($argv[$i],0,1) == '-';
  236. while ($repeat) {
  237. $repeat = false;
  238. if (!$is_switch) {
  239. $switch = substr($argv[$i],1,1);
  240. }
  241. $is_switch = true;
  242. switch($switch) {
  243. case 'r':
  244. case 'l':
  245. $test_list = @file($argv[++$i]);
  246. if ($test_list) {
  247. foreach($test_list as $test) {
  248. $matches = array();
  249. if (preg_match('/^#.*\[(.*)\]\:\s+(.*)$/', $test, $matches)) {
  250. $redir_tests[] = array($matches[1], $matches[2]);
  251. } else if (strlen($test)) {
  252. $test_files[] = trim($test);
  253. }
  254. }
  255. }
  256. if ($switch != 'l') {
  257. break;
  258. }
  259. $i--;
  260. // break left intentionally
  261. case 'w':
  262. $failed_tests_file = fopen($argv[++$i], 'w+t');
  263. break;
  264. case 'a':
  265. $failed_tests_file = fopen($argv[++$i], 'a+t');
  266. break;
  267. case 'c':
  268. $conf_passed = $argv[++$i];
  269. break;
  270. case 'd':
  271. $ini_overwrites[] = $argv[++$i];
  272. break;
  273. //case 'h'
  274. case '--keep-all':
  275. foreach($cfgfiles as $file) {
  276. $cfg['keep'][$file] = true;
  277. }
  278. break;
  279. case '--keep-skip':
  280. $cfg['keep']['skip'] = true;
  281. break;
  282. case '--keep-php':
  283. $cfg['keep']['php'] = true;
  284. break;
  285. case '--keep-clean':
  286. $cfg['keep']['clean'] = true;
  287. break;
  288. //case 'l'
  289. case 'm':
  290. $leak_check = true;
  291. break;
  292. case 'n':
  293. if (!$pass_option_n) {
  294. $pass_options .= ' -n';
  295. }
  296. $pass_option_n = true;
  297. break;
  298. case 'N':
  299. $unicode_and_native = false;
  300. $unicode_testing = false;
  301. break;
  302. case '--no-clean':
  303. $no_clean = true;
  304. break;
  305. case 'q':
  306. putenv('NO_INTERACTION=1');
  307. break;
  308. //case 'r'
  309. case 's':
  310. $output_file = $argv[++$i];
  311. $just_save_results = true;
  312. break;
  313. case '--show-all':
  314. foreach($cfgfiles as $file) {
  315. $cfg['show'][$file] = true;
  316. }
  317. break;
  318. case '--show-skip':
  319. $cfg['show']['skip'] = true;
  320. break;
  321. case '--show-php':
  322. $cfg['show']['php'] = true;
  323. break;
  324. case '--show-clean':
  325. $cfg['show']['clean'] = true;
  326. break;
  327. case '--temp-source':
  328. $temp_source = $argv[++$i];
  329. break;
  330. case '--temp-target':
  331. $temp_target = $argv[++$i];
  332. if ($temp_urlbase) {
  333. $temp_urlbase = $temp_target;
  334. }
  335. break;
  336. case '--temp-urlbase':
  337. $temp_urlbase = $argv[++$i];
  338. break;
  339. case 'U':
  340. $unicode_and_native = true;
  341. // break;
  342. case 'u':
  343. $unicode_testing = true;
  344. $ini_overwrites[] = 'unicode_semantics=1';
  345. $ini_overwrites[] = 'unicode.runtime_encoding=iso-8859-1';
  346. $ini_overwrites[] = 'unicode.script_encoding=utf-8';
  347. $ini_overwrites[] = 'unicode.output_encoding=utf-8';
  348. $ini_overwrites[] = 'unicode.from_error_mode=U_INVALID_SUBSTITUTE';
  349. break;
  350. case 'v':
  351. case '--verbose':
  352. $DETAILED = true;
  353. break;
  354. //case 'w'
  355. case '-':
  356. // repeat check with full switch
  357. $switch = $argv[$i];
  358. if ($switch != '-') {
  359. $repeat = true;
  360. }
  361. break;
  362. case '--html':
  363. $html_file = @fopen($argv[++$i], 'wt');
  364. $html_output = is_resource($html_file);
  365. break;
  366. case '--version':
  367. echo '$Revision$'."\n";
  368. exit(1);
  369. default:
  370. echo "Illegal switch specified!\n";
  371. //break
  372. case 'h':
  373. case '-help':
  374. case '--help':
  375. echo <<<HELP
  376. Synopsis:
  377. php run-tests.php [options] [files] [directories]
  378. Options:
  379. -l <file> Read the testfiles to be executed from <file>. After the test
  380. has finished all failed tests are written to the same <file>.
  381. If the list is empty and no further test is specified then
  382. all tests are executed (same as: -r <file> -w <file>).
  383. -r <file> Read the testfiles to be executed from <file>.
  384. -w <file> Write a list of all failed tests to <file>.
  385. -a <file> Same as -w but append rather then truncating <file>.
  386. -c <file> Look for php.ini in directory <file> or use <file> as ini.
  387. -n Pass -n option to the php binary (Do not use a php.ini).
  388. -d foo=bar Pass -d option to the php binary (Define INI entry foo
  389. with value 'bar').
  390. -u Test with unicode_semantics set on.
  391. -U Test in unicode and non unicode mode.
  392. -m Test for memory leaks with Valgrind.
  393. -N Test with unicode_semantics set off.
  394. -s <file> Write output to <file>.
  395. -q Quiet, no user interaction (same as environment NO_INTERACTION).
  396. --verbose
  397. -v Verbose mode.
  398. --help
  399. -h This Help.
  400. --html <file> Generate HTML output.
  401. --temp-source <sdir> --temp-target <tdir> [--temp-urlbase <url>]
  402. Write temporary files to <tdir> by replacing <sdir> from the
  403. filenames to generate with <tdir>. If --html is being used and
  404. <url> given then the generated links are relative and prefixed
  405. with the given url. In general you want to make <sdir> the path
  406. to your source files and <tdir> some pach in your web page
  407. hierarchy with <url> pointing to <tdir>.
  408. --keep-[all|php|skip|clean]
  409. Do not delete 'all' files, 'php' test file, 'skip' or 'clean'
  410. file.
  411. --show-[all|php|skip|clean]
  412. Show 'all' files, 'php' test file, 'skip' or 'clean' file.
  413. --no-clean Do not execute clean section if any.
  414. HELP;
  415. exit(1);
  416. }
  417. }
  418. if (!$is_switch) {
  419. $testfile = realpath($argv[$i]);
  420. if (is_dir($testfile)) {
  421. find_files($testfile);
  422. } else if (preg_match("/\.phpt$/", $testfile)) {
  423. $test_files[] = $testfile;
  424. } else {
  425. die("bogus test name " . $argv[$i] . "\n");
  426. }
  427. }
  428. }
  429. if (strlen($conf_passed))
  430. {
  431. $pass_options .= " -c '$conf_passed'";
  432. }
  433. $test_files = array_unique($test_files);
  434. $test_files = array_merge($test_files, $redir_tests);
  435. // Run selected tests.
  436. $test_cnt = count($test_files);
  437. if ($test_cnt) {
  438. write_information($html_output);
  439. usort($test_files, "test_sort");
  440. $start_time = time();
  441. if (!$html_output) {
  442. echo "Running selected tests.\n";
  443. } else {
  444. show_start($start_time);
  445. }
  446. $test_idx = 0;
  447. run_all_tests($test_files, $environment);
  448. $end_time = time();
  449. if ($html_output) {
  450. show_end($end_time);
  451. }
  452. if ($failed_tests_file) {
  453. fclose($failed_tests_file);
  454. }
  455. if (count($test_files) || count($test_results)) {
  456. compute_summary();
  457. if ($html_output) {
  458. fwrite($html_file, "<hr/>\n" . get_summary(false, true));
  459. }
  460. echo "=====================================================================";
  461. echo get_summary(false, false);
  462. }
  463. if ($html_output) {
  464. fclose($html_file);
  465. }
  466. if (getenv('REPORT_EXIT_STATUS') == 1 and ereg('FAILED( |$)', implode(' ', $test_results))) {
  467. exit(1);
  468. }
  469. exit(0);
  470. }
  471. }
  472. write_information($html_output);
  473. // Compile a list of all test files (*.phpt).
  474. $test_files = array();
  475. $exts_tested = count($exts_to_test);
  476. $exts_skipped = 0;
  477. $ignored_by_ext = 0;
  478. sort($exts_to_test);
  479. $test_dirs = array();
  480. $optionals = array('tests', 'ext', 'Zend', 'ZendEngine2');
  481. foreach($optionals as $dir) {
  482. if (@filetype($dir) == 'dir') {
  483. $test_dirs[] = $dir;
  484. }
  485. }
  486. // Convert extension names to lowercase
  487. foreach ($exts_to_test as $key => $val) {
  488. $exts_to_test[$key] = strtolower($val);
  489. }
  490. foreach ($test_dirs as $dir) {
  491. find_files("{$cwd}/{$dir}", ($dir == 'ext'));
  492. }
  493. foreach ($user_tests as $dir) {
  494. find_files($dir, ($dir == 'ext'));
  495. }
  496. function find_files($dir,$is_ext_dir=FALSE,$ignore=FALSE)
  497. {
  498. global $test_files, $exts_to_test, $ignored_by_ext, $exts_skipped, $exts_tested;
  499. $o = opendir($dir) or error("cannot open directory: $dir");
  500. while (($name = readdir($o)) !== FALSE) {
  501. if (is_dir("{$dir}/{$name}") && !in_array($name, array('.', '..', 'CVS'))) {
  502. $skip_ext = ($is_ext_dir && !in_array(strtolower($name), $exts_to_test));
  503. if ($skip_ext) {
  504. $exts_skipped++;
  505. }
  506. find_files("{$dir}/{$name}", FALSE, $ignore || $skip_ext);
  507. }
  508. // Cleanup any left-over tmp files from last run.
  509. if (substr($name, -4) == '.tmp') {
  510. @unlink("$dir/$name");
  511. continue;
  512. }
  513. // Otherwise we're only interested in *.phpt files.
  514. if (substr($name, -5) == '.phpt') {
  515. if ($ignore) {
  516. $ignored_by_ext++;
  517. } else {
  518. $testfile = realpath("{$dir}/{$name}");
  519. $test_files[] = $testfile;
  520. }
  521. }
  522. }
  523. closedir($o);
  524. }
  525. function test_name($name)
  526. {
  527. if (is_array($name)) {
  528. return $name[0] . ':' . $name[1];
  529. } else {
  530. return $name;
  531. }
  532. }
  533. function test_sort($a, $b)
  534. {
  535. global $cwd;
  536. $a = test_name($a);
  537. $b = test_name($b);
  538. $ta = strpos($a, "{$cwd}/tests")===0 ? 1 + (strpos($a, "{$cwd}/tests/run-test")===0 ? 1 : 0) : 0;
  539. $tb = strpos($b, "{$cwd}/tests")===0 ? 1 + (strpos($b, "{$cwd}/tests/run-test")===0 ? 1 : 0) : 0;
  540. if ($ta == $tb) {
  541. return strcmp($a, $b);
  542. } else {
  543. return $tb - $ta;
  544. }
  545. }
  546. $test_files = array_unique($test_files);
  547. usort($test_files, "test_sort");
  548. $start_time = time();
  549. show_start($start_time);
  550. $test_cnt = count($test_files);
  551. $test_idx = 0;
  552. run_all_tests($test_files, $environment);
  553. $end_time = time();
  554. if ($failed_tests_file) {
  555. fclose($failed_tests_file);
  556. }
  557. // Summarize results
  558. if (0 == count($test_results)) {
  559. echo "No tests were run.\n";
  560. return;
  561. }
  562. compute_summary();
  563. show_end($end_time);
  564. show_summary();
  565. if ($html_output) {
  566. fclose($html_file);
  567. }
  568. define('PHP_QA_EMAIL', 'qa-reports@lists.php.net');
  569. define('QA_SUBMISSION_PAGE', 'http://qa.php.net/buildtest-process.php');
  570. /* We got failed Tests, offer the user to send an e-mail to QA team, unless NO_INTERACTION is set */
  571. if (!getenv('NO_INTERACTION')) {
  572. $fp = fopen("php://stdin", "r+");
  573. echo "\nYou may have found a problem in PHP.\nWe would like to send this report automatically to the\n";
  574. echo "PHP QA team, to give us a better understanding of how\nthe test cases are doing. If you don't want to send it\n";
  575. echo "immediately, you can choose \"s\" to save the report to\na file that you can send us later.\n";
  576. echo "Do you want to send this report now? [Yns]: ";
  577. flush();
  578. $user_input = fgets($fp, 10);
  579. $just_save_results = (strtolower($user_input[0]) == 's');
  580. }
  581. if ($just_save_results || !getenv('NO_INTERACTION')) {
  582. if ($just_save_results || strlen(trim($user_input)) == 0 || strtolower($user_input[0]) == 'y') {
  583. /*
  584. * Collect information about the host system for our report
  585. * Fetch phpinfo() output so that we can see the PHP enviroment
  586. * Make an archive of all the failed tests
  587. * Send an email
  588. */
  589. if ($just_save_results)
  590. {
  591. $user_input = 's';
  592. }
  593. /* Ask the user to provide an email address, so that QA team can contact the user */
  594. if (!strncasecmp($user_input, 'y', 1) || strlen(trim($user_input)) == 0) {
  595. echo "\nPlease enter your email address.\n(Your address will be mangled so that it will not go out on any\nmailinglist in plain text): ";
  596. flush();
  597. $user_email = trim(fgets($fp, 1024));
  598. $user_email = str_replace("@", " at ", str_replace(".", " dot ", $user_email));
  599. }
  600. $failed_tests_data = '';
  601. $sep = "\n" . str_repeat('=', 80) . "\n";
  602. $failed_tests_data .= $failed_test_summary . "\n";
  603. $failed_tests_data .= get_summary(true, false) . "\n";
  604. if ($sum_results['FAILED']) {
  605. foreach ($PHP_FAILED_TESTS['FAILED'] as $test_info) {
  606. $failed_tests_data .= $sep . ($test_info['unicode']?'U:':'N:') . $test_info['name'] . $test_info['info'];
  607. $failed_tests_data .= $sep . file_get_contents(realpath($test_info['output']));
  608. $failed_tests_data .= $sep . file_get_contents(realpath($test_info['diff']));
  609. $failed_tests_data .= $sep . "\n\n";
  610. }
  611. $status = "failed";
  612. } else {
  613. $status = "success";
  614. }
  615. $failed_tests_data .= "\n" . $sep . 'BUILD ENVIRONMENT' . $sep;
  616. $failed_tests_data .= "OS:\n" . PHP_OS . " - " . php_uname() . "\n\n";
  617. $ldd = $autoconf = $sys_libtool = $libtool = $compiler = 'N/A';
  618. if (substr(PHP_OS, 0, 3) != "WIN") {
  619. /* If PHP_AUTOCONF is set, use it; otherwise, use 'autoconf'. */
  620. if (!empty($_ENV['PHP_AUTOCONF'])) {
  621. $autoconf = shell_exec($_ENV['PHP_AUTOCONF'] . ' --version');
  622. } else {
  623. $autoconf = shell_exec('autoconf --version');
  624. }
  625. /* Always use the generated libtool - Mac OSX uses 'glibtool' */
  626. $libtool = shell_exec($CUR_DIR . '/libtool --version');
  627. /* Use shtool to find out if there is glibtool present (MacOSX) */
  628. $sys_libtool_path = shell_exec(dirname(__FILE__) . '/build/shtool path glibtool libtool');
  629. $sys_libtool = shell_exec(str_replace("\n", "", $sys_libtool_path) . ' --version');
  630. /* Try the most common flags for 'version' */
  631. $flags = array('-v', '-V', '--version');
  632. $cc_status=0;
  633. foreach($flags AS $flag) {
  634. system(getenv('CC')." $flag >/dev/null 2>&1", $cc_status);
  635. if ($cc_status == 0) {
  636. $compiler = shell_exec(getenv('CC')." $flag 2>&1");
  637. break;
  638. }
  639. }
  640. $ldd = shell_exec("ldd $php 2>/dev/null");
  641. }
  642. $failed_tests_data .= "Autoconf:\n$autoconf\n";
  643. $failed_tests_data .= "Bundled Libtool:\n$libtool\n";
  644. $failed_tests_data .= "System Libtool:\n$sys_libtool\n";
  645. $failed_tests_data .= "Compiler:\n$compiler\n";
  646. $failed_tests_data .= "Bison:\n". @shell_exec('bison --version 2>/dev/null'). "\n";
  647. $failed_tests_data .= "Libraries:\n$ldd\n";
  648. $failed_tests_data .= "\n";
  649. if (isset($user_email)) {
  650. $failed_tests_data .= "User's E-mail: ".$user_email."\n\n";
  651. }
  652. $failed_tests_data .= $sep . "PHPINFO" . $sep;
  653. $failed_tests_data .= shell_exec($php.' -dhtml_errors=0 -i');
  654. if ($just_save_results || !mail_qa_team($failed_tests_data, $compression, $status)) {
  655. file_put_contents($output_file, $failed_tests_data);
  656. if (!$just_save_results) {
  657. echo "\nThe test script was unable to automatically send the report to PHP's QA Team\n";
  658. }
  659. echo "Please send ".$output_file." to ".PHP_QA_EMAIL." manually, thank you.\n";
  660. } else {
  661. fwrite($fp, "\nThank you for helping to make PHP better.\n");
  662. fclose($fp);
  663. }
  664. }
  665. }
  666. if (getenv('REPORT_EXIT_STATUS') == 1 and $sum_results['FAILED']) {
  667. exit(1);
  668. }
  669. exit(0);
  670. //
  671. // Send Email to QA Team
  672. //
  673. function mail_qa_team($data, $compression, $status = FALSE)
  674. {
  675. $url_bits = parse_url(QA_SUBMISSION_PAGE);
  676. if (empty($url_bits['port'])) $url_bits['port'] = 80;
  677. $data = "php_test_data=" . urlencode(base64_encode(preg_replace("/[\\x00]/", "[0x0]", $data)));
  678. $data_length = strlen($data);
  679. $fs = fsockopen($url_bits['host'], $url_bits['port'], $errno, $errstr, 10);
  680. if (!$fs) {
  681. return FALSE;
  682. }
  683. $php_version = urlencode(TESTED_PHP_VERSION);
  684. echo "\nPosting to {$url_bits['host']} {$url_bits['path']}\n";
  685. fwrite($fs, "POST ".$url_bits['path']."?status=$status&version=$php_version HTTP/1.1\r\n");
  686. fwrite($fs, "Host: ".$url_bits['host']."\r\n");
  687. fwrite($fs, "User-Agent: QA Browser 0.1\r\n");
  688. fwrite($fs, "Content-Type: application/x-www-form-urlencoded\r\n");
  689. fwrite($fs, "Content-Length: ".$data_length."\r\n\r\n");
  690. fwrite($fs, $data);
  691. fwrite($fs, "\r\n\r\n");
  692. fclose($fs);
  693. return 1;
  694. }
  695. //
  696. // Write the given text to a temporary file, and return the filename.
  697. //
  698. function save_text($filename, $text, $filename_copy = null)
  699. {
  700. global $DETAILED;
  701. if ($filename_copy && $filename_copy != $filename) {
  702. if (@file_put_contents($filename_copy, $text) === false) {
  703. error("Cannot open file '" . $filename_copy . "' (save_text)");
  704. }
  705. }
  706. if (@file_put_contents($filename, $text) === false) {
  707. error("Cannot open file '" . $filename . "' (save_text)");
  708. }
  709. if (1 < $DETAILED) echo "
  710. FILE $filename {{{
  711. $text
  712. }}}
  713. ";
  714. }
  715. //
  716. // Write an error in a format recognizable to Emacs or MSVC.
  717. //
  718. function error_report($testname, $logname, $tested)
  719. {
  720. $testname = realpath($testname);
  721. $logname = realpath($logname);
  722. switch (strtoupper(getenv('TEST_PHP_ERROR_STYLE'))) {
  723. case 'MSVC':
  724. echo $testname . "(1) : $tested\n";
  725. echo $logname . "(1) : $tested\n";
  726. break;
  727. case 'EMACS':
  728. echo $testname . ":1: $tested\n";
  729. echo $logname . ":1: $tested\n";
  730. break;
  731. }
  732. }
  733. function system_with_timeout($commandline, $env = null)
  734. {
  735. global $leak_check;
  736. $data = "";
  737. $proc = proc_open($commandline, array(
  738. 0 => array('pipe', 'r'),
  739. 1 => array('pipe', 'w'),
  740. 2 => array('pipe', 'w')
  741. ), $pipes, null, $env, array("suppress_errors" => true));
  742. if (!$proc)
  743. return false;
  744. fclose($pipes[0]);
  745. while (true) {
  746. /* hide errors from interrupted syscalls */
  747. $r = $pipes;
  748. $w = null;
  749. $e = null;
  750. $n = @stream_select($r, $w, $e, $leak_check ? 300 : 60);
  751. if ($n === 0) {
  752. /* timed out */
  753. $data .= "\n ** ERROR: process timed out **\n";
  754. proc_terminate($proc);
  755. return $data;
  756. } else if ($n > 0) {
  757. $line = fread($pipes[1], 8192);
  758. if ($line === false) {
  759. /* EOF */
  760. break;
  761. }
  762. $data .= $line;
  763. }
  764. }
  765. $stat = proc_get_status($proc);
  766. if ($stat['signaled']) {
  767. $data .= "\nTermsig=".$stat['stopsig'];
  768. }
  769. $code = proc_close($proc);
  770. return $data;
  771. }
  772. function run_all_tests($test_files, $env, $redir_tested = NULL)
  773. {
  774. global $test_results, $failed_tests_file, $php, $test_cnt, $test_idx, $unicode_and_native, $unicode_testing;
  775. if ($unicode_and_native && is_null($redir_tested))
  776. {
  777. $test_cnt *= 2;
  778. }
  779. foreach($test_files as $name)
  780. {
  781. if (is_array($name))
  782. {
  783. $index = "# $name[1]: $name[0]";
  784. if ($redir_tested)
  785. {
  786. $name = $name[0];
  787. }
  788. }
  789. else if ($redir_tested)
  790. {
  791. $index = "# $redir_tested: $name";
  792. }
  793. else
  794. {
  795. $index = $name;
  796. }
  797. $unicode_semantics = $unicode_and_native ? 0 : ($unicode_testing ? 1 : 0);
  798. for(; $unicode_semantics < ($unicode_testing ? 2 : 1); $unicode_semantics++)
  799. {
  800. $test_idx++;
  801. $result = run_test($php, $name, $env, $unicode_semantics);
  802. if (!is_array($name) && $result != 'REDIR')
  803. {
  804. $pu = $unicode_and_native && $unicode_semantics ? '.u' : '';
  805. $test_results[$index.$pu] = $result;
  806. if ($failed_tests_file && ($result == 'FAILED' || $result == 'WARNED' || $result == 'LEAKED'))
  807. {
  808. fwrite($failed_tests_file, "$index\n");
  809. }
  810. }
  811. if ($result == 'REDIR')
  812. {
  813. $unicode_semantics = 2;
  814. }
  815. }
  816. }
  817. }
  818. //
  819. // Run an individual test case.
  820. //
  821. function run_test($php, $file, $env, $unicode_semantics)
  822. {
  823. global $log_format, $info_params, $ini_overwrites, $cwd, $PHP_FAILED_TESTS;
  824. global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx;
  825. global $leak_check, $temp_source, $temp_target, $cfg, $environment;
  826. global $no_clean;
  827. global $unicode_and_native;
  828. $temp_filenames = null;
  829. $org_file = $file;
  830. if (isset($env['TEST_PHP_CGI_EXECUTABLE'])) {
  831. $php_cgi = $env['TEST_PHP_CGI_EXECUTABLE'];
  832. }
  833. if (is_array($file)) $file = $file[0];
  834. if ($DETAILED) echo "
  835. =================
  836. TEST $file
  837. ";
  838. // Load the sections of the test file.
  839. $section_text = array(
  840. 'TEST' => '',
  841. 'SKIPIF' => '',
  842. 'GET' => '',
  843. 'POST_RAW' => '',
  844. 'POST' => '',
  845. 'UPLOAD' => '',
  846. 'ARGS' => '',
  847. );
  848. $fp = @fopen($file, "rt") or error("Cannot open test file: $file");
  849. $borked = false;
  850. $bork_info = '';
  851. if (!feof($fp)) {
  852. $line = fgets($fp);
  853. } else {
  854. $bork_info = "empty test [$file]";
  855. $borked = true;
  856. }
  857. if (!ereg('^--TEST--',$line,$r)) {
  858. $bork_info = "tests must start with --TEST-- [$file]";
  859. $borked = true;
  860. }
  861. $section = 'TEST';
  862. $secfile = false;
  863. $secdone = false;
  864. while (!feof($fp)) {
  865. $line = fgets($fp);
  866. // Match the beginning of a section.
  867. if (preg_match('/^--([_A-Z]+)--/', $line, $r)) {
  868. $section = $r[1];
  869. $section_text[$section] = '';
  870. $secfile = $section == 'FILE' || $section == 'FILEEOF';
  871. $secdone = false;
  872. continue;
  873. }
  874. // Add to the section text.
  875. if (!$secdone) {
  876. $section_text[$section] .= $line;
  877. }
  878. // End of actual test?
  879. if ($secfile && preg_match('/^===DONE===/', $line, $r)) {
  880. $secdone = true;
  881. }
  882. }
  883. // the redirect section allows a set of tests to be reused outside of
  884. // a given test dir
  885. if (@count($section_text['REDIRECTTEST']) == 1) {
  886. if ($IN_REDIRECT) {
  887. $borked = true;
  888. $bork_info = "Can't redirect a test from within a redirected test";
  889. } else {
  890. $borked = false;
  891. }
  892. } else {
  893. if (@count($section_text['FILE']) + @count($section_text['FILEEOF']) != 1) {
  894. $bork_info = "missing section --FILE--";
  895. $borked = true;
  896. }
  897. if (@count($section_text['FILEEOF']) == 1) {
  898. $section_text['FILE'] = preg_replace("/[\r\n]+$/", '', $section_text['FILEEOF']);
  899. unset($section_text['FILEEOF']);
  900. }
  901. if ((@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX'])) != 1) {
  902. $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--";
  903. $borked = true;
  904. }
  905. if ((@count($section_text['UEXPECT']) + @count($section_text['UEXPECTF']) + @count($section_text['UEXPECTREGEX'])) > 1) {
  906. $bork_info = "missing section --UEXPECT--, --UEXPECTF-- or --UEXPECTREGEX--";
  907. $borked = true;
  908. }
  909. }
  910. fclose($fp);
  911. $shortname = str_replace($cwd.'/', '', $file);
  912. $tested_file = $shortname;
  913. if ($borked) {
  914. show_result("BORK", $bork_info, $tested_file, $unicode_semantics);
  915. $PHP_FAILED_TESTS['BORKED'][] = array (
  916. 'name' => $file,
  917. 'test_name' => '',
  918. 'output' => '',
  919. 'diff' => '',
  920. 'info' => "$bork_info [$file]",
  921. 'unicode'=> $unicode_semantics,
  922. );
  923. return 'BORKED';
  924. }
  925. $tested = trim($section_text['TEST']);
  926. /* For GET/POST tests, check if cgi sapi is available and if it is, use it. */
  927. if ((!empty($section_text['GET']) || !empty($section_text['POST']))) {
  928. if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) ."/php-cgi.exe")) {
  929. $old_php = $php;
  930. $php = realpath(dirname($php) ."/php-cgi.exe") .' -C ';
  931. } elseif (file_exists("./sapi/cgi/php")) {
  932. $old_php = $php;
  933. $php = realpath("./sapi/cgi/php") . ' -C ';
  934. } else {
  935. show_result("SKIP", $tested, $tested_file, $unicode_semantics, "reason: CGI not available");
  936. return 'SKIPPED';
  937. }
  938. }
  939. show_test($test_idx, $shortname);
  940. if (is_array($IN_REDIRECT)) {
  941. $temp_dir = $test_dir = $IN_REDIRECT['dir'];
  942. } else {
  943. $temp_dir = $test_dir = realpath(dirname($file));
  944. }
  945. if ($temp_source && $temp_target) {
  946. $temp_dir = str_replace($temp_source, $temp_target, $temp_dir);
  947. }
  948. $pu = $unicode_semantics ? 'u.' : '';
  949. $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . basename($file,'phpt').$pu.'diff';
  950. $log_filename = $temp_dir . DIRECTORY_SEPARATOR . basename($file,'phpt').$pu.'log';
  951. $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . basename($file,'phpt').$pu.'exp';
  952. $output_filename = $temp_dir . DIRECTORY_SEPARATOR . basename($file,'phpt').$pu.'out';
  953. $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . basename($file,'phpt').$pu.'mem';
  954. $temp_file = $temp_dir . DIRECTORY_SEPARATOR . basename($file,'phpt')/*.$pu*/.'php';
  955. $test_file = $test_dir . DIRECTORY_SEPARATOR . basename($file,'phpt')/*.$pu*/.'php';
  956. $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . basename($file,'phpt').$pu.'skip.php';
  957. $test_skipif = $test_dir . DIRECTORY_SEPARATOR . basename($file,'phpt').$pu.'skip.php';
  958. $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . basename($file,'phpt').$pu.'clean.php';
  959. $test_clean = $test_dir . DIRECTORY_SEPARATOR . basename($file,'phpt').$pu.'clean.php';
  960. $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('/phpt.');
  961. $tmp_relative_file = str_replace(dirname(__FILE__).DIRECTORY_SEPARATOR, '', $test_file) . 't';
  962. if ($temp_source && $temp_target) {
  963. $temp_skipif .= 's';
  964. $temp_file .= 's';
  965. $temp_clean .= 's';
  966. $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file[1] : $file).'.phps';
  967. if (!is_dir(dirname($copy_file))) {
  968. @mkdir(dirname($copy_file), 0777, true) or error("Cannot create output directory - " . dirname($copy_file));
  969. }
  970. if (isset($section_text['FILE'])) {
  971. save_text($copy_file, $section_text['FILE']);
  972. }
  973. $temp_filenames = array(
  974. 'file' => $copy_file,
  975. 'diff' => $diff_filename,
  976. 'log' => $log_filename,
  977. 'exp' => $exp_filename,
  978. 'out' => $output_filename,
  979. 'mem' => $memcheck_filename,
  980. 'php' => $temp_file,
  981. 'skip' => $temp_skipif,
  982. 'clean'=> $temp_clean);
  983. }
  984. if (is_array($IN_REDIRECT)) {
  985. $tested = $IN_REDIRECT['prefix'] . ' ' . trim($section_text['TEST']);
  986. $tested_file = $tmp_relative_file;
  987. $section_text['FILE'] = "# original source file: $shortname\n" . $section_text['FILE'];
  988. }
  989. // unlink old test results
  990. @unlink($diff_filename);
  991. @unlink($log_filename);
  992. @unlink($exp_filename);
  993. @unlink($output_filename);
  994. @unlink($memcheck_filename);
  995. @unlink($temp_file);
  996. @unlink($test_file);
  997. @unlink($temp_skipif);
  998. @unlink($test_skipif);
  999. @unlink($tmp_post);
  1000. @unlink($temp_clean);
  1001. @unlink($test_clean);
  1002. // Reset environment from any previous test.
  1003. $env['REDIRECT_STATUS']='';
  1004. $env['QUERY_STRING']='';
  1005. $env['PATH_TRANSLATED']='';
  1006. $env['SCRIPT_FILENAME']='';
  1007. $env['REQUEST_METHOD']='';
  1008. $env['CONTENT_TYPE']='';
  1009. $env['CONTENT_LENGTH']='';
  1010. if (!empty($section_text['ENV'])) {
  1011. foreach(explode("\n", $section_text['ENV']) as $e) {
  1012. $e = explode('=',trim($e));
  1013. if (count($e) == 2) {
  1014. $env[$e[0]] = $e[1];
  1015. }
  1016. }
  1017. }
  1018. // Default ini settings
  1019. $ini_settings = array();
  1020. // additional ini overwrites
  1021. //$ini_overwrites[] = 'setting=value';
  1022. settings2array($ini_overwrites, $ini_settings);
  1023. // is this unicode/native per run-tests.php switch?
  1024. if ($unicode_and_native) {
  1025. $ini_settings["unicode_semantics"] = $unicode_semantics ? '1' : '0';
  1026. }
  1027. // Any special ini settings
  1028. // these may overwrite the test defaults...
  1029. if (array_key_exists('INI', $section_text)) {
  1030. if (strpos($section_text['INI'], '{PWD}') !== false) {
  1031. $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']);
  1032. }
  1033. settings2array(preg_split( "/[\n\r]+/", $section_text['INI']), $ini_settings);
  1034. if (isset($ini_settings["unicode_semantics"])) {
  1035. $unicode_test = strcasecmp($ini_settings["unicode_semantics"],"on") == 0 || $ini_settings["unicode_semantics"] == 1;
  1036. } else {
  1037. $unicode_test = TESTED_UNICODE;
  1038. }
  1039. } else {
  1040. $unicode_test = $unicode_and_native ? $unicode_semantics : TESTED_UNICODE;
  1041. }
  1042. settings2params($ini_settings);
  1043. // Check if test should be skipped.
  1044. $info = '';
  1045. $warn = false;
  1046. if (array_key_exists('SKIPIF', $section_text)) {
  1047. if (trim($section_text['SKIPIF'])) {
  1048. if ($cfg['show']['skip']) {
  1049. echo "\n========SKIP========\n";
  1050. echo $section_text['SKIPIF'];
  1051. echo "========DONE========\n";
  1052. }
  1053. save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif);
  1054. $extra = substr(PHP_OS, 0, 3) !== "WIN" ?
  1055. "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;": "";
  1056. $output = system_with_timeout("$extra $php -q $ini_settings $test_skipif", $env);
  1057. if (!$cfg['keep']['skip']) {
  1058. @unlink($test_skipif);
  1059. }
  1060. if (!strncasecmp('skip', trim($output), 4)) {
  1061. $reason = (eregi("^skip[[:space:]]*(.+)\$", trim($output))) ? eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE;
  1062. if ($reason) {
  1063. show_result("SKIP", $tested, $tested_file, $unicode_semantics, "reason: $reason", $temp_filenames);
  1064. } else {
  1065. show_result("SKIP", $tested, $tested_file, $unicode_semantics, '', $temp_filenames);
  1066. }
  1067. if (isset($old_php)) {
  1068. $php = $old_php;
  1069. }
  1070. if (!$cfg['keep']['skip']) {
  1071. @unlink($test_skipif);
  1072. }
  1073. return 'SKIPPED';
  1074. }
  1075. if (!strncasecmp('info', trim($output), 4)) {
  1076. $reason = (ereg("^info[[:space:]]*(.+)\$", trim($output))) ? ereg_replace("^info[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE;
  1077. if ($reason) {
  1078. $info = " (info: $reason)";
  1079. }
  1080. }
  1081. if (!strncasecmp('warn', trim($output), 4)) {
  1082. $reason = (ereg("^warn[[:space:]]*(.+)\$", trim($output))) ? ereg_replace("^warn[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE;
  1083. if ($reason) {
  1084. $warn = true; /* only if there is a reason */
  1085. $info = " (warn: $reason)";
  1086. }
  1087. }
  1088. }
  1089. }
  1090. if (@count($section_text['REDIRECTTEST']) == 1) {
  1091. $test_files = array();
  1092. $IN_REDIRECT = eval($section_text['REDIRECTTEST']);
  1093. $IN_REDIRECT['via'] = "via [$shortname]\n\t";
  1094. $IN_REDIRECT['dir'] = realpath(dirname($file));
  1095. $IN_REDIRECT['prefix'] = trim($section_text['TEST']);
  1096. if (@count($IN_REDIRECT['TESTS']) == 1) {
  1097. if (is_array($org_file)) {
  1098. $test_files[] = $org_file[1];
  1099. } else {
  1100. $GLOBALS['test_files'] = $test_files;
  1101. find_files($IN_REDIRECT['TESTS']);
  1102. foreach($GLOBALS['test_files'] as $f) {
  1103. $test_files[] = array($f, $file);
  1104. }
  1105. }
  1106. $test_cnt += (count($test_files) - 1) * ($unicode_and_native ? 2 : 1);
  1107. $test_idx--;
  1108. show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file);
  1109. // set up environment
  1110. $redirenv = array_merge($environment, $IN_REDIRECT['ENV']);
  1111. $redirenv['REDIR_TEST_DIR'] = realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR;
  1112. usort($test_files, "test_sort");
  1113. run_all_tests($test_files, $redirenv, $tested);
  1114. show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file);
  1115. // a redirected test never fails
  1116. $IN_REDIRECT = false;
  1117. return 'REDIR';
  1118. } else {
  1119. $bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory.";
  1120. show_result("BORK", $bork_info, '', $unicode_semantics, $temp_filenames);
  1121. $PHP_FAILED_TESTS['BORKED'][] = array (
  1122. 'name' => $file,
  1123. 'test_name' => '',
  1124. 'output' => '',
  1125. 'diff' => '',
  1126. 'info' => "$bork_info [$file]",
  1127. 'unicode'=> $unicode_semantics,
  1128. );
  1129. }
  1130. }
  1131. if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) {
  1132. if (is_array($org_file)) $file = $org_file[0];
  1133. $bork_info = "Redirected test did not contain redirection info";
  1134. show_result("BORK", $bork_info, '', $unicode_semantics, $temp_filenames);
  1135. $PHP_FAILED_TESTS['BORKED'][] = array (
  1136. 'name' => $file,
  1137. 'test_name' => '',
  1138. 'output' => '',
  1139. 'diff' => '',
  1140. 'info' => "$bork_info [$file]",
  1141. 'unicode'=> $unicode_semantics,
  1142. );
  1143. //$test_cnt -= 1; // Only if is_array($org_file) ?
  1144. //$test_idx--;
  1145. return 'BORKED';
  1146. }
  1147. if ($unicode_test) {
  1148. if (isset($section_text['UEXPECT'])) {
  1149. unset($section_text['EXPECT']);
  1150. unset($section_text['EXPECTF']);
  1151. unset($section_text['EXPECTREGEX']);
  1152. $section_text['EXPECT'] = $section_text['UEXPECT'];
  1153. unset($section_text['UEXPECT']);
  1154. } else if (isset($section_text['UEXPECTF'])) {
  1155. unset($section_text['EXPECT']);
  1156. unset($section_text['EXPECTF']);
  1157. unset($section_text['EXPECTREGEX']);
  1158. $section_text['EXPECTF'] = $section_text['UEXPECTF'];
  1159. unset($section_text['UEXPECTF']);
  1160. } else if (isset($section_text['UEXPECTREGEX'])) {
  1161. unset($section_text['EXPECT']);
  1162. unset($section_text['EXPECTF']);
  1163. unset($section_text['EXPECTREGEX']);
  1164. $section_text['EXPECTREGEX'] = $section_text['UEXPECTREGEX'];
  1165. unset($section_text['UEXPECTREGEX']);
  1166. }
  1167. }
  1168. // We've satisfied the preconditions - run the test!
  1169. if ($cfg['show']['php']) {
  1170. echo "\n========TEST========\n";
  1171. echo $section_text['FILE'];
  1172. echo "========DONE========\n";
  1173. }
  1174. save_text($test_file, $section_text['FILE'], $temp_file);
  1175. if (array_key_exists('GET', $section_text)) {
  1176. $query_string = trim($section_text['GET']);
  1177. } else {
  1178. $query_string = '';
  1179. }
  1180. $env['REDIRECT_STATUS'] = '1';
  1181. $env['QUERY_STRING'] = $query_string;
  1182. $env['PATH_TRANSLATED'] = $test_file;
  1183. $env['SCRIPT_FILENAME'] = $test_file;
  1184. $args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : '';
  1185. if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) {
  1186. $post = trim($section_text['POST_RAW']);
  1187. $raw_lines = explode("\n", $post);
  1188. $request = '';
  1189. foreach ($raw_lines as $line) {
  1190. if (empty($env['CONTENT_TYPE']) && eregi('^(Content-Type:)(.*)', $line, $res)) {
  1191. $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[2]));
  1192. continue;
  1193. }
  1194. $request .= $line . "\n";
  1195. }
  1196. $env['CONTENT_LENGTH'] = strlen($request);
  1197. $env['REQUEST_METHOD'] = 'POST';
  1198. if (empty($request)) {
  1199. return 'BORKED';
  1200. }
  1201. save_text($tmp_post, $request);
  1202. $cmd = "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < $tmp_post";
  1203. } elseif (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) {
  1204. $post = trim($section_text['POST']);
  1205. save_text($tmp_post, $post);
  1206. $content_length = strlen($post);
  1207. $env['REQUEST_METHOD'] = 'POST';
  1208. $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
  1209. $env['CONTENT_LENGTH'] = $content_length;
  1210. $cmd = "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < $tmp_post";
  1211. } else {
  1212. $env['REQUEST_METHOD'] = 'GET';
  1213. $env['CONTENT_TYPE'] = '';
  1214. $env['CONTENT_LENGTH'] = '';
  1215. $cmd = "$php$pass_options$ini_settings -f \"$test_file\" $args 2>&1";
  1216. }
  1217. if ($leak_check) {
  1218. $cmd = "valgrind -q --tool=memcheck --log-file-exactly=$memcheck_filename $cmd";
  1219. }
  1220. if ($DETAILED) echo "
  1221. CONTENT_LENGTH = " . $env['CONTENT_LENGTH'] . "
  1222. CONTENT_TYPE = " . $env['CONTENT_TYPE'] . "
  1223. PATH_TRANSLATED = " . $env['PATH_TRANSLATED'] . "
  1224. QUERY_STRING = " . $env['QUERY_STRING'] . "
  1225. REDIRECT_STATUS = " . $env['REDIRECT_STATUS'] . "
  1226. REQUEST_METHOD = " . $env['REQUEST_METHOD'] . "
  1227. SCRIPT_FILENAME = " . $env['SCRIPT_FILENAME'] . "
  1228. COMMAND $cmd
  1229. ";
  1230. $out = system_with_timeout($cmd, $env);
  1231. if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) {
  1232. if (trim($section_text['CLEAN'])) {
  1233. if ($cfg['show']['clean']) {
  1234. echo "\n========CLEAN=======\n";
  1235. echo $section_text['CLEAN'];
  1236. echo "========DONE========\n";
  1237. }
  1238. save_text($test_clean, trim($section_text['CLEAN']), $temp_clean);
  1239. if (!$no_clean) {
  1240. $clean_params = array();
  1241. settings2array($ini_overwrites,$clean_params);
  1242. settings2params($clean_params);
  1243. $extra = substr(PHP_OS, 0, 3) !== "WIN" ?
  1244. "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;": "";
  1245. system_with_timeout("$extra $php -q $clean_params $test_clean", $env);
  1246. }
  1247. if (!$cfg['keep']['clean']) {
  1248. @unlink($test_clean);
  1249. }
  1250. }
  1251. }
  1252. @unlink($tmp_post);
  1253. $leaked = false;
  1254. $passed = false;
  1255. if ($leak_check) { // leak check
  1256. $leaked = @filesize($memcheck_filename) > 0;
  1257. if (!$leaked) {
  1258. @unlink($memcheck_filename);
  1259. }
  1260. }
  1261. // Does the output match what is expected?
  1262. $output = str_replace("\r\n", "\n", trim($out));
  1263. /* when using CGI, strip the headers from the output */
  1264. $headers = "";
  1265. if (isset($old_php) && preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) {
  1266. $output = $match[2];
  1267. $rh = preg_split("/[\n\r]+/",$match[1]);
  1268. $headers = array();
  1269. foreach ($rh as $line) {
  1270. if (strpos($line, ':')!==false) {
  1271. $line = explode(':', $line, 2);
  1272. $headers[trim($line[0])] = trim($line[1]);
  1273. }
  1274. }
  1275. }
  1276. $failed_headers = false;
  1277. if (isset($section_text['EXPECTHEADERS'])) {
  1278. $want = array();
  1279. $wanted_headers = array();
  1280. $lines = preg_split("/[\n\r]+/",$section_text['EXPECTHEADERS']);
  1281. foreach($lines as $line) {
  1282. if (strpos($line, ':') !== false) {
  1283. $line = explode(':', $line, 2);
  1284. $want[trim($line[0])] = trim($line[1]);
  1285. $wanted_headers[] = trim($line[0]) . ': ' . trim($line[1]);
  1286. }
  1287. }
  1288. $org_headers = $headers;
  1289. $headers = array();
  1290. $output_headers = array();
  1291. foreach($want as $k => $v) {
  1292. if (isset($org_headers[$k])) {
  1293. $headers = $org_headers[$k];
  1294. $output_headers[] = $k . ': ' . $org_headers[$k];
  1295. }
  1296. if (!isset($org_headers[$k]) || $org_headers[$k] != $v) {
  1297. $failed_headers = true;
  1298. }
  1299. }
  1300. ksort($wanted_headers);
  1301. $wanted_headers = join("\n", $wanted_headers);
  1302. ksort($output_headers);
  1303. $output_headers = join("\n", $output_headers);
  1304. }
  1305. if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) {
  1306. if (isset($section_text['EXPECTF'])) {
  1307. $wanted = trim($section_text['EXPECTF']);
  1308. } else {
  1309. $wanted = trim($section_text['EXPECTREGEX']);
  1310. }
  1311. $wanted_re = preg_replace('/\r\n/',"\n",$wanted);
  1312. if (isset($section_text['EXPECTF'])) {
  1313. $wanted_re = preg_quote($wanted_re, '/');
  1314. // Stick to basics
  1315. $wanted_re = str_replace("%e", '\\' . DIRECTORY_SEPARATOR, $wanted_re);
  1316. $wanted_re = str_replace("%s", ".+?", $wanted_re); //not greedy
  1317. $wanted_re = str_replace("%w", "\s*", $wanted_re);
  1318. $wanted_re = str_replace("%i", "[+\-]?[0-9]+", $wanted_re);
  1319. $wanted_re = str_replace("%d", "[0-9]+", $wanted_re);
  1320. $wanted_re = str_replace("%x", "[0-9a-fA-F]+", $wanted_re);
  1321. $wanted_re = str_replace("%f", "[+\-]?\.?[0-9]+\.?[0-9]*(E-?[0-9]+)?", $wanted_re);
  1322. $wanted_re = str_replace("%c", ".", $wanted_re);
  1323. // %f allows two points "-.0.0" but that is the best *simple* expression
  1324. }
  1325. /* DEBUG YOUR REGEX HERE
  1326. var_dump($wanted_re);
  1327. print(str_repeat('=', 80) . "\n");
  1328. var_dump($output);
  1329. */
  1330. if (preg_match("/^$wanted_re\$/s", $output)) {
  1331. $passed = true;
  1332. if (!$cfg['keep']['php']) {
  1333. @unlink($test_file);
  1334. }
  1335. if (isset($old_php)) {
  1336. $php = $old_php;
  1337. }
  1338. if (!$leaked && !$failed_headers) {
  1339. show_result("PASS", $tested, $tested_file, $unicode_semantics, '', $temp_filenames);
  1340. return 'PASSED';
  1341. }
  1342. }
  1343. } else {
  1344. $wanted = trim($section_text['EXPECT']);
  1345. $wanted = preg_replace('/\r\n/',"\n",$wanted);
  1346. // compare and leave on success
  1347. if (!strcmp($output, $wanted)) {
  1348. $passed = true;
  1349. if (!$cfg['keep']['php']) {
  1350. @unlink($test_file);
  1351. }
  1352. if (isset($old_php)) {
  1353. $php = $old_php;
  1354. }
  1355. if (!$leaked && !$failed_headers) {
  1356. show_result("PASS", $tested, $tested_file, $unicode_semantics, '', $temp_filenames);
  1357. return 'PASSED';
  1358. }
  1359. }
  1360. $wanted_re = NULL;
  1361. }
  1362. // Test failed so we need to report details.
  1363. if ($failed_headers) {
  1364. $passed = false;
  1365. $wanted = $wanted_headers . "\n--HEADERS--\n" . $wanted;
  1366. $output = $output_headers . "\n--HEADERS--\n" . $output;
  1367. if (isset($wanted_re)) {
  1368. $wanted_re = $wanted_headers . "\n--HEADERS--\n" . $wanted_re;
  1369. }
  1370. }
  1371. if ($leaked) {
  1372. $restype = 'LEAK';
  1373. } else if ($warn) {
  1374. $restype = 'WARN';
  1375. } else {
  1376. $restype = 'FAIL';
  1377. }
  1378. if (!$passed) {
  1379. // write .exp
  1380. if (strpos($log_format,'E') !== FALSE && file_put_contents($exp_filename, $wanted) === FALSE) {
  1381. error("Cannot create expected test output - $exp_filename");
  1382. }
  1383. // write .out
  1384. if (strpos($log_format,'O') !== FALSE && file_put_contents($output_filename, $output) === FALSE) {
  1385. error("Cannot create test output - $output_filename");
  1386. }
  1387. // write .diff
  1388. if (strpos($log_format,'D') !== FALSE && file_put_contents($diff_filename, generate_diff($wanted,$wanted_re,$output)) === FALSE) {
  1389. error("Cannot create test diff - $diff_filename");
  1390. }
  1391. // write .log
  1392. if (strpos($log_format,'L') !== FALSE && file_put_contents($log_filename, "
  1393. ---- EXPECTED OUTPUT
  1394. $wanted
  1395. ---- ACTUAL OUTPUT
  1396. $output
  1397. ---- FAILED
  1398. ") === FALSE) {
  1399. error("Cannot create test log - $log_filename");
  1400. error_report($file, $log_filename, $tested);
  1401. }
  1402. }
  1403. show_result($restype, $tested, $tested_file, $unicode_semantics, $info, $temp_filenames);
  1404. $PHP_FAILED_TESTS[$restype.'ED'][] = array (
  1405. 'name' => $file,
  1406. 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [$tested_file]",
  1407. 'output' => $output_filename,
  1408. 'diff' => $diff_filename,
  1409. 'info' => $info,
  1410. 'unicode'=> $unicode_semantics,
  1411. );
  1412. if (isset($old_php)) {
  1413. $php = $old_php;
  1414. }
  1415. return $restype.'ED';
  1416. }
  1417. function comp_line($l1,$l2,$is_reg)
  1418. {
  1419. if ($is_reg) {
  1420. return preg_match('/^'.$l1.'$/s', $l2);
  1421. } else {
  1422. return !strcmp($l1, $l2);
  1423. }
  1424. }
  1425. function count_array_diff($ar1,$ar2,$is_reg,$w,$idx1,$idx2,$cnt1,$cnt2,$steps)
  1426. {
  1427. $equal = 0;
  1428. while ($idx1 < $cnt1 && $idx2 < $cnt2 && comp_line($ar1[$idx1], $ar2[$idx2], $is_reg)) {
  1429. $idx1++;
  1430. $idx2++;
  1431. $equal++;
  1432. $steps--;
  1433. }
  1434. if (--$steps > 0) {
  1435. $eq1 = 0;
  1436. $st = $steps / 2;
  1437. for ($ofs1 = $idx1+1; $ofs1 < $cnt1 && $st-- > 0; $ofs1++) {
  1438. $eq = count_array_diff($ar1,$ar2,$is_reg,$w,$ofs1,$idx2,$cnt1,$cnt2,$st);
  1439. if ($eq > $eq1) {
  1440. $eq1 = $eq;
  1441. }
  1442. }
  1443. $eq2 = 0;
  1444. $st = $steps;
  1445. for ($ofs2 = $idx2+1; $ofs2 < $cnt2 && $st-- > 0; $ofs2++) {
  1446. $eq = count_array_diff($ar1,$ar2,$is_reg,$w,$idx1,$ofs2,$cnt1,$cnt2,$st);
  1447. if ($eq > $eq2) {
  1448. $eq2 = $eq;
  1449. }
  1450. }
  1451. if ($eq1 > $eq2) {
  1452. $equal += $eq1;
  1453. } else if ($eq2 > 0) {
  1454. $equal += $eq2;
  1455. }
  1456. }
  1457. return $equal;
  1458. }
  1459. function generate_array_diff($ar1,$ar2,$is_reg,$w)
  1460. {
  1461. $idx1 = 0; $ofs1 = 0; $cnt1 = count($ar1);
  1462. $idx2 = 0; $ofs2 = 0; $cnt2 = count($ar2);
  1463. $diff = array();
  1464. $old1 = array();
  1465. $old2 = array();
  1466. while ($idx1 < $cnt1 && $idx2 < $cnt2) {
  1467. if (comp_line($ar1[$idx1], $ar2[$idx2], $is_reg)) {
  1468. $idx1++;
  1469. $idx2++;
  1470. continue;
  1471. } else {
  1472. $c1 = count_array_diff($ar1,$ar2,$is_reg,$w,$idx1+1,$idx2,$cnt1,$cnt2,10);
  1473. $c2 = count_array_diff($ar1,$ar2,$is_reg,$w,$idx1,$idx2+1,$cnt1,$cnt2,10);
  1474. if ($c1 > $c2) {
  1475. $old1[$idx1] = sprintf("%03d- ", $idx1+1).$w[$idx1++];
  1476. $last = 1;
  1477. } else if ($c2 > 0) {
  1478. $old2[$idx2] = sprintf("%03d+ ", $idx2+1).$ar2[$idx2++];
  1479. $last = 2;
  1480. } else {
  1481. $old1[$idx1] = sprintf("%03d- ", $idx1+1).$w[$idx1++];
  1482. $old2[$idx2] = sprintf("%03d+ ", $idx2+1).$ar2[$idx2++];
  1483. }
  1484. }
  1485. }
  1486. reset($old1); $k1 = key($old1); $l1 = -2;
  1487. reset($old2); $k2 = key($old2); $l2 = -2;
  1488. while ($k1 !== NULL || $k2 !== NULL) {
  1489. if ($k1 == $l1+1 || $k2 === NULL) {
  1490. $l1 = $k1;
  1491. $diff[] = current($old1);
  1492. $k1 = next($old1) ? key($old1) : NULL;
  1493. } else if ($k2 == $l2+1 || $k1 === NULL) {
  1494. $l2 = $k2;
  1495. $diff[] = current($old2);
  1496. $k2 = next($old2) ? key($old2) : NULL;
  1497. } else if ($k1 < $k2) {
  1498. $l1 = $k1;
  1499. $diff[] = current($old1);
  1500. $k1 = next($old1) ? key($old1) : NULL;
  1501. } else {
  1502. $l2 = $k2;
  1503. $diff[] = current($old2);
  1504. $k2 = next($old2) ? key($old2) : NULL;
  1505. }
  1506. }
  1507. while ($idx1 < $cnt1) {
  1508. $diff[] = sprintf("%03d- ", $idx1+1).$w[$idx1++];
  1509. }
  1510. while ($idx2 < $cnt2) {
  1511. $diff[] = sprintf("%03d+ ", $idx2+1).$ar2[$idx2++];
  1512. }
  1513. return $diff;
  1514. }
  1515. function generate_diff($wanted,$wanted_re,$output)
  1516. {
  1517. $w = explode("\n", $wanted);
  1518. $o = explode("\n", $output);
  1519. $r = is_null($wanted_re) ? $w : explode("\n", $wanted_re);
  1520. $diff = generate_array_diff($r,$o,!is_null($wanted_re),$w);
  1521. return implode("\r\n", $diff);
  1522. }
  1523. function error($message)
  1524. {
  1525. echo "ERROR: {$message}\n";
  1526. exit(1);
  1527. }
  1528. function settings2array($settings, &$ini_settings)
  1529. {
  1530. foreach($settings as $setting) {
  1531. if (strpos($setting, '=')!==false) {
  1532. $setting = explode("=", $setting, 2);
  1533. $name = trim(strtolower($setting[0]));
  1534. $value = trim($setting[1]);
  1535. $ini_settings[$name] = $value;
  1536. }
  1537. }
  1538. }
  1539. function settings2params(&$ini_settings)
  1540. {
  1541. $settings = '';
  1542. foreach($ini_settings as $name => $value) {
  1543. $value = addslashes($value);
  1544. $settings .= " -d \"$name=$value\"";
  1545. }
  1546. $ini_settings = $settings;
  1547. }
  1548. function compute_summary()
  1549. {
  1550. global $n_total, $test_results, $ignored_by_ext, $sum_results, $percent_results;
  1551. $n_total = count($test_results);
  1552. $n_total += $ignored_by_ext;
  1553. $sum_results = array('PASSED'=>0, 'WARNED'=>0, 'SKIPPED'=>0, 'FAILED'=>0, 'BORKED'=>0, 'LEAKED'=>0);
  1554. foreach ($test_results as $v) {
  1555. $sum_results[$v]++;
  1556. }
  1557. $sum_results['SKIPPED'] += $ignored_by_ext;
  1558. $percent_results = array();
  1559. while (list($v,$n) = each($sum_results)) {
  1560. $percent_results[$v] = (100.0 * $n) / $n_total;
  1561. }
  1562. }
  1563. function get_summary($show_ext_summary, $show_html)
  1564. {
  1565. global $exts_skipped, $exts_tested, $n_total, $sum_results, $percent_results, $end_time, $start_time, $failed_test_summary, $PHP_FAILED_TESTS, $leak_check;
  1566. $x_total = $n_total - $sum_results['SKIPPED'] - $sum_results['BORKED'];
  1567. if ($x_total) {
  1568. $x_warned = (100.0 * $sum_results['WARNED']) / $x_total;
  1569. $x_failed = (100.0 * $sum_results['FAILED']) / $x_total;
  1570. $x_leaked = (100.0 * $sum_results['LEAKED']) / $x_total;
  1571. $x_passed = (100.0 * $sum_results['PASSED']) / $x_total;
  1572. } else {
  1573. $x_warned = $x_failed = $x_passed = $x_leaked = 0;
  1574. }
  1575. $summary = "";
  1576. if ($show_html) $summary .= "<pre>\n";
  1577. if ($show_ext_summary) {
  1578. $summary .= "
  1579. =====================================================================
  1580. TEST RESULT SUMMARY
  1581. ---------------------------------------------------------------------
  1582. Exts skipped : " . sprintf("%4d",$exts_skipped) . "
  1583. Exts tested : " . sprintf("%4d",$exts_tested) . "
  1584. ---------------------------------------------------------------------
  1585. ";
  1586. }
  1587. $summary .= "
  1588. Number of tests : " . sprintf("%4d",$n_total). " " . sprintf("%8d",$x_total);
  1589. if ($sum_results['BORKED']) {
  1590. $summary .= "
  1591. Tests borked : " . sprintf("%4d (%5.1f%%)",$sum_results['BORKED'],$percent_results['BORKED']) . " --------";
  1592. }
  1593. $summary .= "
  1594. Tests skipped : " . sprintf("%4d (%5.1f%%)",$sum_results['SKIPPED'],$percent_results['SKIPPED']) . " --------
  1595. Tests warned : " . sprintf("%4d (%5.1f%%)",$sum_results['WARNED'], $percent_results['WARNED']) . " " . sprintf("(%5.1f%%)",$x_warned) . "
  1596. Tests failed : " . sprintf("%4d (%5.1f%%)",$sum_results['FAILED'], $percent_results['FAILED']) . " " . sprintf("(%5.1f%%)",$x_failed);
  1597. if ($leak_check) {
  1598. $summary .= "
  1599. Tests leaked : " . sprintf("%4d (%5.1f%%)",$sum_results['LEAKED'], $percent_results['LEAKED']) . " " . sprintf("(%5.1f%%)",$x_leaked);
  1600. }
  1601. $summary .= "
  1602. Tests passed : " . sprintf("%4d (%5.1f%%)",$sum_results['PASSED'], $percent_results['PASSED']) . " " . sprintf("(%5.1f%%)",$x_passed) . "
  1603. ---------------------------------------------------------------------
  1604. Time taken : " . sprintf("%4d seconds", $end_time - $start_time) . "
  1605. =====================================================================
  1606. ";
  1607. $failed_test_summary = '';
  1608. if (count($PHP_FAILED_TESTS['BORKED'])) {
  1609. $failed_test_summary .= "
  1610. =====================================================================
  1611. BORKED TEST SUMMARY
  1612. ---------------------------------------------------------------------
  1613. ";
  1614. foreach ($PHP_FAILED_TESTS['BORKED'] as $test_data) {
  1615. $failed_test_summary .= ($test_data['unicode']?'U:':'N:') . $test_data['info'] . "\n";
  1616. }
  1617. $failed_test_summary .= "=====================================================================\n";
  1618. }
  1619. if (count($PHP_FAILED_TESTS['FAILED'])) {
  1620. $failed_test_summary .= "
  1621. =====================================================================
  1622. FAILED TEST SUMMARY
  1623. ---------------------------------------------------------------------
  1624. ";
  1625. foreach ($PHP_FAILED_TESTS['FAILED'] as $test_data) {
  1626. $failed_test_summary .= ($test_data['unicode']?'U:':'N:') . $test_data['test_name'] . $test_data['info'] . "\n";
  1627. }
  1628. $failed_test_summary .= "=====================================================================\n";
  1629. }
  1630. if (count($PHP_FAILED_TESTS['LEAKED'])) {
  1631. $failed_test_summary .= "
  1632. =====================================================================
  1633. LEAKED TEST SUMMARY
  1634. ---------------------------------------------------------------------
  1635. ";
  1636. foreach ($PHP_FAILED_TESTS['LEAKED'] as $test_data) {
  1637. $failed_test_summary .= ($test_data['unicode']?'U:':'N:') . $test_data['test_name'] . $test_data['info'] . "\n";
  1638. }
  1639. $failed_test_summary .= "=====================================================================\n";
  1640. }
  1641. if ($failed_test_summary && !getenv('NO_PHPTEST_SUMMARY')) {
  1642. $summary .= $failed_test_summary;
  1643. }
  1644. if ($show_html) $summary .= "</pre>";
  1645. return $summary;
  1646. }
  1647. function show_start($start_time)
  1648. {
  1649. global $html_output, $html_file;
  1650. if ($html_output)
  1651. {
  1652. fwrite($html_file, "<h2>Time Start: " . date('Y-m-d H:i:s', $start_time) . "</h2>\n");
  1653. fwrite($html_file, "<table>\n");
  1654. }
  1655. echo "TIME START " . date('Y-m-d H:i:s', $start_time) . "\n=====================================================================\n";
  1656. }
  1657. function show_end($end_time)
  1658. {
  1659. global $html_output, $html_file;
  1660. if ($html_output)
  1661. {
  1662. fwrite($html_file, "</table>\n");
  1663. fwrite($html_file, "<h2>Time End: " . date('Y-m-d H:i:s', $end_time) . "</h2>\n");
  1664. }
  1665. echo "=====================================================================\nTIME END " . date('Y-m-d H:i:s', $end_time) . "\n";
  1666. }
  1667. function show_summary()
  1668. {
  1669. global $html_output, $html_file;
  1670. if ($html_output)
  1671. {
  1672. fwrite($html_file, "<hr/>\n" . get_summary(true, true));
  1673. }
  1674. echo get_summary(true, false);
  1675. }
  1676. function show_redirect_start($tests, $tested, $tested_file)
  1677. {
  1678. global $html_output, $html_file;
  1679. if ($html_output)
  1680. {
  1681. fwrite($html_file, "<tr><td colspan='3'>---&gt; $tests ($tested [$tested_file]) begin</td></tr>\n");
  1682. }
  1683. echo "---> $tests ($tested [$tested_file]) begin\n";
  1684. }
  1685. function show_redirect_ends($tests, $tested, $tested_file)
  1686. {
  1687. global $html_output, $html_file;
  1688. if ($html_output)
  1689. {
  1690. fwrite($html_file, "<tr><td colspan='3'>---&gt; $tests ($tested [$tested_file]) done</td></tr>\n");
  1691. }
  1692. echo "---> $tests ($tested [$tested_file]) done\n";
  1693. }
  1694. function show_test($test_idx, $shortname)
  1695. {
  1696. global $test_cnt;
  1697. echo "TEST $test_idx/$test_cnt [$shortname]\r";
  1698. flush();
  1699. }
  1700. function show_result($result, $tested, $tested_file, $unicode_semantics, $extra = '', $temp_filenames = null)
  1701. {
  1702. global $html_output, $html_file, $temp_target, $temp_urlbase, $unicode_and_native;
  1703. $kind = $unicode_and_native ? ($unicode_semantics ? ':U' : ':N') : '';
  1704. echo "$result$kind $tested [$tested_file] $extra\n";
  1705. if ($html_output)
  1706. {
  1707. if (isset($temp_filenames['file']) && @file_exists($temp_filenames['file'])) {
  1708. $url = str_replace($temp_target, $temp_urlbase, $temp_filenames['file']);
  1709. $tested = "<a href='$url'>$tested</a>";
  1710. }
  1711. if (isset($temp_filenames['skip']) && @file_exists($temp_filenames['skip'])) {
  1712. if (empty($extra)) {
  1713. $extra = "skipif";
  1714. }
  1715. $url = str_replace($temp_target, $temp_urlbase, $temp_filenames['skip']);
  1716. $extra = "<a href='$url'>$extra</a>";
  1717. } else if (empty($extra)) {
  1718. $extra = "&nbsp;";
  1719. }
  1720. if (isset($temp_filenames['diff']) && @file_exists($temp_filenames['diff'])) {
  1721. $url = str_replace($temp_target, $temp_urlbase, $temp_filenames['diff']);
  1722. $diff = "<a href='$url'>diff</a>";
  1723. } else {
  1724. $diff = "&nbsp;";
  1725. }
  1726. if (isset($temp_filenames['mem']) && @file_exists($temp_filenames['mem'])) {
  1727. $url = str_replace($temp_target, $temp_urlbase, $temp_filenames['mem']);
  1728. $mem = "<a href='$url'>leaks</a>";
  1729. } else {
  1730. $mem = "&nbsp;";
  1731. }
  1732. fwrite($html_file,
  1733. "<tr>" .
  1734. "<td>$result</td>" .
  1735. "<td>$tested</td>" .
  1736. "<td>$extra</td>" .
  1737. "<td>$diff</td>" .
  1738. "<td>$mem</td>" .
  1739. "</tr>\n");
  1740. }
  1741. }
  1742. /*
  1743. * Local variables:
  1744. * tab-width: 4
  1745. * c-basic-offset: 4
  1746. * End:
  1747. * vim: noet sw=4 ts=4
  1748. */
  1749. ?>