Annotation of embedaddon/php/ext/pcntl/tests/002.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: pcntl: pcntl_sigprocmask(), pcntl_sigwaitinfo(), pcntl_sigtimedwait()
        !             3: --SKIPIF--
        !             4: <?php
        !             5:        if (!extension_loaded('pcntl')) die('skip pcntl extension not available');
        !             6:        elseif (!extension_loaded('posix')) die('skip posix extension not available');
        !             7:        elseif (!function_exists('pcntl_sigwaitinfo') or !function_exists('pcntl_sigtimedwait')) die('skip required functionality is not available');
        !             8:        elseif (!defined('CLD_EXITED')) die('skip CLD_EXITED not defined');
        !             9: ?>
        !            10: --FILE--
        !            11: <?php
        !            12: 
        !            13: $pid = pcntl_fork();
        !            14: if ($pid == -1) {
        !            15:        die('failed');
        !            16: } else if ($pid) {
        !            17:        pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD,(string)SIGTERM));
        !            18:        $oldset = array();
        !            19:        pcntl_sigprocmask(SIG_BLOCK, array(), $oldset);
        !            20:        var_dump(in_array(SIGCHLD, $oldset));
        !            21:        var_dump(in_array(SIGTERM, $oldset));
        !            22: 
        !            23:        posix_kill(posix_getpid(), SIGTERM);
        !            24:        $signo = pcntl_sigwaitinfo(array(SIGTERM), $siginfo);
        !            25:        echo "signo == SIGTERM\n";
        !            26:        var_dump($signo === SIGTERM && $signo === $siginfo['signo']);
        !            27:        echo "code === SI_USER || SI_NOINFO\n";
        !            28:        if (defined('SI_NOINFO')) {
        !            29:                var_dump(($siginfo['code'] === SI_USER) || ($siginfo['code'] === SI_NOINFO));
        !            30:        } else {
        !            31:                var_dump($siginfo['code'] === SI_USER);
        !            32:        }
        !            33: 
        !            34:        pcntl_signal(SIGCHLD, function($signo){});
        !            35:        posix_kill($pid, SIGTERM);
        !            36:        $signo = pcntl_sigwaitinfo(array((string)SIGCHLD), $siginfo);
        !            37:        echo "signo == SIGCHLD\n";
        !            38:        var_dump($signo === SIGCHLD && $signo === $siginfo['signo']);
        !            39:        echo "code === CLD_KILLED\n";
        !            40:        var_dump($siginfo['code'] === CLD_KILLED);
        !            41:        echo "signo === SIGCHLD\n";
        !            42:        var_dump($siginfo['signo'] === SIGCHLD);
        !            43:        echo "signo === uid\n";
        !            44:        var_dump($siginfo['uid'] === posix_getuid());
        !            45:        echo "signo === pid\n";
        !            46:        var_dump($siginfo['pid'] === $pid);
        !            47:        pcntl_waitpid($pid, $status);
        !            48: 
        !            49:        set_error_handler(function($errno, $errstr) { echo "Error triggered\n"; }, E_WARNING);
        !            50: 
        !            51:        echo "sigprocmask with invalid arguments\n";
        !            52: 
        !            53:        /* Valgrind expectedly complains about this:
        !            54:          * "sigprocmask: unknown 'how' field 2147483647"
        !            55:         * Skip */
        !            56:        if (getenv("USE_ZEND_ALLOC") !== '0') {
        !            57:                var_dump(pcntl_sigprocmask(PHP_INT_MAX, array(SIGTERM)));
        !            58:        } else {
        !            59:                echo "Error triggered\n";
        !            60:                echo "bool(false)\n";
        !            61:        }
        !            62:        var_dump(pcntl_sigprocmask(SIG_SETMASK, array(0)));
        !            63: 
        !            64:        echo "sigwaitinfo with invalid arguments\n";
        !            65:        var_dump(pcntl_sigwaitinfo(array(0)));
        !            66: 
        !            67:        echo "sigtimedwait with invalid arguments\n";
        !            68:        var_dump(pcntl_sigtimedwait(array(SIGTERM), $signo, PHP_INT_MAX, PHP_INT_MAX));
        !            69: } else {
        !            70:        $siginfo = NULL;
        !            71:        pcntl_sigtimedwait(array(SIGINT), $siginfo, 3600, 0);
        !            72:        exit;
        !            73: }
        !            74: 
        !            75: ?>
        !            76: --EXPECTF--
        !            77: bool(true)
        !            78: bool(true)
        !            79: signo == SIGTERM
        !            80: bool(true)
        !            81: code === SI_USER || SI_NOINFO
        !            82: bool(true)
        !            83: signo == SIGCHLD
        !            84: bool(true)
        !            85: code === CLD_KILLED
        !            86: bool(true)
        !            87: signo === SIGCHLD
        !            88: bool(true)
        !            89: signo === uid
        !            90: bool(true)
        !            91: signo === pid
        !            92: bool(true)
        !            93: sigprocmask with invalid arguments
        !            94: Error triggered
        !            95: bool(false)
        !            96: Error triggered
        !            97: bool(false)
        !            98: sigwaitinfo with invalid arguments
        !            99: Error triggered
        !           100: bool(false)
        !           101: sigtimedwait with invalid arguments
        !           102: Error triggered
        !           103: int(-1)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>