diff options
Diffstat (limited to 'ext/pcntl/tests')
-rw-r--r-- | ext/pcntl/tests/001.phpt | 82 | ||||
-rw-r--r-- | ext/pcntl/tests/002.phpt | 103 | ||||
-rw-r--r-- | ext/pcntl/tests/003.phpt | 32 | ||||
-rw-r--r-- | ext/pcntl/tests/bug47566.phpt | 19 | ||||
-rw-r--r-- | ext/pcntl/tests/pcntl_alarm.phpt | 23 | ||||
-rw-r--r-- | ext/pcntl/tests/pcntl_exec.phpt | 15 | ||||
-rw-r--r-- | ext/pcntl/tests/pcntl_exec_2.phpt | 27 | ||||
-rw-r--r-- | ext/pcntl/tests/pcntl_exec_3.phpt | 17 | ||||
-rw-r--r-- | ext/pcntl/tests/pcntl_fork_basic.phpt | 27 | ||||
-rw-r--r-- | ext/pcntl/tests/pcntl_fork_variation.phpt | 48 | ||||
-rw-r--r-- | ext/pcntl/tests/pcntl_get_last_error.phpt | 17 | ||||
-rw-r--r-- | ext/pcntl/tests/pcntl_signal.phpt | 40 | ||||
-rw-r--r-- | ext/pcntl/tests/pcntl_signal_dispatch.phpt | 26 | ||||
-rw-r--r-- | ext/pcntl/tests/pcntl_wait.phpt | 66 | ||||
-rw-r--r-- | ext/pcntl/tests/signal_closure_handler.phpt | 25 |
15 files changed, 567 insertions, 0 deletions
diff --git a/ext/pcntl/tests/001.phpt b/ext/pcntl/tests/001.phpt new file mode 100644 index 0000000..fb1006e --- /dev/null +++ b/ext/pcntl/tests/001.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test pcntl wait functionality +--SKIPIF-- +<?php + if (!extension_loaded("pcntl")) print "skip"; + elseif (!function_exists("posix_kill")) print "skip posix_kill() not available"; +?> +--FILE-- +<?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(); +?> +--EXPECT-- +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 diff --git a/ext/pcntl/tests/002.phpt b/ext/pcntl/tests/002.phpt new file mode 100644 index 0000000..3cec883 --- /dev/null +++ b/ext/pcntl/tests/002.phpt @@ -0,0 +1,103 @@ +--TEST-- +pcntl: pcntl_sigprocmask(), pcntl_sigwaitinfo(), pcntl_sigtimedwait() +--SKIPIF-- +<?php + if (!extension_loaded('pcntl')) die('skip pcntl extension not available'); + elseif (!extension_loaded('posix')) die('skip posix extension not available'); + elseif (!function_exists('pcntl_sigwaitinfo') or !function_exists('pcntl_sigtimedwait')) die('skip required functionality is not available'); + elseif (!defined('CLD_EXITED')) die('skip CLD_EXITED not defined'); +?> +--FILE-- +<?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; +} + +?> +--EXPECTF-- +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) diff --git a/ext/pcntl/tests/003.phpt b/ext/pcntl/tests/003.phpt new file mode 100644 index 0000000..012277d --- /dev/null +++ b/ext/pcntl/tests/003.phpt @@ -0,0 +1,32 @@ +--TEST-- +pcntl: SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK +--SKIPIF-- +<?php + if (!extension_loaded('pcntl')) die('skip pcntl extension not available'); + elseif (!extension_loaded('posix')) die('skip posix extension not available'); + elseif (!function_exists('pcntl_sigwaitinfo') or !function_exists('pcntl_sigtimedwait')) die('skip required functionality is not available'); +?> +--FILE-- +<?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)); + +?> +--EXPECT-- +int(0) +int(2) +int(3) +int(2) +int(1) +int(0) diff --git a/ext/pcntl/tests/bug47566.phpt b/ext/pcntl/tests/bug47566.phpt new file mode 100644 index 0000000..6eb3dbc --- /dev/null +++ b/ext/pcntl/tests/bug47566.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #47566 (return value of pcntl_wexitstatus()) +--SKIPIF-- +<?php if (!extension_loaded("pcntl")) print "skip"; ?> +--FILE-- +<?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); +} +?> +--EXPECT-- +int(128) diff --git a/ext/pcntl/tests/pcntl_alarm.phpt b/ext/pcntl/tests/pcntl_alarm.phpt new file mode 100644 index 0000000..a9cae16 --- /dev/null +++ b/ext/pcntl/tests/pcntl_alarm.phpt @@ -0,0 +1,23 @@ +--TEST-- +pcntl_alarm() +--SKIPIF-- +<?php if (!function_exists("pcntl_sigtimedwait")) die("skip pcntl_sigtimedwait() not available"); ?> +--INI-- +max_execution_time=0 +--FILE-- +<?php +pcntl_signal(SIGALRM, function(){}); + +var_dump(pcntl_alarm()); +pcntl_alarm(0); +var_dump(pcntl_alarm(60)); +var_dump(pcntl_alarm(1) > 0); +$siginfo = array(); +var_dump(pcntl_sigtimedwait(array(SIGALRM),$siginfo,2) === SIGALRM); +?> +--EXPECTF-- +Warning: pcntl_alarm() expects exactly 1 parameter, 0 given in %s +NULL +int(0) +bool(true) +bool(true) diff --git a/ext/pcntl/tests/pcntl_exec.phpt b/ext/pcntl/tests/pcntl_exec.phpt new file mode 100644 index 0000000..9d2ec1d --- /dev/null +++ b/ext/pcntl/tests/pcntl_exec.phpt @@ -0,0 +1,15 @@ +--TEST-- +pcntl_exec() +--SKIPIF-- +<?php +if (!extension_loaded("pcntl")) print "skip"; +if (!getenv("TEST_PHP_EXECUTABLE") || !is_executable(getenv("TEST_PHP_EXECUTABLE"))) die("skip TEST_PHP_EXECUTABLE not set"); +?> +--FILE-- +<?php +echo "ok\n"; +pcntl_exec(getenv("TEST_PHP_EXECUTABLE")); +echo "nok\n"; +?> +--EXPECT-- +ok diff --git a/ext/pcntl/tests/pcntl_exec_2.phpt b/ext/pcntl/tests/pcntl_exec_2.phpt new file mode 100644 index 0000000..02b5e22 --- /dev/null +++ b/ext/pcntl/tests/pcntl_exec_2.phpt @@ -0,0 +1,27 @@ +--TEST-- +pcntl_exec() 2 +--SKIPIF-- +<?php + +if (!extension_loaded("pcntl")) print "skip"; +if (!getenv("TEST_PHP_EXECUTABLE") || !is_executable(getenv("TEST_PHP_EXECUTABLE"))) die("skip TEST_PHP_EXECUTABLE not set"); + +?> +--FILE-- +<?php +if (getenv("PCNTL_EXEC_TEST_IS_CHILD")) { + var_dump((binary)getenv("FOO")); + exit; +} +echo "ok\n"; +pcntl_exec(getenv("TEST_PHP_EXECUTABLE"), array(__FILE__), array( + b"PCNTL_EXEC_TEST_IS_CHILD" => b"1", + b"FOO" => b"BAR", + 1 => b"long") +); + +echo "nok\n"; +?> +--EXPECT-- +ok +string(3) "BAR" diff --git a/ext/pcntl/tests/pcntl_exec_3.phpt b/ext/pcntl/tests/pcntl_exec_3.phpt new file mode 100644 index 0000000..5349381 --- /dev/null +++ b/ext/pcntl/tests/pcntl_exec_3.phpt @@ -0,0 +1,17 @@ +--TEST-- +pcntl_exec() 3 +--SKIPIF-- +<?php if (!extension_loaded("pcntl")) print "skip"; ?> +--FILE-- +<?php +var_dump(pcntl_exec()); +$file = tempnam(sys_get_temp_dir(),"php"); +var_dump(pcntl_exec($file, array("foo","bar"), array("foo" => "bar"))); +unlink($file); +?> +--EXPECTF-- +Warning: pcntl_exec() expects at least 1 parameter, 0 given %s +NULL + +Warning: pcntl_exec(): Error has occurred: (errno %d) %s +bool(false) diff --git a/ext/pcntl/tests/pcntl_fork_basic.phpt b/ext/pcntl/tests/pcntl_fork_basic.phpt new file mode 100644 index 0000000..b1e2a9b --- /dev/null +++ b/ext/pcntl/tests/pcntl_fork_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test function pcntl_fork() by calling it with its expected arguments +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if (!extension_loaded('pcntl')) die('skip pcntl extension not available'); + elseif (!extension_loaded('posix')) die('skip posix extension not available'); +?> +--FILE-- +<?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); +} +?> +--EXPECTF-- +*** Test by calling method or function with its expected arguments, first print the child PID and the father *** +int(0) +int(%d) diff --git a/ext/pcntl/tests/pcntl_fork_variation.phpt b/ext/pcntl/tests/pcntl_fork_variation.phpt new file mode 100644 index 0000000..4eea071 --- /dev/null +++ b/ext/pcntl/tests/pcntl_fork_variation.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test function pcntl_fork() by testing the process isolation in the forking hierarchy father -> son -> grandson where father can not knows his grandson +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if (!extension_loaded('pcntl')) die('skip pcntl extension not available'); + elseif (!extension_loaded('posix')) die('skip posix extension not available'); +?> +--FILE-- +<?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"; + } +} +?> +--EXPECTF-- +*** 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 diff --git a/ext/pcntl/tests/pcntl_get_last_error.phpt b/ext/pcntl/tests/pcntl_get_last_error.phpt new file mode 100644 index 0000000..4ed66c9 --- /dev/null +++ b/ext/pcntl/tests/pcntl_get_last_error.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test pcntl_get_last_error() +--SKIPIF-- +<?php + if (!extension_loaded("pcntl")) print "skip"; +?> +--FILE-- +<?php +var_dump(pcntl_get_last_error()); +$pid = pcntl_wait($status); +var_dump($pid); +var_dump(pcntl_get_last_error() == PCNTL_ECHILD); +?> +--EXPECT-- +int(0) +int(-1) +bool(true) diff --git a/ext/pcntl/tests/pcntl_signal.phpt b/ext/pcntl/tests/pcntl_signal.phpt new file mode 100644 index 0000000..2db0130 --- /dev/null +++ b/ext/pcntl/tests/pcntl_signal.phpt @@ -0,0 +1,40 @@ +--TEST-- +pcntl_signal() +--SKIPIF-- +<?php if (!extension_loaded("pcntl")) print "skip"; ?> +<?php if (!extension_loaded("posix")) die("skip posix extension not available"); ?> +--FILE-- +<?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"; +?> +--EXPECTF-- +signal dispatched + +Warning: pcntl_signal() expects at least 2 parameters, 0 given in %s +NULL +bool(true) + +Warning: pcntl_signal(): Invalid signal %s +bool(false) + +Warning: pcntl_signal(): Invalid signal %s +bool(false) + +Warning: pcntl_signal(): not callable is not a callable function name error in %s +bool(false) +ok diff --git a/ext/pcntl/tests/pcntl_signal_dispatch.phpt b/ext/pcntl/tests/pcntl_signal_dispatch.phpt new file mode 100644 index 0000000..acf6cc0 --- /dev/null +++ b/ext/pcntl/tests/pcntl_signal_dispatch.phpt @@ -0,0 +1,26 @@ +--TEST-- +pcnt_signal_dispatch() +--SKIPIF-- +<?php + if (!extension_loaded("pcntl")) print "skip"; + elseif (!function_exists("pcntl_signal")) print "skip pcntl_signal() not available"; + elseif (!function_exists("pcntl_signal_dispatch")) print "skip pcntl_signal_dispatch() not available"; + elseif (!function_exists("posix_kill")) print "skip posix_kill() not available"; + elseif (!function_exists("posix_getpid")) print "skip posix_getpid() not available"; +?> +--FILE-- +<?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"; + +?> +--EXPECTF-- +Start! +Signal handler called! +Done! diff --git a/ext/pcntl/tests/pcntl_wait.phpt b/ext/pcntl/tests/pcntl_wait.phpt new file mode 100644 index 0000000..c304c84 --- /dev/null +++ b/ext/pcntl/tests/pcntl_wait.phpt @@ -0,0 +1,66 @@ +--TEST-- +pcntl_wait() +--SKIPIF-- +<?php if (!extension_loaded("pcntl")) print "skip"; ?> +<?php if (!extension_loaded("posix")) die("skip posix extension not available"); ?> +--FILE-- +<?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); +} +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +int(42) +int(-1) + +Warning: pcntl_wait() expects at least 1 parameter, 0 given in %s +NULL + +Warning: pcntl_waitpid() expects at least 2 parameters, 0 given in %s +NULL + +Warning: pcntl_wifexited() expects exactly 1 parameter, 0 given in %s +NULL + +Warning: pcntl_wifstopped() expects exactly 1 parameter, 0 given in %s +NULL + +Warning: pcntl_wifsignaled() expects exactly 1 parameter, 0 given in %s +NULL + +Warning: pcntl_wexitstatus() expects exactly 1 parameter, 0 given in %s +NULL + +Warning: pcntl_wtermsig() expects exactly 1 parameter, 0 given in %s +NULL + +Warning: pcntl_wstopsig() expects exactly 1 parameter, 0 given in %s +NULL diff --git a/ext/pcntl/tests/signal_closure_handler.phpt b/ext/pcntl/tests/signal_closure_handler.phpt new file mode 100644 index 0000000..438e051 --- /dev/null +++ b/ext/pcntl/tests/signal_closure_handler.phpt @@ -0,0 +1,25 @@ +--TEST-- +Closures as a signal handler +--SKIPIF-- +<?php + if (!extension_loaded("pcntl")) print "skip"; + elseif (!function_exists("pcntl_signal")) print "skip pcntl_signal() not available"; + elseif (!function_exists("posix_kill")) print "skip posix_kill() not available"; + elseif (!function_exists("posix_getpid")) print "skip posix_getpid() not available"; +?> +--FILE-- +<?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"; + +?> +--EXPECTF-- +Start! +Signal handler called! +Done! |