import zend pcntl tests

Esse commit está contido em:
Paul Tarjan
2013-04-22 19:31:50 -07:00
commit de Sara Golemon
commit 4710a5538a
23 arquivos alterados com 369 adições e 1 exclusões
+65
Ver Arquivo
@@ -0,0 +1,65 @@
<?php
$pid = pcntl_fork();
if ($pid == -1) {
die('failed');
} else if ($pid) {
pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD,(string)SIGTERM));
$oldset = array();
pcntl_sigprocmask(SIG_BLOCK, array(), $oldset);
var_dump(in_array(SIGCHLD, $oldset));
var_dump(in_array(SIGTERM, $oldset));
posix_kill(posix_getpid(), SIGTERM);
$signo = pcntl_sigwaitinfo(array(SIGTERM), $siginfo);
echo "signo == SIGTERM\n";
var_dump($signo === SIGTERM && $signo === $siginfo['signo']);
echo "code === SI_USER || SI_NOINFO\n";
if (defined('SI_NOINFO')) {
var_dump(($siginfo['code'] === SI_USER) || ($siginfo['code'] === SI_NOINFO));
} else {
var_dump($siginfo['code'] === SI_USER);
}
pcntl_signal(SIGCHLD, function($signo){});
posix_kill($pid, SIGTERM);
$signo = pcntl_sigwaitinfo(array((string)SIGCHLD), $siginfo);
echo "signo == SIGCHLD\n";
var_dump($signo === SIGCHLD && $signo === $siginfo['signo']);
echo "code === CLD_KILLED\n";
var_dump($siginfo['code'] === CLD_KILLED);
echo "signo === SIGCHLD\n";
var_dump($siginfo['signo'] === SIGCHLD);
echo "signo === uid\n";
var_dump($siginfo['uid'] === posix_getuid());
echo "signo === pid\n";
var_dump($siginfo['pid'] === $pid);
pcntl_waitpid($pid, $status);
set_error_handler(function($errno, $errstr) { echo "Error triggered\n"; }, E_WARNING);
echo "sigprocmask with invalid arguments\n";
/* Valgrind expectedly complains about this:
* "sigprocmask: unknown 'how' field 2147483647"
* Skip */
if (getenv("USE_ZEND_ALLOC") !== '0') {
var_dump(pcntl_sigprocmask(PHP_INT_MAX, array(SIGTERM)));
} else {
echo "Error triggered\n";
echo "bool(false)\n";
}
var_dump(pcntl_sigprocmask(SIG_SETMASK, array(0)));
echo "sigwaitinfo with invalid arguments\n";
var_dump(pcntl_sigwaitinfo(array(0)));
echo "sigtimedwait with invalid arguments\n";
var_dump(pcntl_sigtimedwait(array(SIGTERM), $signo, PHP_INT_MAX, PHP_INT_MAX));
} else {
$siginfo = NULL;
pcntl_sigtimedwait(array(SIGINT), $siginfo, 3600, 0);
exit;
}
?>
+27
Ver Arquivo
@@ -0,0 +1,27 @@
bool(true)
bool(true)
signo == SIGTERM
bool(true)
code === SI_USER || SI_NOINFO
bool(true)
signo == SIGCHLD
bool(true)
code === CLD_KILLED
bool(true)
signo === SIGCHLD
bool(true)
signo === uid
bool(true)
signo === pid
bool(true)
sigprocmask with invalid arguments
Error triggered
bool(false)
Error triggered
bool(false)
sigwaitinfo with invalid arguments
Error triggered
bool(false)
sigtimedwait with invalid arguments
Error triggered
int(-1)
+16
Ver Arquivo
@@ -0,0 +1,16 @@
<?php
pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD,SIGTERM), $old);
var_dump(count($old));
pcntl_sigprocmask(SIG_BLOCK, array(SIGINT), $old);
var_dump(count($old));
pcntl_sigprocmask(SIG_UNBLOCK, array(SIGINT), $old);
var_dump(count($old));
pcntl_sigprocmask(SIG_SETMASK, array(SIGINT), $old);
var_dump(count($old));
pcntl_sigprocmask(SIG_SETMASK, array(), $old);
var_dump(count($old));
pcntl_sigprocmask(SIG_SETMASK, array(), $old);
var_dump(count($old));
?>
@@ -0,0 +1,6 @@
int(0)
int(2)
int(3)
int(2)
int(1)
int(0)
@@ -0,0 +1,11 @@
<?php
echo "*** Test by calling method or function with its expected arguments, first print the child PID and the father ***\n";
$pid = pcntl_fork();
if ($pid > 0) {
pcntl_wait($status);
var_dump($pid);
} else {
var_dump($pid);
}
?>
@@ -0,0 +1,3 @@
*** Test by calling method or function with its expected arguments, first print the child PID and the father ***
int(0)
int(%d)
@@ -0,0 +1,6 @@
<?php
var_dump(pcntl_get_last_error());
$pid = pcntl_wait($status);
var_dump($pid);
var_dump(pcntl_get_last_error() == PCNTL_ECHILD);
?>
@@ -0,0 +1,3 @@
int(0)
int(-1)
bool(true)
@@ -0,0 +1,18 @@
<?php
pcntl_signal(SIGTERM, function($signo){
echo "signal dispatched\n";
});
posix_kill(posix_getpid(), SIGTERM);
pcntl_signal_dispatch();
var_dump(pcntl_signal());
var_dump(pcntl_signal(SIGALRM, SIG_IGN));
var_dump(pcntl_signal(-1, -1));
var_dump(pcntl_signal(-1, function(){}));
var_dump(pcntl_signal(SIGALRM, "not callable"));
/* test freeing queue in RSHUTDOWN */
posix_kill(posix_getpid(), SIGTERM);
echo "ok\n";
?>
@@ -0,0 +1,11 @@
signal dispatched
HipHop Warning: %a
NULL
bool(true)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
ok
+63
Ver Arquivo
@@ -0,0 +1,63 @@
<?php
function test_exit_waits(){
print "\n\nTesting pcntl_wifexited and wexitstatus....";
$pid=pcntl_fork();
if ($pid==0) {
sleep(1);
exit(-1);
} else {
$options=0;
pcntl_waitpid($pid, $status, $options);
if ( pcntl_wifexited($status) ) print "\nExited With: ". pcntl_wexitstatus($status);
}
}
function test_exit_signal(){
print "\n\nTesting pcntl_wifsignaled....";
$pid=pcntl_fork();
if ($pid==0) {
sleep(10);
exit;
} else {
$options=0;
posix_kill($pid, SIGTERM);
pcntl_waitpid($pid, $status, $options);
if ( pcntl_wifsignaled($status) ) {
$signal_print=pcntl_wtermsig($status);
if ($signal_print==SIGTERM) $signal_print="SIGTERM";
print "\nProcess was terminated by signal : ". $signal_print;
}
}
}
function test_stop_signal(){
print "\n\nTesting pcntl_wifstopped and pcntl_wstopsig....";
$pid=pcntl_fork();
if ($pid==0) {
sleep(1);
exit;
} else {
$options=WUNTRACED;
posix_kill($pid, SIGSTOP);
pcntl_waitpid($pid, $status, $options);
if ( pcntl_wifstopped($status) ) {
$signal_print=pcntl_wstopsig($status);
if ($signal_print==SIGSTOP) $signal_print="SIGSTOP";
print "\nProcess was stoped by signal : ". $signal_print;
}
posix_kill($pid, SIGCONT);
}
}
print "Staring wait.h tests....";
test_exit_waits();
test_exit_signal();
test_stop_signal();
?>
@@ -0,0 +1,10 @@
Staring wait.h tests....
Testing pcntl_wifexited and wexitstatus....
Exited With: 255
Testing pcntl_wifsignaled....
Process was terminated by signal : SIGTERM
Testing pcntl_wifstopped and pcntl_wstopsig....
Process was stoped by signal : SIGSTOP
+12
Ver Arquivo
@@ -0,0 +1,12 @@
<?php
$pid = pcntl_fork();
if ($pid == -1) {
echo "Unable to fork";
exit;
} elseif ($pid) {
$epid = pcntl_waitpid(-1,$status);
var_dump(pcntl_wexitstatus($status));
} else {
exit(128);
}
?>
@@ -0,0 +1 @@
int(128)
@@ -0,0 +1,29 @@
<?php
echo "*** Testing the process isolations between a process and its forks ***\n";
$pid = pcntl_fork();
if ($pid > 0) {
pcntl_wait($status);
echo "father is $pid\n";
if (!isset($pid2))
{
echo "father ($pid) doesn't know its grandsons\n";
}
}
else
{
echo "son ($pid)\n";
$pid2 = pcntl_fork();
if ($pid2 > 0)
{
pcntl_wait($status2);
echo "son is father of $pid2\n";
}
else
{
echo "grandson ($pid2)\n";
}
}
?>
@@ -0,0 +1,6 @@
*** Testing the process isolations between a process and its forks ***
son (0)
grandson (0)
son is father of %d
father is %d
father (%d) doesn't know its grandsons
@@ -0,0 +1,11 @@
<?php
pcntl_signal(SIGTERM, function ($signo) { echo "Signal handler called!\n"; });
echo "Start!\n";
posix_kill(posix_getpid(), SIGTERM);
$i = 0; // dummy
pcntl_signal_dispatch();
echo "Done!\n";
?>
@@ -0,0 +1,3 @@
Start!
Signal handler called!
Done!
+30
Ver Arquivo
@@ -0,0 +1,30 @@
<?php
$pid = pcntl_fork();
if ($pid == 1) {
die("failed");
} else if ($pid) {
$status = 0;
pcntl_wait($status, WUNTRACED);
var_dump(pcntl_wifexited($status));
posix_kill($pid, SIGCONT);
pcntl_wait($status);
var_dump(pcntl_wifsignaled($status));
var_dump(pcntl_wifstopped($status));
var_dump(pcntl_wexitstatus($status));
var_dump(pcntl_wait($status, WNOHANG | WUNTRACED));
var_dump(pcntl_wait());
var_dump(pcntl_waitpid());
var_dump(pcntl_wifexited());
var_dump(pcntl_wifstopped());
var_dump(pcntl_wifsignaled());
var_dump(pcntl_wexitstatus());
var_dump(pcntl_wtermsig());
var_dump(pcntl_wstopsig());
} else {
posix_kill(posix_getpid(), SIGSTOP);
exit(42);
}
?>
@@ -0,0 +1,21 @@
bool(false)
bool(false)
bool(false)
int(42)
int(-1)
HipHop Warning: %a
NULL
HipHop Warning: %a
NULL
HipHop Warning: %a
NULL
HipHop Warning: %a
NULL
HipHop Warning: %a
NULL
HipHop Warning: %a
NULL
HipHop Warning: %a
NULL
HipHop Warning: %a
NULL
@@ -0,0 +1,11 @@
<?php
declare (ticks = 1);
pcntl_signal(SIGTERM, function ($signo) { echo "Signal handler called!\n"; });
echo "Start!\n";
posix_kill(posix_getpid(), SIGTERM);
$i = 0; // dummy
echo "Done!\n";
?>
@@ -0,0 +1,3 @@
Start!
Signal handler called!
Done!
+3 -1
Ver Arquivo
@@ -99,6 +99,9 @@ no_import = (
'Zend/tests/callable_type_hint_003.phpt',
'Zend/tests/jump13.phpt',
'Zend/tests/heredoc_005.phpt',
'pcntl/tests/pcntl_exec.phpt',
'pcntl/tests/pcntl_exec_2.phpt',
'pcntl/tests/pcntl_exec_3.phpt',
# not imported yet, but will be
'/ext/exif',
@@ -110,7 +113,6 @@ no_import = (
'/ext/mcrypt',
'/ext/mysql',
'/ext/openssl',
'/ext/pcntl',
'/ext/pcre',
'/ext/pdo',
'/ext/pdo_mysql',