summaryrefslogtreecommitdiff
path: root/run-tests.php
diff options
context:
space:
mode:
authorMichele Locati <michele@locati.it>2016-08-29 11:57:53 +0200
committerAnatol Belski <ab@php.net>2016-10-28 19:23:00 +0200
commit33301d5bae4964f74fd1fc8c4fc485abfde0378e (patch)
treef077a695e30b939114cf3bc541e71a2973045dda /run-tests.php
parent946eb9b452302a258c90752a9a4c81d1824c1a3a (diff)
downloadphp-git-33301d5bae4964f74fd1fc8c4fc485abfde0378e.tar.gz
Add VT100 support for Windows
Fix function names prefix Use Unicode version of GetFinalPathNameByHandle Use EG(windows_version_info) instead of RtlGetVersion Use the specified handle_id instead of STD_OUTPUT_HANDLE Switch from stream name to stream resource Allow running tests capturing only stdout and/or stderr Add tests for stream_vt100_support function Export Win32 console functions Fix x64 build Use zend_long instead of long long, use GetConsole instead of GetFinalPathNameByHandleW to check if a handle is a valid console stream Always use zend_long on any platform Use _get_osfhandle to determine the standard handle Accept stream names Raise warnings in case of invalid stream parameter Return true if disabling VT100 support on a not-console/redirected stream or on old Windows versions Remove php_win32_console_os_supports_vt100 Differentiate stdin vs stdout/stderr Simplify setting flag Allow avoid piping STDIN Let stream_vt100_support accept only resources Fix run-tests Revert console flags in case of failure Simplify logic of stream_vt100_support when setting the flag Return true if succeeded, false otherwise Drop support for STDIN More comprehensive tests for stream_vt100_support Remove old tests Fix name of included file and use absolute paths Enable ENABLE_VIRTUAL_TERMINAL_PROCESSING on Windows by default Remove tests for stream_vt100_support Split stream_vt100_support into stream_isatty+sapi_windows_vt100_support Add tests for stream_isatty Add tests for sapi_windows_vt100_support Return null from stream_isatty is neither Windows nor Posix Fallback to S_ISCHR if neither Windows nor Posix Avoid defining argc since it's only used once Better comment about php_win32_console_fileno_is_console Use events instead of cNumberOfEvents Do not restore previous console mode We need to restore previous console mode on failing SetConsole calls only for STDIN Don't configure STDOUT/STDERR on Windows with PHP_CLI_WIN32_NO_CONSOLE
Diffstat (limited to 'run-tests.php')
-rwxr-xr-xrun-tests.php65
1 files changed, 47 insertions, 18 deletions
diff --git a/run-tests.php b/run-tests.php
index 20d148b0b0..247e7d5313 100755
--- a/run-tests.php
+++ b/run-tests.php
@@ -1057,7 +1057,7 @@ function error_report($testname, $logname, $tested)
}
}
-function system_with_timeout($commandline, $env = null, $stdin = null)
+function system_with_timeout($commandline, $env = null, $stdin = null, $captureStdIn = true, $captureStdOut = true, $captureStdErr = true)
{
global $leak_check, $cwd;
@@ -1068,21 +1068,29 @@ function system_with_timeout($commandline, $env = null, $stdin = null)
$bin_env[$key] = $value;
}
- $proc = proc_open($commandline, array(
- 0 => array('pipe', 'r'),
- 1 => array('pipe', 'w'),
- 2 => array('pipe', 'w')
- ), $pipes, $cwd, $bin_env, array('suppress_errors' => true, 'binary_pipes' => true));
+ $descriptorspec = array();
+ if ($captureStdIn) {
+ $descriptorspec[0] = array('pipe', 'r');
+ }
+ if ($captureStdOut) {
+ $descriptorspec[1] = array('pipe', 'w');
+ }
+ if ($captureStdErr) {
+ $descriptorspec[2] = array('pipe', 'w');
+ }
+ $proc = proc_open($commandline, $descriptorspec, $pipes, $cwd, $bin_env, array('suppress_errors' => true, 'binary_pipes' => true));
if (!$proc) {
return false;
}
- if (!is_null($stdin)) {
- fwrite($pipes[0], $stdin);
+ if ($captureStdIn) {
+ if (!is_null($stdin)) {
+ fwrite($pipes[0], $stdin);
+ }
+ fclose($pipes[0]);
+ unset($pipes[0]);
}
- fclose($pipes[0]);
- unset($pipes[0]);
$timeout = $leak_check ? 300 : (isset($env['TEST_TIMEOUT']) ? $env['TEST_TIMEOUT'] : 60);
@@ -1102,7 +1110,13 @@ function system_with_timeout($commandline, $env = null, $stdin = null)
proc_terminate($proc, 9);
return $data;
} else if ($n > 0) {
- $line = fread($pipes[1], 8192);
+ if ($captureStdOut) {
+ $line = fread($pipes[1], 8192);
+ } elseif ($captureStdErr) {
+ $line = fread($pipes[2], 8192);
+ } else {
+ $line = '';
+ }
if (strlen($line) == 0) {
/* EOF */
break;
@@ -1332,6 +1346,21 @@ TEST $file
return 'BORKED';
}
+ if (isset($section_text['CAPTURE_STDIO'])) {
+ $captureStdIn = stripos($section_text['CAPTURE_STDIO'], 'STDIN') !== false;
+ $captureStdOut = stripos($section_text['CAPTURE_STDIO'], 'STDOUT') !== false;
+ $captureStdErr = stripos($section_text['CAPTURE_STDIO'], 'STDERR') !== false;
+ } else {
+ $captureStdIn = true;
+ $captureStdOut = true;
+ $captureStdErr = true;
+ }
+ if ($captureStdOut && $captureStdErr) {
+ $cmdRedirect = ' 2>&1';
+ } else {
+ $cmdRedirect = '';
+ }
+
$tested = trim($section_text['TEST']);
/* For GET/POST/PUT tests, check if cgi sapi is available and if it is, use it. */
@@ -1740,7 +1769,7 @@ TEST $file
}
save_text($tmp_post, $request);
- $cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
+ $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\"";
} elseif (array_key_exists('PUT', $section_text) && !empty($section_text['PUT'])) {
@@ -1774,7 +1803,7 @@ TEST $file
}
save_text($tmp_post, $request);
- $cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
+ $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\"";
} else if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) {
@@ -1791,7 +1820,7 @@ TEST $file
$env['CONTENT_LENGTH'] = $content_length;
}
- $cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
+ $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\"";
} else if (array_key_exists('GZIP_POST', $section_text) && !empty($section_text['GZIP_POST'])) {
@@ -1806,7 +1835,7 @@ TEST $file
$env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
$env['CONTENT_LENGTH'] = $content_length;
- $cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
+ $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\"";
} else if (array_key_exists('DEFLATE_POST', $section_text) && !empty($section_text['DEFLATE_POST'])) {
$post = trim($section_text['DEFLATE_POST']);
@@ -1819,7 +1848,7 @@ TEST $file
$env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
$env['CONTENT_LENGTH'] = $content_length;
- $cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
+ $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\"";
} else {
@@ -1827,7 +1856,7 @@ TEST $file
$env['CONTENT_TYPE'] = '';
$env['CONTENT_LENGTH'] = '';
- $cmd = "$php $pass_options $ini_settings -f \"$test_file\" $args 2>&1";
+ $cmd = "$php $pass_options $ini_settings -f \"$test_file\" $args$cmdRedirect";
}
if ($leak_check) {
@@ -1863,7 +1892,7 @@ COMMAND $cmd
junit_start_timer($shortname);
- $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null);
+ $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null, $captureStdIn, $captureStdOut, $captureStdErr);
junit_finish_timer($shortname);