| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "base/test/test_suite.h" | 25 #include "base/test/test_suite.h" |
| 26 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
| 27 #include "ipc/ipc_descriptors.h" | 27 #include "ipc/ipc_descriptors.h" |
| 28 #include "ipc/ipc_channel.h" | 28 #include "ipc/ipc_channel.h" |
| 29 #include "ipc/ipc_channel_proxy.h" | 29 #include "ipc/ipc_channel_proxy.h" |
| 30 #include "ipc/ipc_message_utils.h" | 30 #include "ipc/ipc_message_utils.h" |
| 31 #include "ipc/ipc_sender.h" | 31 #include "ipc/ipc_sender.h" |
| 32 #include "ipc/ipc_switches.h" | 32 #include "ipc/ipc_switches.h" |
| 33 #include "testing/multiprocess_func_list.h" | 33 #include "testing/multiprocess_func_list.h" |
| 34 | 34 |
| 35 #if defined(OS_POSIX) |
| 36 #include "base/global_descriptors_posix.h" |
| 37 #include "ipc/ipc_descriptors.h" |
| 38 #endif |
| 39 |
| 35 // Define to enable IPC performance testing instead of the regular unit tests | 40 // Define to enable IPC performance testing instead of the regular unit tests |
| 36 // #define PERFORMANCE_TEST | 41 // #define PERFORMANCE_TEST |
| 37 | 42 |
| 38 const char kTestClientChannel[] = "T1"; | 43 const char kTestClientChannel[] = "T1"; |
| 39 const char kReflectorChannel[] = "T2"; | 44 const char kReflectorChannel[] = "T2"; |
| 40 const char kFuzzerChannel[] = "F3"; | 45 const char kFuzzerChannel[] = "F3"; |
| 41 const char kSyncSocketChannel[] = "S4"; | 46 const char kSyncSocketChannel[] = "S4"; |
| 42 | 47 |
| 43 const size_t kLongMessageStringNumBytes = 50000; | 48 const size_t kLongMessageStringNumBytes = 50000; |
| 44 | 49 |
| 45 #ifndef PERFORMANCE_TEST | 50 #ifndef PERFORMANCE_TEST |
| 46 | 51 |
| 52 int MultiProcessTestIPCSetUp() { |
| 53 #if defined(OS_POSIX) |
| 54 base::GlobalDescriptors::GetInstance()->Set(kPrimaryIPCChannel, |
| 55 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); |
| 56 #endif |
| 57 return 0; |
| 58 } |
| 59 |
| 47 void IPCChannelTest::SetUp() { | 60 void IPCChannelTest::SetUp() { |
| 48 MultiProcessTest::SetUp(); | 61 MultiProcessTest::SetUp(); |
| 49 | 62 |
| 50 // Construct a fresh IO Message loop for the duration of each test. | 63 // Construct a fresh IO Message loop for the duration of each test. |
| 51 message_loop_ = new MessageLoopForIO(); | 64 message_loop_ = new MessageLoopForIO(); |
| 52 } | 65 } |
| 53 | 66 |
| 54 void IPCChannelTest::TearDown() { | 67 void IPCChannelTest::TearDown() { |
| 55 delete message_loop_; | 68 delete message_loop_; |
| 56 message_loop_ = NULL; | 69 message_loop_ = NULL; |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 MessageLoop::current()->Run(); | 408 MessageLoop::current()->Run(); |
| 396 | 409 |
| 397 // Close Channel so client gets its OnChannelError() callback fired. | 410 // Close Channel so client gets its OnChannelError() callback fired. |
| 398 channel.Close(); | 411 channel.Close(); |
| 399 | 412 |
| 400 // Cleanup child process. | 413 // Cleanup child process. |
| 401 EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 5000)); | 414 EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 5000)); |
| 402 base::CloseProcessHandle(process_handle); | 415 base::CloseProcessHandle(process_handle); |
| 403 } | 416 } |
| 404 | 417 |
| 405 MULTIPROCESS_TEST_MAIN(RunTestClient) { | 418 MULTIPROCESS_TEST_MAIN(RunTestClient, MultiProcessTestIPCSetUp) { |
| 406 MessageLoopForIO main_message_loop; | 419 MessageLoopForIO main_message_loop; |
| 407 MyChannelListener channel_listener; | 420 MyChannelListener channel_listener; |
| 408 | 421 |
| 409 // setup IPC channel | 422 // setup IPC channel |
| 410 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_CLIENT, | 423 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_CLIENT, |
| 411 &channel_listener); | 424 &channel_listener); |
| 412 CHECK(chan.Connect()); | 425 CHECK(chan.Connect()); |
| 413 channel_listener.Init(&chan); | 426 channel_listener.Init(&chan); |
| 414 Send(&chan, "hello from child"); | 427 Send(&chan, "hello from child"); |
| 415 // run message loop | 428 // run message loop |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 | 578 |
| 566 // run message loop | 579 // run message loop |
| 567 MessageLoop::current()->Run(); | 580 MessageLoop::current()->Run(); |
| 568 | 581 |
| 569 // cleanup child process | 582 // cleanup child process |
| 570 WaitForSingleObject(process, 5000); | 583 WaitForSingleObject(process, 5000); |
| 571 CloseHandle(process); | 584 CloseHandle(process); |
| 572 } | 585 } |
| 573 | 586 |
| 574 // This message loop bounces all messages back to the sender | 587 // This message loop bounces all messages back to the sender |
| 575 MULTIPROCESS_TEST_MAIN(RunReflector) { | 588 MULTIPROCESS_TEST_MAIN(RunReflector, MultiProcessTestIPCSetUp) { |
| 589 #if defined(OS_POSIX) |
| 590 base::GlobalDescriptors::GetInstance()->Set(kPrimaryIPCChannel, |
| 591 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); |
| 592 #endif |
| 576 MessageLoopForIO main_message_loop; | 593 MessageLoopForIO main_message_loop; |
| 577 IPC::Channel chan(kReflectorChannel, IPC::Channel::MODE_CLIENT, NULL); | 594 IPC::Channel chan(kReflectorChannel, IPC::Channel::MODE_CLIENT, NULL); |
| 578 ChannelReflectorListener channel_reflector_listener(&chan); | 595 ChannelReflectorListener channel_reflector_listener(&chan); |
| 579 chan.set_listener(&channel_reflector_listener); | 596 chan.set_listener(&channel_reflector_listener); |
| 580 ASSERT_TRUE(chan.Connect()); | 597 ASSERT_TRUE(chan.Connect()); |
| 581 | 598 |
| 582 MessageLoop::current()->Run(); | 599 MessageLoop::current()->Run(); |
| 583 return true; | 600 return true; |
| 584 } | 601 } |
| 585 | 602 |
| 586 #endif // PERFORMANCE_TEST | 603 #endif // PERFORMANCE_TEST |
| 587 | 604 |
| 588 int main(int argc, char** argv) { | 605 int main(int argc, char** argv) { |
| 589 #ifdef PERFORMANCE_TEST | 606 #ifdef PERFORMANCE_TEST |
| 590 int retval = base::PerfTestSuite(argc, argv).Run(); | 607 int retval = base::PerfTestSuite(argc, argv).Run(); |
| 591 #else | 608 #else |
| 592 int retval = base::TestSuite(argc, argv).Run(); | 609 int retval = base::TestSuite(argc, argv).Run(); |
| 593 #endif | 610 #endif |
| 594 return retval; | 611 return retval; |
| 595 } | 612 } |
| OLD | NEW |