| 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> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #include <stdio.h> | |
| 15 #include <string> | |
| 16 #include <utility> | 14 #include <utility> |
| 17 | 15 |
| 18 #include "ipc/ipc_test_base.h" | 16 #include "ipc/ipc_test_base.h" |
| 19 | 17 |
| 20 #include "base/base_switches.h" | |
| 21 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 22 #include "base/debug/debug_on_start_win.h" | 19 #include "base/debug/debug_on_start_win.h" |
| 23 #include "base/perftimer.h" | |
| 24 #include "base/pickle.h" | |
| 25 #include "base/test/perf_test_suite.h" | |
| 26 #include "base/test/test_suite.h" | |
| 27 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 28 #include "base/time.h" | 21 #include "base/time.h" |
| 29 #include "ipc/ipc_descriptors.h" | 22 #include "ipc/ipc_descriptors.h" |
| 30 #include "ipc/ipc_channel.h" | 23 #include "ipc/ipc_channel.h" |
| 31 #include "ipc/ipc_channel_proxy.h" | 24 #include "ipc/ipc_channel_proxy.h" |
| 32 #include "ipc/ipc_message_utils.h" | 25 #include "ipc/ipc_message_utils.h" |
| 33 #include "ipc/ipc_multiprocess_test.h" | 26 #include "ipc/ipc_multiprocess_test.h" |
| 34 #include "ipc/ipc_sender.h" | 27 #include "ipc/ipc_sender.h" |
| 35 #include "ipc/ipc_switches.h" | 28 #include "ipc/ipc_switches.h" |
| 36 #include "testing/multiprocess_func_list.h" | 29 #include "testing/multiprocess_func_list.h" |
| 37 | 30 |
| 38 // Define to enable IPC performance testing instead of the regular unit tests | |
| 39 // #define PERFORMANCE_TEST | |
| 40 | |
| 41 const char kTestClientChannel[] = "T1"; | 31 const char kTestClientChannel[] = "T1"; |
| 42 const char kReflectorChannel[] = "T2"; | 32 const char kReflectorChannel[] = "T2"; |
| 43 const char kFuzzerChannel[] = "F3"; | 33 const char kFuzzerChannel[] = "F3"; |
| 44 const char kSyncSocketChannel[] = "S4"; | 34 const char kSyncSocketChannel[] = "S4"; |
| 45 | 35 |
| 46 void IPCTestBase::SetUp() { | 36 void IPCTestBase::SetUp() { |
| 47 MultiProcessTest::SetUp(); | 37 MultiProcessTest::SetUp(); |
| 48 | 38 |
| 49 // Construct a fresh IO Message loop for the duration of each test. | 39 // Construct a fresh IO Message loop for the duration of each test. |
| 50 message_loop_ = new MessageLoopForIO(); | 40 message_loop_ = new MessageLoopForIO(); |
| 51 } | 41 } |
| 52 | 42 |
| 53 void IPCTestBase::TearDown() { | 43 void IPCTestBase::TearDown() { |
| 54 delete message_loop_; | 44 delete message_loop_; |
| 55 message_loop_ = NULL; | 45 message_loop_ = NULL; |
| 56 | 46 |
| 57 MultiProcessTest::TearDown(); | 47 MultiProcessTest::TearDown(); |
| 58 } | 48 } |
| 59 | 49 |
| 60 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 61 base::ProcessHandle IPCTestBase::SpawnChild(IPCTestBase::ChildType child_type, | 51 base::ProcessHandle IPCTestBase::SpawnChild(IPCTestBase::ChildType child_type, |
| 62 IPC::Channel *channel) { | 52 IPC::Channel* channel) { |
| 63 // kDebugChildren support. | 53 // kDebugChildren support. |
| 64 bool debug_on_start = | 54 bool debug_on_start = |
| 65 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren); | 55 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren); |
| 66 | 56 |
| 67 switch (child_type) { | 57 switch (child_type) { |
| 68 case TEST_CLIENT: | 58 case TEST_CLIENT: |
| 69 return MultiProcessTest::SpawnChild("RunTestClient", debug_on_start); | 59 return MultiProcessTest::SpawnChild("RunTestClient", debug_on_start); |
| 70 case TEST_REFLECTOR: | 60 case TEST_REFLECTOR: |
| 71 return MultiProcessTest::SpawnChild("RunReflector", debug_on_start); | 61 return MultiProcessTest::SpawnChild("RunReflector", debug_on_start); |
| 72 case FUZZER_SERVER: | 62 case FUZZER_SERVER: |
| 73 return MultiProcessTest::SpawnChild("RunFuzzServer", debug_on_start); | 63 return MultiProcessTest::SpawnChild("RunFuzzServer", debug_on_start); |
| 74 case SYNC_SOCKET_SERVER: | 64 case SYNC_SOCKET_SERVER: |
| 75 return MultiProcessTest::SpawnChild("RunSyncSocketServer", debug_on_start); | 65 return MultiProcessTest::SpawnChild("RunSyncSocketServer", debug_on_start); |
| 76 default: | 66 default: |
| 77 return NULL; | 67 return NULL; |
| 78 } | 68 } |
| 79 } | 69 } |
| 80 #elif defined(OS_POSIX) | 70 #elif defined(OS_POSIX) |
| 81 base::ProcessHandle IPCTestBase::SpawnChild(IPCTestBase::ChildType child_type, | 71 base::ProcessHandle IPCTestBase::SpawnChild(IPCTestBase::ChildType child_type, |
| 82 IPC::Channel *channel) { | 72 IPC::Channel* channel) { |
| 83 // kDebugChildren support. | 73 // kDebugChildren support. |
| 84 bool debug_on_start = | 74 bool debug_on_start = |
| 85 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren); | 75 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren); |
| 86 | 76 |
| 87 base::FileHandleMappingVector fds_to_map; | 77 base::FileHandleMappingVector fds_to_map; |
| 88 const int ipcfd = channel->GetClientFileDescriptor(); | 78 const int ipcfd = channel->GetClientFileDescriptor(); |
| 89 if (ipcfd > -1) { | 79 if (ipcfd > -1) { |
| 90 fds_to_map.push_back(std::pair<int, int>(ipcfd, kPrimaryIPCChannel + 3)); | 80 fds_to_map.push_back(std::pair<int, int>(ipcfd, kPrimaryIPCChannel + 3)); |
| 91 } | 81 } |
| 92 | 82 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 122 fds_to_map, | 112 fds_to_map, |
| 123 debug_on_start); | 113 debug_on_start); |
| 124 break; | 114 break; |
| 125 default: | 115 default: |
| 126 return base::kNullProcessHandle; | 116 return base::kNullProcessHandle; |
| 127 break; | 117 break; |
| 128 } | 118 } |
| 129 return ret; | 119 return ret; |
| 130 } | 120 } |
| 131 #endif // defined(OS_POSIX) | 121 #endif // defined(OS_POSIX) |
| OLD | NEW |