From: Wez Furlong Date: Sat, 15 Feb 2003 18:09:52 +0000 (+0000) Subject: If a test does not have any data after 60 seconds of waiting, assume that X-Git-Tag: RELEASE_0_5~996 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e035fe14e0681f9ebc78897bc84c5c6b6d24474a;p=php If a test does not have any data after 60 seconds of waiting, assume that it died a horrible death and kill it. This is useful on windows when a message box is popped-up during an automated test-run. --- diff --git a/run-tests.php b/run-tests.php index 646ab253c3..cb68f32653 100755 --- a/run-tests.php +++ b/run-tests.php @@ -516,6 +516,40 @@ function error_report($testname,$logname,$tested) } } +function system_with_timeout($commandline) +{ + $data = ""; + + $proc = proc_open($commandline, array(1 => array('pipe', 'w')), $pipes); + + if (!$proc) + return false; + + while (true) { + /* hide errors from interrupted syscalls */ + $r = $pipes; + $w = null; + $e = null; + $n = stream_select($r, $w, $e, 60); + + if ($n == 0) { + /* timed out */ + $data .= "\n ** ERROR: process timed out **\n"; + proc_terminate($proc); + return $data; + } else if ($n) { + $line = fgets($pipes[1]); + if ($line === false) { + /* EOF */ + break; + } + $data .= $line; + } + } + $code = proc_close($proc); + return $data; +} + // // Run an individual test case. // @@ -667,7 +701,8 @@ SCRIPT_FILENAME = " . getenv("SCRIPT_FILENAME") . " COMMAND $cmd "; - $out = `$cmd`; +// $out = `$cmd`; + $out = system_with_timeout($cmd); @unlink($tmp_post);