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 #include "ipc/ipc_test_base.h" | 7 #include "ipc/ipc_test_base.h" |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/debug_on_start_win.h" | 10 #include "base/debug/debug_on_start_win.h" |
11 #include "base/process/kill.h" | 11 #include "base/process/kill.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "ipc/ipc_descriptors.h" | 14 #include "ipc/ipc_descriptors.h" |
15 #include "ipc/ipc_switches.h" | |
16 | 15 |
17 #if defined(OS_POSIX) | 16 #if defined(OS_POSIX) |
18 #include "base/posix/global_descriptors.h" | 17 #include "base/posix/global_descriptors.h" |
19 #endif | 18 #endif |
20 | 19 |
21 // static | 20 // static |
22 std::string IPCTestBase::GetChannelName(const std::string& test_client_name) { | 21 std::string IPCTestBase::GetChannelName(const std::string& test_client_name) { |
23 DCHECK(!test_client_name.empty()); | 22 DCHECK(!test_client_name.empty()); |
24 return test_client_name + "__Channel"; | 23 return test_client_name + "__Channel"; |
25 } | 24 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 88 |
90 void IPCTestBase::DestroyChannelProxy() { | 89 void IPCTestBase::DestroyChannelProxy() { |
91 CHECK(channel_proxy_.get()); | 90 CHECK(channel_proxy_.get()); |
92 channel_proxy_.reset(); | 91 channel_proxy_.reset(); |
93 } | 92 } |
94 | 93 |
95 bool IPCTestBase::StartClient() { | 94 bool IPCTestBase::StartClient() { |
96 DCHECK(client_process_ == base::kNullProcessHandle); | 95 DCHECK(client_process_ == base::kNullProcessHandle); |
97 | 96 |
98 std::string test_main = test_client_name_ + "TestClientMain"; | 97 std::string test_main = test_client_name_ + "TestClientMain"; |
99 bool debug_on_start = | |
100 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren); | |
101 | 98 |
102 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
103 client_process_ = SpawnChild(test_main, debug_on_start); | 100 client_process_ = SpawnChild(test_main); |
104 #elif defined(OS_POSIX) | 101 #elif defined(OS_POSIX) |
105 base::FileHandleMappingVector fds_to_map; | 102 base::FileHandleMappingVector fds_to_map; |
106 const int ipcfd = channel_.get() ? channel_->GetClientFileDescriptor() : | 103 const int ipcfd = channel_.get() ? channel_->GetClientFileDescriptor() : |
107 channel_proxy_->GetClientFileDescriptor(); | 104 channel_proxy_->GetClientFileDescriptor(); |
108 if (ipcfd > -1) | 105 if (ipcfd > -1) |
109 fds_to_map.push_back(std::pair<int, int>(ipcfd, | 106 fds_to_map.push_back(std::pair<int, int>(ipcfd, |
110 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 107 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
111 base::LaunchOptions options; | 108 base::LaunchOptions options; |
112 options.fds_to_remap = &fds_to_map; | 109 options.fds_to_remap = &fds_to_map; |
113 client_process_ = SpawnChildWithOptions(test_main, options, debug_on_start); | 110 client_process_ = SpawnChildWithOptions(test_main, options); |
114 #endif | 111 #endif |
115 | 112 |
116 return client_process_ != base::kNullProcessHandle; | 113 return client_process_ != base::kNullProcessHandle; |
117 } | 114 } |
118 | 115 |
119 bool IPCTestBase::WaitForClientShutdown() { | 116 bool IPCTestBase::WaitForClientShutdown() { |
120 DCHECK(client_process_ != base::kNullProcessHandle); | 117 DCHECK(client_process_ != base::kNullProcessHandle); |
121 | 118 |
122 bool rv = base::WaitForSingleProcess(client_process_, | 119 bool rv = base::WaitForSingleProcess(client_process_, |
123 base::TimeDelta::FromSeconds(5)); | 120 base::TimeDelta::FromSeconds(5)); |
124 base::CloseProcessHandle(client_process_); | 121 base::CloseProcessHandle(client_process_); |
125 client_process_ = base::kNullProcessHandle; | 122 client_process_ = base::kNullProcessHandle; |
126 return rv; | 123 return rv; |
127 } | 124 } |
OLD | NEW |