diff options
author | Arnaud Le Blanc <lbarnaud@php.net> | 2008-07-29 16:59:10 +0000 |
---|---|---|
committer | Arnaud Le Blanc <lbarnaud@php.net> | 2008-07-29 16:59:10 +0000 |
commit | c58e2b9d20610b652535ccd01a8643dcf425742c (patch) | |
tree | 1d45b0f0db2a37524b5b9258043fd224491126a5 /ext/pcntl/tests | |
parent | 204fcbe5d3ffb4a9c1383e39f7549b8326801894 (diff) | |
download | php-git-c58e2b9d20610b652535ccd01a8643dcf425742c.tar.gz |
MFH: Added pcntl_sigwaitinfo(), pcntl_sigtimedwait() and pcntl_sigprocmask()
[DOC] pcntl_sigprocmask() allows to block signals. pcntl_sigwaitinfo()
allows to fetch blocked signals or signals delivered while pcntl_sigwaitinfo()
is running. pcntl_sigtimedwait() is pcntl_sigwaitinfo() with a timeout.
Diffstat (limited to 'ext/pcntl/tests')
-rw-r--r-- | ext/pcntl/tests/002.phpt | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/ext/pcntl/tests/002.phpt b/ext/pcntl/tests/002.phpt new file mode 100644 index 0000000000..3d06d5e437 --- /dev/null +++ b/ext/pcntl/tests/002.phpt @@ -0,0 +1,87 @@ +--TEST-- +pcntl: pcntl_sigprocmask(), pcntl_sigwaitinfo(), pcntl_sigtimedwait() +--SKIPIF-- +<?php +if (!extension_loaded('pcntl')) die('skip pcntl extension not available'); +if (!extension_loaded('posix')) die('skip posix extension not available'); +?> +--FILE-- +<?php + +$pid = pcntl_fork(); +if ($pid == -1) { + die('failed'); +} else if ($pid) { + pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD,(string)SIGTERM)); + 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); + + echo "sigprocmask with invalid arguments\n"; + var_dump(pcntl_sigprocmask(PHP_INT_MAX, array(SIGTERM))); + 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(SIGTERM), $siginfo, PHP_INT_MAX, 999999999); + exit; +} + +?> +--EXPECTF-- +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 + +Warning: pcntl_sigprocmask(): Invalid argument in %s on line %d +bool(false) + +Warning: pcntl_sigprocmask(): Invalid argument in %s on line %d +bool(false) +sigwaitinfo with invalid arguments + +Warning: pcntl_sigwaitinfo(): Invalid argument in %s on line %d +bool(false) +sigtimedwait with invalid arguments + +Warning: pcntl_sigtimedwait(): Invalid argument in %s on line %d +int(-1) |