diff --git a/hphp/test/ext/test_ext.h b/hphp/test/ext/test_ext.h index 7df25cadf..0eb76077c 100644 --- a/hphp/test/ext/test_ext.h +++ b/hphp/test/ext/test_ext.h @@ -36,7 +36,6 @@ #include "hphp/facebook/extensions/urlextraction/test_ext_urlextraction.h" #include "hphp/test/ext/test_ext_curl.h" #include "hphp/test/ext/test_ext_imagesprite.h" -#include "hphp/test/ext/test_ext_ipc.h" #include "hphp/test/ext/test_ext_mailparse.h" #include "hphp/test/ext/test_ext_math.h" #include "hphp/test/ext/test_ext_mb.h" diff --git a/hphp/test/ext/test_ext_ipc.cpp b/hphp/test/ext/test_ext_ipc.cpp deleted file mode 100644 index c34f4ff47..000000000 --- a/hphp/test/ext/test_ext_ipc.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | HipHop for PHP | - +----------------------------------------------------------------------+ - | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ -*/ - -#include "hphp/test/ext/test_ext_ipc.h" -#include "hphp/runtime/ext/ext_ipc.h" -#include - -/////////////////////////////////////////////////////////////////////////////// - -bool TestExtIpc::RunTests(const std::string &which) { - bool ret = true; - - /* - RUN_TEST(test_ftok); - RUN_TEST(test_msg_get_queue); - RUN_TEST(test_msg_send); - RUN_TEST(test_msg_receive); - RUN_TEST(test_msg_remove_queue); - RUN_TEST(test_msg_set_queue); - RUN_TEST(test_msg_stat_queue); - RUN_TEST(test_sem_acquire); - RUN_TEST(test_sem_get); - RUN_TEST(test_sem_release); - RUN_TEST(test_sem_remove); - RUN_TEST(test_shm_attach); - RUN_TEST(test_shm_detach); - RUN_TEST(test_shm_remove); - RUN_TEST(test_shm_get_var); - RUN_TEST(test_shm_put_var); - RUN_TEST(test_shm_remove_var); - */ - RUN_TEST(test_message_queue); - RUN_TEST(test_semaphore); - RUN_TEST(test_shared_memory); - - return ret; -} - -/////////////////////////////////////////////////////////////////////////////// - -bool TestExtIpc::test_message_queue() { - static const StaticString s_msg_qnum("msg_qnum"); - char filename[64]; - strcpy(filename, "/tmp/XXXXXX"); - close(mkstemp(filename)); - - int64_t token = f_ftok(filename, "a"); - VERIFY(!f_msg_queue_exists(token)); - Object queue = f_msg_get_queue(token); - VERIFY(queue.get()); - VERIFY(f_msg_queue_exists(token)); - - int pid = fork(); - if (pid == 0) { - Object q = f_msg_get_queue(token); - always_assert(q.get()); - always_assert(f_msg_send(q, 2, "start")); - Variant type, msg; - always_assert(f_msg_receive(q, 1, ref(type), 100, ref(msg))); - always_assert(f_msg_send(q, 2, msg)); // echo - _exit(-1); - } - - Variant type, msg; - VERIFY(f_msg_receive(queue, 2, ref(type), 100, ref(msg))); - VERIFY(same(msg, "start")); - - VERIFY(f_msg_send(queue, 1, "ok")); - VERIFY(f_msg_receive(queue, 2, ref(type), 100, ref(msg))); - VERIFY(same(msg, "ok")); - - Array ret = f_msg_stat_queue(queue); - VS(ret[s_msg_qnum], 0); - f_msg_set_queue(queue, CREATE_MAP1("msg_perm.mode", 0666)); - - f_msg_remove_queue(queue); - int status = -1; - wait(&status); - return Count(true); -} - -bool TestExtIpc::test_ftok() { return test_message_queue();} -bool TestExtIpc::test_msg_get_queue() { return test_message_queue();} -bool TestExtIpc::test_msg_send() { return test_message_queue();} -bool TestExtIpc::test_msg_receive () { return test_message_queue();} -bool TestExtIpc::test_msg_remove_queue() { return test_message_queue();} -bool TestExtIpc::test_msg_set_queue() { return test_message_queue();} -bool TestExtIpc::test_msg_stat_queue() { return test_message_queue();} - -/////////////////////////////////////////////////////////////////////////////// - -bool TestExtIpc::test_semaphore() { - Variant ret = f_sem_get(0xDEADBEEF); - VERIFY(!same(ret, false)); - Object sem = ret.toObject(); - time_t now = time(0); - VERIFY(f_sem_acquire(sem)); - - int pid = fork(); - if (pid == 0) { - Variant ret = f_sem_get(0xDEADBEEF); - always_assert(!same(ret, false)); - Object sem = ret.toObject(); - - always_assert(f_sem_acquire(sem)); - - // This isn't a sure test, but may be false if f_sem_acquire() didn't work - time_t then = time(0); - always_assert(then - now > 1); - (void)then; - (void)now; - - always_assert(f_sem_release(sem)); - VERIFY(f_sem_remove(sem)); - _exit(-1); - } - - sleep(3); // aha - VERIFY(f_sem_release(sem)); - int status = -1; - wait(&status); - return Count(true); -} - -bool TestExtIpc::test_sem_acquire() { return test_semaphore();} -bool TestExtIpc::test_sem_get() { return test_semaphore();} -bool TestExtIpc::test_sem_release() { return test_semaphore();} -bool TestExtIpc::test_sem_remove() { return test_semaphore();} - -/////////////////////////////////////////////////////////////////////////////// - -bool TestExtIpc::test_shared_memory() { - Variant ret = f_shm_attach(0xDEADBEEF); - VERIFY(!same(ret, false)); - int64_t index = ret.toInt64(); - VERIFY(!f_shm_has_var(index, 1234)); - VERIFY(f_shm_put_var(index, 1234, "test")); - VERIFY(f_shm_has_var(index, 1234)); - - int pid = fork(); - if (pid == 0) { - Variant ret = f_shm_attach(index); - always_assert(!same(ret, false)); - Object mem = ret.toObject(); - - ret = f_shm_get_var(index, 1234); - always_assert(same(ret, "test")); - - always_assert(f_shm_remove_var(index, 1234)); - always_assert(f_shm_detach(index)); - _exit(-1); - } - - // Verifying f_shm_remove_var worked, this is not sure test though. - ret = f_shm_get_var(index, 1234); - for (int i = 0; i < 1000; i++) { - if (same(ret, false)) break; - usleep(1000); - ret = f_shm_get_var(index, 1234); - } - VERIFY(same(ret, false)); - - VERIFY(f_shm_remove(index)); - int status = -1; - wait(&status); - return Count(true); -} - -bool TestExtIpc::test_shm_attach() { return test_shared_memory();} -bool TestExtIpc::test_shm_detach() { return test_shared_memory();} -bool TestExtIpc::test_shm_remove() { return test_shared_memory();} -bool TestExtIpc::test_shm_get_var() { return test_shared_memory();} -bool TestExtIpc::test_shm_put_var() { return test_shared_memory();} -bool TestExtIpc::test_shm_remove_var() { return test_shared_memory();} diff --git a/hphp/test/ext/test_ext_ipc.h b/hphp/test/ext/test_ext_ipc.h deleted file mode 100644 index e9b126d3c..000000000 --- a/hphp/test/ext/test_ext_ipc.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | HipHop for PHP | - +----------------------------------------------------------------------+ - | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ -*/ - -#ifndef incl_HPHP_TEST_EXT_IPC_H_ -#define incl_HPHP_TEST_EXT_IPC_H_ - -// >>>>>> Generated by idl.php. Do NOT modify. <<<<<< - -#include "hphp/test/ext/test_cpp_ext.h" - -/////////////////////////////////////////////////////////////////////////////// - -class TestExtIpc : public TestCppExt { -public: - virtual bool RunTests(const std::string &which); - - bool test_ftok(); - bool test_msg_get_queue(); - bool test_msg_send(); - bool test_msg_receive(); - bool test_msg_remove_queue(); - bool test_msg_set_queue(); - bool test_msg_stat_queue(); - bool test_sem_acquire(); - bool test_sem_get(); - bool test_sem_release(); - bool test_sem_remove(); - bool test_shm_attach(); - bool test_shm_detach(); - bool test_shm_remove(); - bool test_shm_get_var(); - bool test_shm_put_var(); - bool test_shm_remove_var(); - - bool test_message_queue(); - bool test_semaphore(); - bool test_shared_memory(); -}; - -/////////////////////////////////////////////////////////////////////////////// - -#endif // incl_HPHP_TEST_EXT_IPC_H_ diff --git a/hphp/test/slow/ext_ipc/message_queue.php b/hphp/test/slow/ext_ipc/message_queue.php new file mode 100644 index 000000000..e6616e787 --- /dev/null +++ b/hphp/test/slow/ext_ipc/message_queue.php @@ -0,0 +1,35 @@ + 0666)); + +msg_remove_queue($queue); +pcntl_waitpid($pid, $status); + +unlink($filename); diff --git a/hphp/test/slow/ext_ipc/message_queue.php.expect b/hphp/test/slow/ext_ipc/message_queue.php.expect new file mode 100644 index 000000000..d13002500 --- /dev/null +++ b/hphp/test/slow/ext_ipc/message_queue.php.expect @@ -0,0 +1,4 @@ +bool(true) +string(5) "start" +string(2) "ok" +int(0) diff --git a/hphp/test/slow/ext_ipc/semaphore.php b/hphp/test/slow/ext_ipc/semaphore.php new file mode 100644 index 000000000..4265812c1 --- /dev/null +++ b/hphp/test/slow/ext_ipc/semaphore.php @@ -0,0 +1,29 @@ + 1)) { + echo "oops: $then $now\n"; + } + + sem_release($sem); + sem_remove($sem); + exit(0); +} + +sleep(3); // aha +sem_release($sem); +pcntl_waitpid($pid, $status); diff --git a/hphp/test/slow/ext_ipc/semaphore.php.expect b/hphp/test/slow/ext_ipc/semaphore.php.expect new file mode 100644 index 000000000..ea5b1fdc3 --- /dev/null +++ b/hphp/test/slow/ext_ipc/semaphore.php.expect @@ -0,0 +1 @@ +bool(true) diff --git a/hphp/test/slow/ext_ipc/shared_memory.php b/hphp/test/slow/ext_ipc/shared_memory.php new file mode 100644 index 000000000..cb0ede533 --- /dev/null +++ b/hphp/test/slow/ext_ipc/shared_memory.php @@ -0,0 +1,35 @@ +