summaryrefslogtreecommitdiffstats
path: root/chrome/common/ipc_tests.cc
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 22:00:47 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 22:00:47 +0000
commit95cb7fb94d22b073291ee45bf10ea880a4d93b33 (patch)
tree073bb49e20a94846f46106557904de2715c787c7 /chrome/common/ipc_tests.cc
parent767cc7f25de0c9be199d1f4f267e569ff6788119 (diff)
downloadchromium_src-95cb7fb94d22b073291ee45bf10ea880a4d93b33.zip
chromium_src-95cb7fb94d22b073291ee45bf10ea880a4d93b33.tar.gz
chromium_src-95cb7fb94d22b073291ee45bf10ea880a4d93b33.tar.bz2
Bring up ipc tests on POSIX.
Review URL: http://codereview.chromium.org/13158 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6634 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/ipc_tests.cc')
-rw-r--r--chrome/common/ipc_tests.cc129
1 files changed, 56 insertions, 73 deletions
diff --git a/chrome/common/ipc_tests.cc b/chrome/common/ipc_tests.cc
index e0c14c8..444824e 100644
--- a/chrome/common/ipc_tests.cc
+++ b/chrome/common/ipc_tests.cc
@@ -18,12 +18,13 @@
#include "base/perftimer.h"
#include "base/process_util.h"
#include "base/scoped_nsautorelease_pool.h"
+#include "base/test_suite.h"
#include "base/thread.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/ipc_channel.h"
#include "chrome/common/ipc_channel_proxy.h"
#include "chrome/common/ipc_message_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/multiprocess_func_list.h"
// Define to enable IPC performance testing instead of the regular unit tests
// #define PERFORMANCE_TEST
@@ -32,13 +33,43 @@ const wchar_t kTestClientChannel[] = L"T1";
const wchar_t kReflectorChannel[] = L"T2";
const wchar_t kFuzzerChannel[] = L"F3";
-const wchar_t kChild[] = L"child";
-const wchar_t kReflector[] = L"reflector";
-const wchar_t kFuzzer[] = L"fuzzer";
-
#ifndef PERFORMANCE_TEST
-TEST(IPCChannelTest, BasicMessageTest) {
+void IPCChannelTest::SetUp() {
+ MultiProcessTest::SetUp();
+
+ // Construct a fresh IO Message loop for the duration of each test.
+ message_loop_ = new MessageLoopForIO();
+}
+
+void IPCChannelTest::TearDown() {
+ delete message_loop_;
+ message_loop_ = NULL;
+
+ MultiProcessTest::TearDown();
+}
+
+base::ProcessHandle IPCChannelTest::SpawnChild(ChildType child_type) {
+ // kDebugChildren support.
+ bool debug_on_start = CommandLine().HasSwitch(switches::kDebugChildren);
+
+ switch (child_type) {
+ case TEST_CLIENT:
+ return MultiProcessTest::SpawnChild(L"RunTestClient", debug_on_start);
+ break;
+ case TEST_REFLECTOR:
+ return MultiProcessTest::SpawnChild(L"RunReflector", debug_on_start);
+ break;
+ case FUZZER_SERVER:
+ return MultiProcessTest::SpawnChild(L"RunFuzzServer", debug_on_start);
+ break;
+ default:
+ return NULL;
+ break;
+ }
+}
+
+TEST_F(IPCChannelTest, BasicMessageTest) {
int v1 = 10;
std::string v2("foobar");
std::wstring v3(L"hello world");
@@ -94,7 +125,6 @@ class MyChannelListener : public IPC::Channel::Listener {
iter.NextInt();
const std::string data = iter.NextString();
-
if (--messages_left_ == 0) {
MessageLoop::current()->Quit();
} else {
@@ -119,9 +149,7 @@ class MyChannelListener : public IPC::Channel::Listener {
};
static MyChannelListener channel_listener;
-// TODO(playmobil): Implement
-#if defined(OS_WIN)
-TEST(IPCChannelTest, ChannelTest) {
+TEST_F(IPCChannelTest, ChannelTest) {
// setup IPC channel
IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER,
&channel_listener);
@@ -129,7 +157,7 @@ TEST(IPCChannelTest, ChannelTest) {
channel_listener.Init(&chan);
- HANDLE process_handle = SpawnChild(TEST_CLIENT);
+ base::ProcessHandle process_handle = SpawnChild(TEST_CLIENT);
ASSERT_TRUE(process_handle);
Send(&chan, "hello from parent");
@@ -138,11 +166,12 @@ TEST(IPCChannelTest, ChannelTest) {
MessageLoop::current()->Run();
// cleanup child process
- WaitForSingleObject(process_handle, 5000);
- CloseHandle(process_handle);
+ EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 5000));
}
-TEST(IPCChannelTest, ChannelProxyTest) {
+// TODO(playmobil): Implement
+#if defined(OS_WIN)
+TEST_F(IPCChannelTest, ChannelProxyTest) {
// The thread needs to out-live the ChannelProxy.
base::Thread thread("ChannelProxyTestServer");
base::Thread::Options options;
@@ -171,7 +200,9 @@ TEST(IPCChannelTest, ChannelProxyTest) {
}
#endif // defined(OS_WIN)
-static bool RunTestClient() {
+MULTIPROCESS_TEST_MAIN(RunTestClient) {
+ MessageLoopForIO main_message_loop;
+
// setup IPC channel
IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_CLIENT,
&channel_listener);
@@ -180,7 +211,8 @@ static bool RunTestClient() {
Send(&chan, "hello from child");
// run message loop
MessageLoop::current()->Run();
- return true;
+ // return true;
+ return NULL;
}
#endif // !PERFORMANCE_TEST
@@ -204,7 +236,7 @@ static bool RunTestClient() {
// "quit" is sent, it will exit.
class ChannelReflectorListener : public IPC::Channel::Listener {
public:
- ChannelReflectorListener(IPC::Channel *channel) :
+ explicit ChannelReflectorListener(IPC::Channel *channel) :
channel_(channel),
count_messages_(0),
latency_messages_(0) {
@@ -301,7 +333,7 @@ class ChannelPerfListener : public IPC::Channel::Listener {
int latency_messages_;
};
-TEST(IPCChannelTest, Performance) {
+TEST_F(IPCChannelTest, Performance) {
// setup IPC channel
IPC::Channel chan(kReflectorChannel, IPC::Channel::MODE_SERVER, NULL);
ChannelPerfListener perf_listener(&chan, 10000, 100000);
@@ -333,7 +365,8 @@ TEST(IPCChannelTest, Performance) {
}
// This message loop bounces all messages back to the sender
-static bool RunReflector() {
+MULTIPROCESS_TEST_MAIN(RunReflector) {
+ MessageLoopForIO main_message_loop;
IPC::Channel chan(kReflectorChannel, IPC::Channel::MODE_CLIENT, NULL);
ChannelReflectorListener channel_reflector_listener(&chan);
chan.set_listener(&channel_reflector_listener);
@@ -345,7 +378,6 @@ static bool RunReflector() {
#endif // PERFORMANCE_TEST
-// TODO(playmobil): Implement
#if defined(OS_WIN)
// All fatal log messages (e.g. DCHECK failures) imply unit test failures
static void IPCTestAssertHandler(const std::string& str) {
@@ -362,54 +394,13 @@ static void SuppressErrorDialogs() {
UINT existing_flags = SetErrorMode(new_flags);
SetErrorMode(existing_flags | new_flags);
}
-
-HANDLE SpawnChild(ChildType child_type) {
- // spawn child process
- std::wstring cl(GetCommandLineW());
- switch(child_type) {
- case TEST_CLIENT:
- CommandLine::AppendSwitch(&cl, kChild);
- break;
- case TEST_REFLECTOR:
- CommandLine::AppendSwitch(&cl, kReflector);
- break;
- case FUZZER_SERVER:
- CommandLine::AppendSwitch(&cl, kFuzzer);
- break;
- default:
- return NULL;
- }
- // kDebugChildren support.
- if (CommandLine().HasSwitch(switches::kDebugChildren)) {
- CommandLine::AppendSwitch(&cl, switches::kDebugOnStart);
- }
- HANDLE process = NULL;
- if (!base::LaunchApp(cl, false, true, &process))
- return NULL;
-
- return process;
-}
#endif // defined(OS_WIN)
-// TODO(playmobil): Implement
-#if defined(OS_POSIX)
-base::ProcessHandle SpawnChild(ChildType child_type) {
- NOTIMPLEMENTED();
- return NULL;
-}
-#endif
-
-
int main(int argc, char** argv) {
base::ScopedNSAutoreleasePool scoped_pool;
base::EnableTerminationOnHeapCorruption();
-#if defined(OS_WIN)
- // Some tests may use base::Singleton<>, thus we need to instanciate
- // the AtExitManager or else we will leak objects.
- base::AtExitManager at_exit_manager;
-
- MessageLoopForIO main_message_loop;
+#if defined(OS_WIN)
// suppress standard crash dialogs and such unless a debugger is present.
if (!IsDebuggerPresent()) {
SuppressErrorDialogs();
@@ -417,19 +408,11 @@ int main(int argc, char** argv) {
}
#endif // defined(OS_WIN)
-#ifndef PERFORMANCE_TEST
- if (CommandLine().HasSwitch(kChild))
- return RunTestClient();
- if (CommandLine().HasSwitch(kFuzzer))
- return RunFuzzServer();
-#else
- if (CommandLine().HasSwitch(kReflector))
- return RunReflector();
+ int retval = TestSuite(argc, argv).Run();
+#ifdef PERFORMANCE_TEST
if (!InitPerfLog("ipc_perf_child.log"))
return 1;
#endif
-
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+ return retval;
}