blob: aa30182fb037bb2107f07c82e16ce4763e9b927c [file] [log] [blame]
[email protected]b7243c42010-07-23 05:23:131// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]645aaa52009-02-07 01:03:055#include "build/build_config.h"
6
[email protected]d4651ff2008-12-02 16:51:587#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:298#include <windows.h>
[email protected]43cf8152009-02-07 00:57:459#elif defined(OS_POSIX)
10#include <sys/types.h>
[email protected]43cf8152009-02-07 00:57:4511#include <unistd.h>
[email protected]d4651ff2008-12-02 16:51:5812#endif
[email protected]43cf8152009-02-07 00:57:4513
initial.commit09911bf2008-07-26 23:55:2914#include <stdio.h>
initial.commit09911bf2008-07-26 23:55:2915#include <string>
[email protected]b7243c42010-07-23 05:23:1316#include <utility>
initial.commit09911bf2008-07-26 23:55:2917
[email protected]946d1b22009-07-22 23:57:2118#include "ipc/ipc_tests.h"
initial.commit09911bf2008-07-26 23:55:2919
20#include "base/base_switches.h"
21#include "base/command_line.h"
22#include "base/debug_on_start.h"
23#include "base/perftimer.h"
[email protected]fb895c62009-10-09 18:20:3024#include "base/test/perf_test_suite.h"
25#include "base/test/test_suite.h"
initial.commit09911bf2008-07-26 23:55:2926#include "base/thread.h"
[email protected]946d1b22009-07-22 23:57:2127#include "ipc/ipc_descriptors.h"
28#include "ipc/ipc_channel.h"
29#include "ipc/ipc_channel_proxy.h"
30#include "ipc/ipc_message_utils.h"
31#include "ipc/ipc_switches.h"
[email protected]95cb7fb92008-12-09 22:00:4732#include "testing/multiprocess_func_list.h"
initial.commit09911bf2008-07-26 23:55:2933
34// Define to enable IPC performance testing instead of the regular unit tests
35// #define PERFORMANCE_TEST
36
[email protected]9a3a293b2009-06-04 22:28:1637const char kTestClientChannel[] = "T1";
38const char kReflectorChannel[] = "T2";
39const char kFuzzerChannel[] = "F3";
[email protected]0840cc72009-11-24 16:14:5340const char kSyncSocketChannel[] = "S4";
initial.commit09911bf2008-07-26 23:55:2941
[email protected]c2f10ed2009-02-10 00:52:5742const size_t kLongMessageStringNumBytes = 50000;
43
initial.commit09911bf2008-07-26 23:55:2944#ifndef PERFORMANCE_TEST
45
[email protected]95cb7fb92008-12-09 22:00:4746void IPCChannelTest::SetUp() {
47 MultiProcessTest::SetUp();
48
49 // Construct a fresh IO Message loop for the duration of each test.
50 message_loop_ = new MessageLoopForIO();
51}
52
53void IPCChannelTest::TearDown() {
54 delete message_loop_;
55 message_loop_ = NULL;
56
57 MultiProcessTest::TearDown();
58}
59
[email protected]df3c1ca12008-12-19 21:37:0160#if defined(OS_WIN)
61base::ProcessHandle IPCChannelTest::SpawnChild(ChildType child_type,
62 IPC::Channel *channel) {
[email protected]95cb7fb92008-12-09 22:00:4763 // kDebugChildren support.
[email protected]bb975362009-01-21 01:00:2264 bool debug_on_start =
65 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren);
[email protected]95cb7fb92008-12-09 22:00:4766
67 switch (child_type) {
68 case TEST_CLIENT:
[email protected]d420c31e2010-07-30 02:14:2269 return MultiProcessTest::SpawnChild("RunTestClient", debug_on_start);
[email protected]95cb7fb92008-12-09 22:00:4770 case TEST_REFLECTOR:
[email protected]d420c31e2010-07-30 02:14:2271 return MultiProcessTest::SpawnChild("RunReflector", debug_on_start);
[email protected]95cb7fb92008-12-09 22:00:4772 case FUZZER_SERVER:
[email protected]d420c31e2010-07-30 02:14:2273 return MultiProcessTest::SpawnChild("RunFuzzServer", debug_on_start);
[email protected]0840cc72009-11-24 16:14:5374 case SYNC_SOCKET_SERVER:
[email protected]d420c31e2010-07-30 02:14:2275 return MultiProcessTest::SpawnChild("RunSyncSocketServer", debug_on_start);
[email protected]95cb7fb92008-12-09 22:00:4776 default:
77 return NULL;
[email protected]95cb7fb92008-12-09 22:00:4778 }
79}
[email protected]df3c1ca12008-12-19 21:37:0180#elif defined(OS_POSIX)
81base::ProcessHandle IPCChannelTest::SpawnChild(ChildType child_type,
82 IPC::Channel *channel) {
83 // kDebugChildren support.
[email protected]bb975362009-01-21 01:00:2284 bool debug_on_start =
85 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren);
[email protected]df3c1ca12008-12-19 21:37:0186
87 base::file_handle_mapping_vector fds_to_map;
[email protected]cc8f1462009-06-12 17:36:5588 const int ipcfd = channel->GetClientFileDescriptor();
89 if (ipcfd > -1) {
[email protected]b7243c42010-07-23 05:23:1390 fds_to_map.push_back(std::pair<int, int>(ipcfd, kPrimaryIPCChannel + 3));
[email protected]df3c1ca12008-12-19 21:37:0191 }
92
93 base::ProcessHandle ret = NULL;
94 switch (child_type) {
95 case TEST_CLIENT:
[email protected]d420c31e2010-07-30 02:14:2296 ret = MultiProcessTest::SpawnChild("RunTestClient",
[email protected]df3c1ca12008-12-19 21:37:0197 fds_to_map,
98 debug_on_start);
[email protected]df3c1ca12008-12-19 21:37:0199 break;
[email protected]526776c2009-02-07 00:39:26100 case TEST_DESCRIPTOR_CLIENT:
[email protected]d420c31e2010-07-30 02:14:22101 ret = MultiProcessTest::SpawnChild("RunTestDescriptorClient",
[email protected]526776c2009-02-07 00:39:26102 fds_to_map,
103 debug_on_start);
[email protected]526776c2009-02-07 00:39:26104 break;
[email protected]e8351b7e2009-02-10 22:25:39105 case TEST_DESCRIPTOR_CLIENT_SANDBOXED:
[email protected]d420c31e2010-07-30 02:14:22106 ret = MultiProcessTest::SpawnChild("RunTestDescriptorClientSandboxed",
[email protected]e8351b7e2009-02-10 22:25:39107 fds_to_map,
108 debug_on_start);
[email protected]e8351b7e2009-02-10 22:25:39109 break;
[email protected]df3c1ca12008-12-19 21:37:01110 case TEST_REFLECTOR:
[email protected]d420c31e2010-07-30 02:14:22111 ret = MultiProcessTest::SpawnChild("RunReflector",
[email protected]df3c1ca12008-12-19 21:37:01112 fds_to_map,
113 debug_on_start);
[email protected]df3c1ca12008-12-19 21:37:01114 break;
115 case FUZZER_SERVER:
[email protected]d420c31e2010-07-30 02:14:22116 ret = MultiProcessTest::SpawnChild("RunFuzzServer",
[email protected]df3c1ca12008-12-19 21:37:01117 fds_to_map,
118 debug_on_start);
[email protected]df3c1ca12008-12-19 21:37:01119 break;
[email protected]0840cc72009-11-24 16:14:53120 case SYNC_SOCKET_SERVER:
[email protected]d420c31e2010-07-30 02:14:22121 ret = MultiProcessTest::SpawnChild("RunSyncSocketServer",
[email protected]0840cc72009-11-24 16:14:53122 fds_to_map,
123 debug_on_start);
124 break;
[email protected]df3c1ca12008-12-19 21:37:01125 default:
126 return NULL;
127 break;
128 }
129 return ret;
130}
131#endif // defined(OS_POSIX)
[email protected]95cb7fb92008-12-09 22:00:47132
133TEST_F(IPCChannelTest, BasicMessageTest) {
initial.commit09911bf2008-07-26 23:55:29134 int v1 = 10;
135 std::string v2("foobar");
136 std::wstring v3(L"hello world");
137
138 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL);
139 EXPECT_TRUE(m.WriteInt(v1));
140 EXPECT_TRUE(m.WriteString(v2));
141 EXPECT_TRUE(m.WriteWString(v3));
142
143 void* iter = NULL;
144
145 int vi;
146 std::string vs;
147 std::wstring vw;
148
149 EXPECT_TRUE(m.ReadInt(&iter, &vi));
150 EXPECT_EQ(v1, vi);
151
152 EXPECT_TRUE(m.ReadString(&iter, &vs));
153 EXPECT_EQ(v2, vs);
154
155 EXPECT_TRUE(m.ReadWString(&iter, &vw));
156 EXPECT_EQ(v3, vw);
157
158 // should fail
159 EXPECT_FALSE(m.ReadInt(&iter, &vi));
160 EXPECT_FALSE(m.ReadString(&iter, &vs));
161 EXPECT_FALSE(m.ReadWString(&iter, &vw));
162}
163
164static void Send(IPC::Message::Sender* sender, const char* text) {
165 static int message_index = 0;
166
167 IPC::Message* message = new IPC::Message(0,
168 2,
169 IPC::Message::PRIORITY_NORMAL);
170 message->WriteInt(message_index++);
171 message->WriteString(std::string(text));
172
[email protected]3d1b6662009-01-29 17:03:11173 // Make sure we can handle large messages.
[email protected]c2f10ed2009-02-10 00:52:57174 char junk[kLongMessageStringNumBytes];
[email protected]3d1b6662009-01-29 17:03:11175 memset(junk, 'a', sizeof(junk)-1);
initial.commit09911bf2008-07-26 23:55:29176 junk[sizeof(junk)-1] = 0;
177 message->WriteString(std::string(junk));
178
179 // DEBUG: printf("[%u] sending message [%s]\n", GetCurrentProcessId(), text);
180 sender->Send(message);
181}
182
183class MyChannelListener : public IPC::Channel::Listener {
184 public:
185 virtual void OnMessageReceived(const IPC::Message& message) {
186 IPC::MessageIterator iter(message);
187
[email protected]d4651ff2008-12-02 16:51:58188 iter.NextInt();
initial.commit09911bf2008-07-26 23:55:29189 const std::string data = iter.NextString();
[email protected]c2f10ed2009-02-10 00:52:57190 const std::string big_string = iter.NextString();
191 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length());
192
193
initial.commit09911bf2008-07-26 23:55:29194 if (--messages_left_ == 0) {
195 MessageLoop::current()->Quit();
196 } else {
197 Send(sender_, "Foo");
198 }
199 }
200
[email protected]b6be5882008-11-07 21:53:03201 virtual void OnChannelError() {
202 // There is a race when closing the channel so the last message may be lost.
203 EXPECT_LE(messages_left_, 1);
204 MessageLoop::current()->Quit();
205 }
206
initial.commit09911bf2008-07-26 23:55:29207 void Init(IPC::Message::Sender* s) {
208 sender_ = s;
209 messages_left_ = 50;
210 }
211
212 private:
213 IPC::Message::Sender* sender_;
214 int messages_left_;
215};
initial.commit09911bf2008-07-26 23:55:29216
[email protected]95cb7fb92008-12-09 22:00:47217TEST_F(IPCChannelTest, ChannelTest) {
[email protected]c2f10ed2009-02-10 00:52:57218 MyChannelListener channel_listener;
[email protected]3d1b6662009-01-29 17:03:11219 // Setup IPC channel.
initial.commit09911bf2008-07-26 23:55:29220 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER,
221 &channel_listener);
[email protected]39703fb2010-10-19 19:11:15222 ASSERT_TRUE(chan.Connect());
initial.commit09911bf2008-07-26 23:55:29223
224 channel_listener.Init(&chan);
225
[email protected]df3c1ca12008-12-19 21:37:01226 base::ProcessHandle process_handle = SpawnChild(TEST_CLIENT, &chan);
initial.commit09911bf2008-07-26 23:55:29227 ASSERT_TRUE(process_handle);
228
229 Send(&chan, "hello from parent");
230
[email protected]3d1b6662009-01-29 17:03:11231 // Run message loop.
initial.commit09911bf2008-07-26 23:55:29232 MessageLoop::current()->Run();
233
[email protected]3d1b6662009-01-29 17:03:11234 // Close Channel so client gets its OnChannelError() callback fired.
235 chan.Close();
236
237 // Cleanup child process.
[email protected]95cb7fb92008-12-09 22:00:47238 EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 5000));
[email protected]cd4fd152009-02-09 19:28:41239 base::CloseProcessHandle(process_handle);
initial.commit09911bf2008-07-26 23:55:29240}
241
[email protected]95cb7fb92008-12-09 22:00:47242TEST_F(IPCChannelTest, ChannelProxyTest) {
[email protected]c2f10ed2009-02-10 00:52:57243 MyChannelListener channel_listener;
244
initial.commit09911bf2008-07-26 23:55:29245 // The thread needs to out-live the ChannelProxy.
[email protected]ab820df2008-08-26 05:55:10246 base::Thread thread("ChannelProxyTestServer");
247 base::Thread::Options options;
248 options.message_loop_type = MessageLoop::TYPE_IO;
249 thread.StartWithOptions(options);
initial.commit09911bf2008-07-26 23:55:29250 {
251 // setup IPC channel proxy
252 IPC::ChannelProxy chan(kTestClientChannel, IPC::Channel::MODE_SERVER,
253 &channel_listener, NULL, thread.message_loop());
254
255 channel_listener.Init(&chan);
256
[email protected]e74488c2008-12-22 22:43:41257#if defined(OS_WIN)
[email protected]bb975362009-01-21 01:00:22258 base::ProcessHandle process_handle = SpawnChild(TEST_CLIENT, NULL);
[email protected]e74488c2008-12-22 22:43:41259#elif defined(OS_POSIX)
[email protected]bb975362009-01-21 01:00:22260 bool debug_on_start = CommandLine::ForCurrentProcess()->HasSwitch(
261 switches::kDebugChildren);
[email protected]e74488c2008-12-22 22:43:41262 base::file_handle_mapping_vector fds_to_map;
[email protected]cc8f1462009-06-12 17:36:55263 const int ipcfd = chan.GetClientFileDescriptor();
264 if (ipcfd > -1) {
[email protected]b7243c42010-07-23 05:23:13265 fds_to_map.push_back(std::pair<int, int>(ipcfd, kPrimaryIPCChannel + 3));
[email protected]e74488c2008-12-22 22:43:41266 }
267
[email protected]df3c1ca12008-12-19 21:37:01268 base::ProcessHandle process_handle = MultiProcessTest::SpawnChild(
[email protected]d420c31e2010-07-30 02:14:22269 "RunTestClient",
[email protected]e74488c2008-12-22 22:43:41270 fds_to_map,
[email protected]df3c1ca12008-12-19 21:37:01271 debug_on_start);
[email protected]1db97ce72009-08-21 21:53:54272#endif // defined(OS_POSIX)
[email protected]e74488c2008-12-22 22:43:41273
initial.commit09911bf2008-07-26 23:55:29274 ASSERT_TRUE(process_handle);
275
276 Send(&chan, "hello from parent");
277
278 // run message loop
279 MessageLoop::current()->Run();
280
281 // cleanup child process
[email protected]df3c1ca12008-12-19 21:37:01282 EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 5000));
[email protected]cd4fd152009-02-09 19:28:41283 base::CloseProcessHandle(process_handle);
initial.commit09911bf2008-07-26 23:55:29284 }
285 thread.Stop();
286}
287
[email protected]052fd452009-09-23 17:56:25288class ChannelListenerWithOnConnectedSend : public IPC::Channel::Listener {
289 public:
290 virtual void OnChannelConnected(int32 peer_pid) {
291 SendNextMessage();
292 }
293
294 virtual void OnMessageReceived(const IPC::Message& message) {
295 IPC::MessageIterator iter(message);
296
297 iter.NextInt();
298 const std::string data = iter.NextString();
299 const std::string big_string = iter.NextString();
300 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length());
301 SendNextMessage();
302 }
303
304 virtual void OnChannelError() {
305 // There is a race when closing the channel so the last message may be lost.
306 EXPECT_LE(messages_left_, 1);
307 MessageLoop::current()->Quit();
308 }
309
310 void Init(IPC::Message::Sender* s) {
311 sender_ = s;
312 messages_left_ = 50;
313 }
314
315 private:
316 void SendNextMessage() {
317 if (--messages_left_ == 0) {
318 MessageLoop::current()->Quit();
319 } else {
320 Send(sender_, "Foo");
321 }
322 }
323
324 IPC::Message::Sender* sender_;
325 int messages_left_;
326};
327
328TEST_F(IPCChannelTest, SendMessageInChannelConnected) {
329 // This tests the case of a listener sending back an event in it's
330 // OnChannelConnected handler.
331
332 ChannelListenerWithOnConnectedSend channel_listener;
333 // Setup IPC channel.
334 IPC::Channel channel(kTestClientChannel, IPC::Channel::MODE_SERVER,
335 &channel_listener);
336 channel_listener.Init(&channel);
[email protected]39703fb2010-10-19 19:11:15337 ASSERT_TRUE(channel.Connect());
[email protected]052fd452009-09-23 17:56:25338
339 base::ProcessHandle process_handle = SpawnChild(TEST_CLIENT, &channel);
340 ASSERT_TRUE(process_handle);
341
342 Send(&channel, "hello from parent");
343
344 // Run message loop.
345 MessageLoop::current()->Run();
346
347 // Close Channel so client gets its OnChannelError() callback fired.
348 channel.Close();
349
350 // Cleanup child process.
351 EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 5000));
352 base::CloseProcessHandle(process_handle);
353}
354
[email protected]95cb7fb92008-12-09 22:00:47355MULTIPROCESS_TEST_MAIN(RunTestClient) {
356 MessageLoopForIO main_message_loop;
[email protected]c2f10ed2009-02-10 00:52:57357 MyChannelListener channel_listener;
[email protected]95cb7fb92008-12-09 22:00:47358
initial.commit09911bf2008-07-26 23:55:29359 // setup IPC channel
360 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_CLIENT,
361 &channel_listener);
[email protected]39703fb2010-10-19 19:11:15362 CHECK(chan.Connect());
initial.commit09911bf2008-07-26 23:55:29363 channel_listener.Init(&chan);
364 Send(&chan, "hello from child");
365 // run message loop
366 MessageLoop::current()->Run();
[email protected]95cb7fb92008-12-09 22:00:47367 // return true;
368 return NULL;
initial.commit09911bf2008-07-26 23:55:29369}
[email protected]526776c2009-02-07 00:39:26370
initial.commit09911bf2008-07-26 23:55:29371#endif // !PERFORMANCE_TEST
372
373#ifdef PERFORMANCE_TEST
374
375//-----------------------------------------------------------------------------
376// Manually performance test
377//
378// This test times the roundtrip IPC message cycle. It is enabled with a
379// special preprocessor define to enable it instead of the standard IPC
380// unit tests. This works around some funny termination conditions in the
381// regular unit tests.
382//
383// This test is not automated. To test, you will want to vary the message
384// count and message size in TEST to get the numbers you want.
385//
386// FIXME(brettw): Automate this test and have it run by default.
387
388// This channel listener just replies to all messages with the exact same
389// message. It assumes each message has one string parameter. When the string
390// "quit" is sent, it will exit.
391class ChannelReflectorListener : public IPC::Channel::Listener {
392 public:
[email protected]95cb7fb92008-12-09 22:00:47393 explicit ChannelReflectorListener(IPC::Channel *channel) :
initial.commit09911bf2008-07-26 23:55:29394 channel_(channel),
395 count_messages_(0),
396 latency_messages_(0) {
397 std::cout << "Reflector up" << std::endl;
398 }
399
400 ~ChannelReflectorListener() {
401 std::cout << "Client Messages: " << count_messages_ << std::endl;
402 std::cout << "Client Latency: " << latency_messages_ << std::endl;
403 }
404
405 virtual void OnMessageReceived(const IPC::Message& message) {
406 count_messages_++;
407 IPC::MessageIterator iter(message);
408 int time = iter.NextInt();
409 int msgid = iter.NextInt();
410 std::string payload = iter.NextString();
411 latency_messages_ += GetTickCount() - time;
412
413 // cout << "reflector msg received: " << msgid << endl;
414 if (payload == "quit")
415 MessageLoop::current()->Quit();
416
417 IPC::Message* msg = new IPC::Message(0,
418 2,
419 IPC::Message::PRIORITY_NORMAL);
420 msg->WriteInt(GetTickCount());
421 msg->WriteInt(msgid);
422 msg->WriteString(payload);
423 channel_->Send(msg);
424 }
425 private:
426 IPC::Channel *channel_;
427 int count_messages_;
428 int latency_messages_;
429};
430
431class ChannelPerfListener : public IPC::Channel::Listener {
432 public:
433 ChannelPerfListener(IPC::Channel* channel, int msg_count, int msg_size) :
434 count_down_(msg_count),
435 channel_(channel),
436 count_messages_(0),
437 latency_messages_(0) {
438 payload_.resize(msg_size);
439 for (int i = 0; i < static_cast<int>(payload_.size()); i++)
440 payload_[i] = 'a';
441 std::cout << "perflistener up" << std::endl;
442 }
443
444 ~ChannelPerfListener() {
445 std::cout << "Server Messages: " << count_messages_ << std::endl;
446 std::cout << "Server Latency: " << latency_messages_ << std::endl;
447 }
448
449 virtual void OnMessageReceived(const IPC::Message& message) {
450 count_messages_++;
451 // decode the string so this gets counted in the total time
452 IPC::MessageIterator iter(message);
453 int time = iter.NextInt();
454 int msgid = iter.NextInt();
455 std::string cur = iter.NextString();
456 latency_messages_ += GetTickCount() - time;
457
458 // cout << "perflistener got message" << endl;
459
460 count_down_--;
461 if (count_down_ == 0) {
462 IPC::Message* msg = new IPC::Message(0,
463 2,
464 IPC::Message::PRIORITY_NORMAL);
465 msg->WriteInt(GetTickCount());
466 msg->WriteInt(count_down_);
467 msg->WriteString("quit");
468 channel_->Send(msg);
469 SetTimer(NULL, 1, 250, (TIMERPROC) PostQuitMessage);
470 return;
471 }
472
473 IPC::Message* msg = new IPC::Message(0,
474 2,
475 IPC::Message::PRIORITY_NORMAL);
476 msg->WriteInt(GetTickCount());
477 msg->WriteInt(count_down_);
478 msg->WriteString(payload_);
479 channel_->Send(msg);
480 }
481
482 private:
483 int count_down_;
484 std::string payload_;
485 IPC::Channel *channel_;
486 int count_messages_;
487 int latency_messages_;
488};
489
[email protected]95cb7fb92008-12-09 22:00:47490TEST_F(IPCChannelTest, Performance) {
initial.commit09911bf2008-07-26 23:55:29491 // setup IPC channel
492 IPC::Channel chan(kReflectorChannel, IPC::Channel::MODE_SERVER, NULL);
493 ChannelPerfListener perf_listener(&chan, 10000, 100000);
494 chan.set_listener(&perf_listener);
[email protected]39703fb2010-10-19 19:11:15495 ASSERT_TRUE(chan.Connect());
initial.commit09911bf2008-07-26 23:55:29496
[email protected]df3c1ca12008-12-19 21:37:01497 HANDLE process = SpawnChild(TEST_REFLECTOR, &chan);
initial.commit09911bf2008-07-26 23:55:29498 ASSERT_TRUE(process);
499
[email protected]ec7690f2009-04-28 00:11:27500 PlatformThread::Sleep(1000);
initial.commit09911bf2008-07-26 23:55:29501
502 PerfTimeLogger logger("IPC_Perf");
503
504 // this initial message will kick-start the ping-pong of messages
505 IPC::Message* message = new IPC::Message(0,
506 2,
507 IPC::Message::PRIORITY_NORMAL);
508 message->WriteInt(GetTickCount());
509 message->WriteInt(-1);
510 message->WriteString("Hello");
511 chan.Send(message);
512
513 // run message loop
514 MessageLoop::current()->Run();
515
516 // cleanup child process
517 WaitForSingleObject(process, 5000);
518 CloseHandle(process);
519}
520
521// This message loop bounces all messages back to the sender
[email protected]95cb7fb92008-12-09 22:00:47522MULTIPROCESS_TEST_MAIN(RunReflector) {
523 MessageLoopForIO main_message_loop;
initial.commit09911bf2008-07-26 23:55:29524 IPC::Channel chan(kReflectorChannel, IPC::Channel::MODE_CLIENT, NULL);
525 ChannelReflectorListener channel_reflector_listener(&chan);
526 chan.set_listener(&channel_reflector_listener);
[email protected]39703fb2010-10-19 19:11:15527 ASSERT_TRUE(chan.Connect());
initial.commit09911bf2008-07-26 23:55:29528
529 MessageLoop::current()->Run();
530 return true;
531}
532
533#endif // PERFORMANCE_TEST
534
initial.commit09911bf2008-07-26 23:55:29535int main(int argc, char** argv) {
[email protected]95cb7fb92008-12-09 22:00:47536#ifdef PERFORMANCE_TEST
[email protected]99cc51e2010-10-10 00:21:35537 int retval = base::PerfTestSuite(argc, argv).Run();
[email protected]302831b2009-01-13 22:35:10538#else
[email protected]20e14912010-08-17 19:40:11539 int retval = base::TestSuite(argc, argv).Run();
initial.commit09911bf2008-07-26 23:55:29540#endif
[email protected]95cb7fb92008-12-09 22:00:47541 return retval;
initial.commit09911bf2008-07-26 23:55:29542}