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.

1757 lines
50 KiB

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