summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Le Blanc <lbarnaud@php.net>2008-09-12 19:49:46 +0000
committerArnaud Le Blanc <lbarnaud@php.net>2008-09-12 19:49:46 +0000
commit41201c78b2f07dee4293c379967024569d538bb4 (patch)
tree8daec9c7455cdca2f852afb263340fa638b2b6c3
parent52f5ee8805207a925b5f6467c17117e327e47607 (diff)
downloadphp-git-41201c78b2f07dee4293c379967024569d538bb4.tar.gz
Add tests for pcntl
-rw-r--r--ext/pcntl/tests/pcntl_alarm.phpt23
-rw-r--r--ext/pcntl/tests/pcntl_exec.phpt12
-rw-r--r--ext/pcntl/tests/pcntl_exec_2.phpt22
-rw-r--r--ext/pcntl/tests/pcntl_exec_3.phpt15
-rw-r--r--ext/pcntl/tests/pcntl_signal.phpt41
-rw-r--r--ext/pcntl/tests/pcntl_wait.phpt66
6 files changed, 179 insertions, 0 deletions
diff --git a/ext/pcntl/tests/pcntl_alarm.phpt b/ext/pcntl/tests/pcntl_alarm.phpt
new file mode 100644
index 0000000000..a9cae1616b
--- /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 0000000000..756fc959c3
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_exec.phpt
@@ -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
index 0000000000..d1672d2a30
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_exec_2.phpt
@@ -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
index 0000000000..1017593b5f
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_exec_3.phpt
@@ -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
index 0000000000..977f26fbcc
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_signal.phpt
@@ -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
index 0000000000..266bb399e5
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_wait.phpt
@@ -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