summaryrefslogtreecommitdiff
path: root/server-tests.php
diff options
context:
space:
mode:
Diffstat (limited to 'server-tests.php')
-rwxr-xr-xserver-tests.php220
1 files changed, 110 insertions, 110 deletions
diff --git a/server-tests.php b/server-tests.php
index ff4b9f6ffc..f914b01187 100755
--- a/server-tests.php
+++ b/server-tests.php
@@ -154,13 +154,13 @@ function post_result_data($query,$data)
$post = "php_test_data=" . urlencode(base64_encode(preg_replace("/[\\x00]/", "[0x0]", $data)));
$r = new HTTPRequest($url,NULL,NULL,$post);
return $this->response_headers['Status']=='200';
-}
+}
function execute($command, $args=NULL, $input=NULL, $cwd=NULL, $env=NULL)
{
$data = "";
-
+
if (gettype($args)=='array') {
$args = join($args,' ');
}
@@ -179,7 +179,7 @@ function execute($command, $args=NULL, $input=NULL, $cwd=NULL, $env=NULL)
return NULL;
}
}
-
+
fclose($pipes[0]);
while (true) {
@@ -247,7 +247,7 @@ class HTTPRequest
/*
URL is the full url
headers is assoc array of outgoing http headers
-
+
options may include
timeout
proxy_host
@@ -255,7 +255,7 @@ class HTTPRequest
proxy_user
proxy_pass
method (GET|POST)
-
+
post data is, well, post data. It is not processed so
multipart stuff must be prepared before calling this
(or add it to class)
@@ -269,14 +269,14 @@ class HTTPRequest
$this->postdata = &$postdata;
$this->doRequest();
}
-
+
function doRequest()
{
if (!$this->_validateUrl()) return;
-
- if (isset($this->options['timeout']))
+
+ if (isset($this->options['timeout']))
$this->timeout = (int)$this->options['timeout'];
-
+
$this->_sendHTTP();
}
@@ -295,7 +295,7 @@ class HTTPRequest
$this->urlparts['path'] = '/';
return TRUE;
}
-
+
function _parseResponse()
{
if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $this->incoming_payload, $match)) {
@@ -319,7 +319,7 @@ class HTTPRequest
$this->errmsg = 'Invalid HTTP Response';
return FALSE;
}
-
+
function &_getRequest()
{
$fullpath = $this->urlparts['path'].
@@ -343,13 +343,13 @@ class HTTPRequest
$headertext .= "$k: $v\r\n";
}
$method = trim($this->options['method'])?strtoupper(trim($this->options['method'])):'GET';
- $this->outgoing_payload =
+ $this->outgoing_payload =
"$method $fullpath HTTP/1.0\r\n".
$headertext."\r\n".
$this->postdata;
return $this->outgoing_payload;
}
-
+
function _sendHTTP()
{
$this->_getRequest();
@@ -378,7 +378,7 @@ class HTTPRequest
$this->errmsg = "Error Sending Request Data to $host";
return NULL;
}
-
+
while ($data = fread($fp, 32768)) {
$this->incoming_payload .= $data;
}
@@ -422,7 +422,7 @@ class testHarness {
'w' => array('TEST_WEB' ,'' ,0 ,'run tests via http'),
'x' => array('TEST_WEB_EXT' ,'file ext' ,'php' ,'http file extension to use')
);
-
+
public $conf = array();
public $test_to_run = array();
public $test_files = array();
@@ -439,7 +439,7 @@ class testHarness {
public $test_executable_iscgi = false;
public $inisettings; // the test executables settings, used for web tests
public $iswin32 = false;
-
+
public $ddash = "=====================================================================";
public $sdash = "---------------------------------------------------------------------";
@@ -463,7 +463,7 @@ class testHarness {
'error_append_string'=>'',
'auto_prepend_file'=>'',
'auto_append_file'=>'',
- );
+ );
public $env = array();
public $info_params = array();
@@ -472,7 +472,7 @@ class testHarness {
$this->checkRequirements();
$this->env = $_ENV;
$this->removeSensitiveEnvVars();
-
+
$this->initializeConfiguration();
$this->parseArgs();
$this->setTestPaths();
@@ -490,13 +490,13 @@ class testHarness {
$this->conf['TEST_PHP_SRCDIR'] = str_replace('/','\\',$this->conf['TEST_PHP_SRCDIR']);
$this->conf['TEST_BASE_PATH'] = str_replace('/','\\',$this->conf['TEST_BASE_PATH']);
}
-
+
if (!$this->conf['TEST_WEB'] && !is_executable($this->conf['TEST_PHP_EXECUTABLE'])) {
$this->error("invalid PHP executable specified by TEST_PHP_EXECUTABLE = " .
$this->conf['TEST_PHP_EXECUTABLE']);
return false;
}
-
+
$this->getInstalledExtensions();
$this->getExecutableInfo();
$this->getExecutableIniSettings();
@@ -506,11 +506,11 @@ class testHarness {
// add TEST_PHP_SRCDIR to the include path, this facilitates
// tests including files from src/tests
//$this->ini_overwrites['include_path'] = $this->cwd.($this->iswin32?';.;':':.:').$this->exec_info['INCLUDE_PATH'];
-
+
$params = array();
settings2array($this->ini_overwrites,$params);
$this->info_params = settings2params($params);
-
+
$this->contextHeader();
if ($this->conf['TEST_CONTEXT_INFO']) return;
$this->loadFileList();
@@ -524,7 +524,7 @@ class testHarness {
$out = $this->runscript(PHP_INI_SETTINGS_SCRIPT,true);
$this->inisettings = unserialize($out);
}
-
+
function getExecutableInfo()
{
$out = $this->runscript(PHP_INFO_SCRIPT,true);
@@ -540,7 +540,7 @@ class testHarness {
}
$this->exec_info = $info;
}
-
+
function getInstalledExtensions()
{
// get the list of installed extensions
@@ -579,21 +579,21 @@ class testHarness {
}
}
-
+
// Use this function to do any displaying of text, so that
// things can be over-written as necessary.
-
+
function writemsg($msg) {
-
+
echo $msg;
-
+
}
-
+
// Another wrapper function, this one should be used any time
// a particular test passes or fails
-
+
function showstatus($item, $status, $reason = '') {
-
+
switch($status) {
case 'PASSED':
$this->writemsg("PASSED: $item ($reason)\n");
@@ -606,8 +606,8 @@ class testHarness {
break;
}
}
-
-
+
+
function help()
{
$usage = "usage: php run-tests.php [options]\n";
@@ -616,17 +616,17 @@ class testHarness {
}
return $usage;
}
-
+
function parseArgs() {
global $argc;
global $argv;
global $_SERVER;
-
+
if (!isset($argv)) {
$argv = $_SERVER['argv'];
$argc = $_SERVER['argc'];
}
-
+
$conf = NULL;
for ($i=1; $i<$argc;) {
if ($argv[$i][0] != '-') continue;
@@ -661,7 +661,7 @@ class testHarness {
break;
}
}
-
+
// set config into environment, this allows
// executed tests to find out about the test
// configurations. config file or args overwrite
@@ -680,14 +680,14 @@ class testHarness {
$this->env['SSH_AUTH_SOCK']='deleted';
$this->env['SSH_TTY']='deleted';
}
-
+
function setEnvConfigVar($name)
{
if (isset($this->env[$name])) {
$this->conf[$name] = $this->env[$name];
}
}
-
+
function initializeConfiguration()
{
foreach ($this->xargs as $arg=>$arg_info) {
@@ -715,7 +715,7 @@ class testHarness {
}
}
}
-
+
function test_sort($a, $b) {
$ta = strpos($a, "{$this->cwd}/tests")===0 ? 1 + (strpos($a, "{$this->cwd}/tests/run-test")===0 ? 1 : 0) : 0;
$tb = strpos($b, "{$this->cwd}/tests")===0 ? 1 + (strpos($b, "{$this->cwd}/tests/run-test")===0 ? 1 : 0) : 0;
@@ -745,7 +745,7 @@ class testHarness {
exit;
}
}
-
+
//
// Write test context information.
//
@@ -767,12 +767,12 @@ class testHarness {
foreach ($this->conf as $k=>$v) {
$conf .= sprintf("%-20.s: %s\n",$k,$v);
}
-
+
$exeinfo = '';
if (!$this->conf['TEST_WEB'])
$exeinfo = "CWD : {$this->cwd}\n".
"PHP : {$this->conf['TEST_PHP_EXECUTABLE']}\n";
-
+
$this->writemsg("\n$this->ddash\n".
"$exeinfo$info\n".
"Test Harness Configuration:\n$conf\n".
@@ -780,7 +780,7 @@ class testHarness {
"Test Dirs : $dirs\n".
"$this->ddash\n");
}
-
+
function loadFileList()
{
foreach ($this->test_dirs as $dir) {
@@ -793,7 +793,7 @@ class testHarness {
usort($this->test_files,array($this,"test_sort"));
$this->writemsg("found ".count($this->test_files)." files\n");
}
-
+
function moveTestFiles()
{
if (!$this->conf['TEST_BASE_PATH'] ||
@@ -819,7 +819,7 @@ class testHarness {
}
$this->test_files = $files;
}
-
+
function findFilesInDir($dir,$is_ext_dir=FALSE,$ignore=FALSE)
{
$skip = array('.', '..', 'CVS');
@@ -833,13 +833,13 @@ class testHarness {
}
$this->findFilesInDir("$dir/$name", FALSE, $ignore || $skip_ext);
}
-
+
// Cleanup any left-over tmp files from last run.
if (substr($name, -4) == '.tmp') {
@unlink("$dir/$name");
continue;
}
-
+
// Otherwise we're only interested in *.phpt files.
if (substr($name, -5) == '.phpt') {
if ($ignore) {
@@ -852,7 +852,7 @@ class testHarness {
}
closedir($o);
}
-
+
function runHeader()
{
$this->writemsg("TIME START " . date('Y-m-d H:i:s', $this->start_time) . "\n".$this->ddash."\n");
@@ -862,14 +862,14 @@ class testHarness {
$this->writemsg("Running all test files.\n");
}
}
-
+
function run()
{
$this->start_time = time();
$this->runHeader();
// Run selected tests.
if (count($this->test_to_run)) {
-
+
foreach($this->test_to_run as $name=>$runnable) {
if(!preg_match("/\.phpt$/", $name))
continue;
@@ -891,10 +891,10 @@ class testHarness {
$this->writemsg("No tests were run.\n");
return;
}
-
+
$n_total = count($this->test_results);
$n_total += $this->ignored_by_ext;
-
+
$sum_results = array('PASSED'=>0, 'SKIPPED'=>0, 'FAILED'=>0);
foreach ($this->test_results as $v) {
$sum_results[$v]++;
@@ -904,7 +904,7 @@ class testHarness {
foreach ($sum_results as $v => $n) {
$percent_results[$v] = (100.0 * $n) / $n_total;
}
-
+
$this->writemsg("\n".$this->ddash."\n".
"TIME END " . date('Y-m-d H:i:s', $this->end_time) . "\n".
$this->ddash."\n".
@@ -920,7 +920,7 @@ class testHarness {
$this->sdash."\n".
"Time taken : " . sprintf("%4d seconds", $this->end_time - $this->start_time) . "\n".
$this->ddash."\n");
-
+
$failed_test_summary = '';
if ($this->failed_tests) {
$failed_test_summary .= "\n".$this->ddash."\n".
@@ -930,7 +930,7 @@ class testHarness {
}
$failed_test_summary .= $this->ddash."\n";
}
-
+
if ($failed_test_summary && !$this->conf['NO_PHPTEST_SUMMARY']) {
$this->writemsg($failed_test_summary);
}
@@ -944,9 +944,9 @@ class testHarness {
flush();
$user_input = fgets($fp, 10);
$just_save_results = (strtolower($user_input[0]) == 's');
-
+
if ($just_save_results || strlen(trim($user_input)) == 0 || strtolower($user_input[0]) == 'y') {
- /*
+ /*
* Collect information about the host system for our report
* Fetch phpinfo() output so that we can see the PHP environment
* Make an archive of all the failed tests
@@ -961,12 +961,12 @@ class testHarness {
$user_email = trim(fgets($fp, 1024));
$user_email = str_replace("@", " at ", str_replace(".", " dot ", $user_email));
}
-
+
$failed_tests_data = '';
$sep = "\n" . str_repeat('=', 80) . "\n";
-
+
$failed_tests_data .= $failed_test_summary . "\n";
-
+
if (array_sum($this->failed_tests)) {
foreach ($this->failed_tests as $test_info) {
$failed_tests_data .= $sep . $test_info['name'];
@@ -978,7 +978,7 @@ class testHarness {
} else {
$status = "success";
}
-
+
$failed_tests_data .= "\n" . $sep . 'BUILD ENVIRONMENT' . $sep;
$failed_tests_data .= "OS:\n". PHP_OS. "\n\n";
$automake = $autoconf = $libtool = $compiler = 'N/A';
@@ -999,7 +999,7 @@ class testHarness {
}
}
}
-
+
$failed_tests_data .= "Automake:\n$automake\n";
$failed_tests_data .= "Autoconf:\n$autoconf\n";
$failed_tests_data .= "Libtool:\n$libtool\n";
@@ -1013,7 +1013,7 @@ class testHarness {
$failed_tests_data .= $sep . "PHPINFO" . $sep;
$failed_tests_data .= shell_exec($this->conf['TEST_PHP_EXECUTABLE'].' -dhtml_errors=0 -i');
-
+
$compression = 0;
if ($just_save_results ||
@@ -1022,7 +1022,7 @@ class testHarness {
$fp = fopen($output_file, "w");
fwrite($fp, $failed_tests_data);
fclose($fp);
-
+
if (!$just_save_results)
echo "\nThe test script was unable to automatically send the report to PHP's QA Team\n";
echo "Please send ".$output_file." to ".PHP_QA_EMAIL." manually, thank you.\n";
@@ -1032,7 +1032,7 @@ class testHarness {
}
}
}
-
+
if($this->conf['REPORT_EXIT_STATUS'] and $sum_results['FAILED']) {
exit(1);
}
@@ -1041,7 +1041,7 @@ class testHarness {
function getINISettings(&$section_text)
{
$ini_settings = $this->ini_overwrites;
- // Any special ini settings
+ // Any special ini settings
// these may overwrite the test defaults...
if (array_key_exists('INI', $section_text)) {
settings2array(preg_split( "/[\n\r]+/", $section_text['INI']), $ini_settings);
@@ -1090,11 +1090,11 @@ class testHarness {
// eval fails if no newline
return eval("$data\n");
}
-
+
function getENVSettings(&$section_text,$testfile)
{
$env = $this->env;
- // Any special environment settings
+ // Any special environment settings
// these may overwrite the test defaults...
if (array_key_exists('ENV', $section_text)) {
$sect = $this->evalSettings($testfile,$section_text['ENV']);
@@ -1107,7 +1107,7 @@ class testHarness {
function getEvalTestSettings($section_text,$testfile)
{
$rq = array();
- // Any special environment settings
+ // Any special environment settings
// these may overwrite the test defaults...
if ($section_text) {
$sect = $this->evalSettings($testfile,$section_text);
@@ -1116,7 +1116,7 @@ class testHarness {
}
return $rq;
}
-
+
//
// Load the sections of the test file.
//
@@ -1131,10 +1131,10 @@ class testHarness {
'_FILE' => $file,
'_DIR' => realpath(dirname($file)),
);
-
+
$fp = @fopen($file, "r")
or $this->error("Cannot open test file: $file");
-
+
$section = '';
while (!feof($fp)) {
$line = fgets($fp);
@@ -1144,7 +1144,7 @@ class testHarness {
$section_text[$section] = '';
continue;
}
-
+
// Add to the section text.
$section_text[$section] .= $line;
}
@@ -1199,7 +1199,7 @@ class testHarness {
if ($this->conf['TEST_PHP_DETAILED'] > 2)
print "SKIPIF: [$output]\n";
if (preg_match("/^skip/i", $output)){
-
+
$reason = (preg_match("/^skip\s*(.+)\$/", $output)) ? preg_replace("/^skip\s*(.+)\$/", "\\1", $output) : FALSE;
$this->showstatus($section_text['TEST'], 'SKIPPED', $reason);
return 'SKIPPED';
@@ -1221,15 +1221,15 @@ class testHarness {
{
if ($this->conf['TEST_PHP_DETAILED'])
$this->writemsg("\n=================\nTEST $file\n");
-
+
$section_text = $this->getSectionText($file);
-
+
if ($this->iswin32)
$shortname = str_replace($this->conf['TEST_BASE_PATH'].'\\', '', $file);
else
$shortname = str_replace($this->conf['TEST_BASE_PATH'].'/', '', $file);
$tested = $section_text['TEST']." [$shortname]";
-
+
if ($this->conf['TEST_WEB']) {
$tmp_file = preg_replace('/\.phpt$/','.'.$this->conf['TEST_WEB_EXT'],$file);
$uri = $this->conf['TEST_BASE_SCRIPT_NAME'].str_replace($this->conf['TEST_BASE_PATH'], '', $tmp_file);
@@ -1238,19 +1238,19 @@ class testHarness {
$tmp_file = preg_replace('/\.phpt$/','.php',$file);
}
@unlink($tmp_file);
-
- // unlink old test results
+
+ // unlink old test results
@unlink(preg_replace('/\.phpt$/','.diff',$file));
@unlink(preg_replace('/\.phpt$/','.log',$file));
@unlink(preg_replace('/\.phpt$/','.exp',$file));
@unlink(preg_replace('/\.phpt$/','.out',$file));
-
+
if (!$this->conf['TEST_WEB']) {
// Reset environment from any previous test.
$env = $this->getENVSettings($section_text,$tmp_file);
$ini_overwrites = $this->getINIParams($section_text);
}
-
+
// if this is a cgi test, prepare for it
$query_string = '';
$havepost = array_key_exists('POST', $section_text) && !empty($section_text['POST']);
@@ -1276,7 +1276,7 @@ class testHarness {
$method = isset($request['method'])?$request['method']:$havepost?'POST':'GET';
$query_string = $haveget?$section_text['GET']:'';
-
+
$options = array();
$options['method']=$method;
if (isset($this->conf['timeout'])) $options['timeout'] = $this->conf['timeout'];
@@ -1284,7 +1284,7 @@ class testHarness {
if (isset($this->conf['proxy_port'])) $options['proxy_port'] = $this->conf['proxy_port'];
if (isset($this->conf['proxy_user'])) $options['proxy_user'] = $this->conf['proxy_user'];
if (isset($this->conf['proxy_pass'])) $options['proxy_pass'] = $this->conf['proxy_pass'];
-
+
$post = $havepost?$section_text['POST']:NULL;
$url = $this->conf['TEST_SERVER_URL'];
if (isset($request['SCRIPT_NAME']))
@@ -1303,7 +1303,7 @@ class testHarness {
$this->writemsg("\nURL = $url\n");
} else if ($do_cgi) {
$query_string = $haveget?$section_text['GET']:'';
-
+
if (!array_key_exists('GATEWAY_INTERFACE', $env))
$env['GATEWAY_INTERFACE']='CGI/1.1';
if (!array_key_exists('SERVER_SOFTWARE', $env))
@@ -1327,7 +1327,7 @@ class testHarness {
$env['SCRIPT_NAME']='';
if (!array_key_exists('SCRIPT_FILENAME', $env))
$env['SCRIPT_FILENAME']='';
-
+
if (array_key_exists('POST', $section_text) && (!$haveget || !empty($section_text['POST']))) {
$post = $section_text['POST'];
$content_length = strlen($post);
@@ -1346,14 +1346,14 @@ class testHarness {
$env['CONTENT_LENGTH']='';
}
if ($this->conf['TEST_PHP_DETAILED'] > 1)
- $this->writemsg("\nCONTENT_LENGTH = " . $env['CONTENT_LENGTH'] .
- "\nCONTENT_TYPE = " . $env['CONTENT_TYPE'] .
- "\nPATH_TRANSLATED = " . $env['PATH_TRANSLATED'] .
- "\nPATH_INFO = " . $env['PATH_INFO'] .
- "\nQUERY_STRING = " . $env['QUERY_STRING'] .
- "\nREDIRECT_STATUS = " . $env['REDIRECT_STATUS'] .
- "\nREQUEST_METHOD = " . $env['REQUEST_METHOD'] .
- "\nSCRIPT_NAME = " . $env['SCRIPT_NAME'] .
+ $this->writemsg("\nCONTENT_LENGTH = " . $env['CONTENT_LENGTH'] .
+ "\nCONTENT_TYPE = " . $env['CONTENT_TYPE'] .
+ "\nPATH_TRANSLATED = " . $env['PATH_TRANSLATED'] .
+ "\nPATH_INFO = " . $env['PATH_INFO'] .
+ "\nQUERY_STRING = " . $env['QUERY_STRING'] .
+ "\nREDIRECT_STATUS = " . $env['REDIRECT_STATUS'] .
+ "\nREQUEST_METHOD = " . $env['REQUEST_METHOD'] .
+ "\nSCRIPT_NAME = " . $env['SCRIPT_NAME'] .
"\nSCRIPT_FILENAME = " . $env['SCRIPT_FILENAME'] . "\n");
/* not cgi spec to put query string on command line,
but used by a couple tests to catch a security hole
@@ -1390,14 +1390,14 @@ class testHarness {
}
}
}
-
+
if ($this->conf['TEST_PHP_DETAILED'] > 2) {
echo "HEADERS: ";
print_r($headers);
echo "OUTPUT: \n$out\n";
-
+
}
-
+
// Does the output match what is expected?
$output = trim($out);
$output = preg_replace('/\r\n/',"\n",$output);
@@ -1473,7 +1473,7 @@ class testHarness {
$wanted_re = str_replace('%f', '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', $wanted_re);
$wanted_re = str_replace('%c', '.', $wanted_re);
// %f allows two points "-.0.0" but that is the best *simple* expression
-
+
}
/* DEBUG YOUR REGEX HERE
var_dump($wanted_re);
@@ -1482,7 +1482,7 @@ class testHarness {
*/
$failed = !preg_match("/^$wanted_re\$/s", $output);
}
-
+
$skipexpect = false;
if (!$failed && $this->conf['TEST_WEB'] && isset($section_text['EXPECTHEADERS'])) {
$want = array();
@@ -1502,7 +1502,7 @@ class testHarness {
$failed = TRUE;
}
}
-
+
// different servers may do different things on non-200 results
// for instance, IIS will deliver it's own error pages, so we
// cannot expect to match up the EXPECT section. We may however,
@@ -1510,50 +1510,50 @@ class testHarness {
// need to change later.
$skipexpect = isset($headers['Status']) && $headers['Status'] != 200;
}
-
+
if (!$failed && !$skipexpect && isset($section_text['EXPECT'])) {
$wanted = $section_text['EXPECT'];
$wanted = preg_replace('/\r\n/',"\n",$wanted);
$failed = (0 != strcmp($output,$wanted));
}
-
+
if (!$failed) {
@unlink($tmp_file);
$this->showstatus($tested, 'PASSED');
return 'PASSED';
}
-
+
// Test failed so we need to report details.
$this->showstatus($tested, 'FAILED');
-
+
$this->failed_tests[] = array(
'name' => $file,
'test_name' => $tested,
'output' => preg_replace('/\.phpt$/','.log', $file),
'diff' => preg_replace('/\.phpt$/','.diff', $file)
);
-
+
if ($this->conf['TEST_PHP_DETAILED'])
$this->writemsg(generate_diff($wanted,$output)."\n");
-
+
// write .exp
if (strpos($this->conf['TEST_PHP_LOG_FORMAT'],'E') !== FALSE) {
$logname = preg_replace('/\.phpt$/','.exp',$file);
file_put_contents($logname,$wanted);
}
-
+
// write .out
if (strpos($this->conf['TEST_PHP_LOG_FORMAT'],'O') !== FALSE) {
$logname = preg_replace('/\.phpt$/','.out',$file);
file_put_contents($logname,$output);
}
-
+
// write .diff
if (strpos($this->conf['TEST_PHP_LOG_FORMAT'],'D') !== FALSE) {
$logname = preg_replace('/\.phpt$/','.diff',$file);
file_put_contents($logname,generate_diff($wanted,$output));
}
-
+
// write .log
if (strpos($this->conf['TEST_PHP_LOG_FORMAT'],'L') !== FALSE) {
$logname = preg_replace('/\.phpt$/','.log',$file);
@@ -1572,7 +1572,7 @@ class testHarness {
//
// Write an error in a format recognizable to Emacs or MSVC.
//
- function error_report($testname,$logname,$tested)
+ function error_report($testname,$logname,$tested)
{
$testname = realpath($testname);
$logname = realpath($logname);