]> granicus.if.org Git - php/commitdiff
Add tests for pcntl
authorArnaud Le Blanc <lbarnaud@php.net>
Fri, 12 Sep 2008 19:49:38 +0000 (19:49 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Fri, 12 Sep 2008 19:49:38 +0000 (19:49 +0000)
ext/pcntl/tests/pcntl_alarm.phpt [new file with mode: 0644]
ext/pcntl/tests/pcntl_exec.phpt [new file with mode: 0644]
ext/pcntl/tests/pcntl_exec_2.phpt [new file with mode: 0644]
ext/pcntl/tests/pcntl_exec_3.phpt [new file with mode: 0644]
ext/pcntl/tests/pcntl_signal.phpt [new file with mode: 0644]
ext/pcntl/tests/pcntl_wait.phpt [new file with mode: 0644]

diff --git a/ext/pcntl/tests/pcntl_alarm.phpt b/ext/pcntl/tests/pcntl_alarm.phpt
new file mode 100644 (file)
index 0000000..a9cae16
--- /dev/null
@@ -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 (file)
index 0000000..756fc95
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+pcntl_exec()
+--SKIPIF--
+<?php 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 (file)
index 0000000..d1672d2
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+pcntl_exec() 2
+--SKIPIF--
+<?php 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 (file)
index 0000000..1017593
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+pcntl_exec() 3
+--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 occured: (errno %d) %s
+bool(false)
diff --git a/ext/pcntl/tests/pcntl_signal.phpt b/ext/pcntl/tests/pcntl_signal.phpt
new file mode 100644 (file)
index 0000000..977f26f
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+pcntl_signal()
+--SKIPIF--
+<?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 value for handle argument specified in %s
+
+Warning: pcntl_signal(): Error assigning signal %s
+bool(false)
+
+Warning: pcntl_signal(): Error assigning 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_wait.phpt b/ext/pcntl/tests/pcntl_wait.phpt
new file mode 100644 (file)
index 0000000..266bb39
--- /dev/null
@@ -0,0 +1,66 @@
+--TEST--
+pcntl_wait()
+--SKIPIF--
+<?php if (!extension_loaded("posix")) die("skip posix extension not available"); ?>
+<?php 
+--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