Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: util/test/multiprocess.cc

Issue 586053002: MachMultiprocess test: the child process must wait for the parent to finish (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Handle it in the base class Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « util/test/multiprocess.h ('k') | util/test/multiprocess_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/test/multiprocess.h" 15 #include "util/test/multiprocess.h"
16 16
17 #include <signal.h> 17 #include <signal.h>
18 #include <stdlib.h> 18 #include <stdlib.h>
19 #include <sys/wait.h> 19 #include <sys/wait.h>
20 20
21 #include <string> 21 #include <string>
22 22
23 #include "base/auto_reset.h" 23 #include "base/auto_reset.h"
24 #include "base/files/scoped_file.h" 24 #include "base/files/scoped_file.h"
25 #include "base/logging.h"
25 #include "base/memory/scoped_ptr.h" 26 #include "base/memory/scoped_ptr.h"
26 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
27 #include "gtest/gtest.h" 28 #include "gtest/gtest.h"
28 #include "util/misc/scoped_forbid_return.h" 29 #include "util/misc/scoped_forbid_return.h"
29 #include "util/test/errors.h" 30 #include "util/test/errors.h"
30 31
31 namespace crashpad { 32 namespace crashpad {
32 namespace test { 33 namespace test {
33 34
34 using namespace testing; 35 using namespace testing;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 message = 107 message =
107 base::StringPrintf("Child terminated by signal %d (%s)%s, expected", 108 base::StringPrintf("Child terminated by signal %d (%s)%s, expected",
108 code, 109 code,
109 strsignal(code), 110 strsignal(code),
110 WCOREDUMP(status) ? " (core dumped)" : ""); 111 WCOREDUMP(status) ? " (core dumped)" : "");
111 } else { 112 } else {
112 FAIL() << "Unknown termination reason"; 113 FAIL() << "Unknown termination reason";
113 } 114 }
114 115
115 if (reason_ == kTerminationNormal) { 116 if (reason_ == kTerminationNormal) {
116 message += base::StringPrintf("exit with code %d", code_); 117 message += base::StringPrintf(" exit with code %d", code_);
117 } else if (reason == kTerminationSignal) { 118 } else if (reason == kTerminationSignal) {
118 message += base::StringPrintf("termination by signal %d", code_); 119 message += base::StringPrintf(" termination by signal %d", code_);
119 } 120 }
120 121
121 if (reason != reason_ || code != code_) { 122 if (reason != reason_ || code != code_) {
122 ADD_FAILURE() << message; 123 ADD_FAILURE() << message;
123 } 124 }
124 } else { 125 } else {
125 RunChild(); 126 RunChild();
126 } 127 }
127 } 128 }
128 129
(...skipping 23 matching lines...) Expand all
152 } 153 }
153 154
154 pid_t Multiprocess::ChildPID() const { 155 pid_t Multiprocess::ChildPID() const {
155 EXPECT_NE(0, info_->child_pid); 156 EXPECT_NE(0, info_->child_pid);
156 return info_->child_pid; 157 return info_->child_pid;
157 } 158 }
158 159
159 int Multiprocess::ReadPipeFD() const { 160 int Multiprocess::ReadPipeFD() const {
160 int fd = info_->child_pid ? info_->pipe_c2p_read.get() 161 int fd = info_->child_pid ? info_->pipe_c2p_read.get()
161 : info_->pipe_p2c_read.get(); 162 : info_->pipe_p2c_read.get();
162 EXPECT_NE(-1, fd); 163 CHECK_NE(fd, -1);
163 return fd; 164 return fd;
164 } 165 }
165 166
166 int Multiprocess::WritePipeFD() const { 167 int Multiprocess::WritePipeFD() const {
167 int fd = info_->child_pid ? info_->pipe_p2c_write.get() 168 int fd = info_->child_pid ? info_->pipe_p2c_write.get()
168 : info_->pipe_c2p_write.get(); 169 : info_->pipe_c2p_write.get();
169 EXPECT_NE(-1, fd); 170 CHECK_NE(fd, -1);
170 return fd; 171 return fd;
171 } 172 }
172 173
174 void Multiprocess::CloseReadPipe() {
175 if (info_->child_pid) {
176 info_->pipe_c2p_read.reset();
177 } else {
178 info_->pipe_p2c_read.reset();
179 }
180 }
181
182 void Multiprocess::CloseWritePipe() {
183 if (info_->child_pid) {
184 info_->pipe_p2c_write.reset();
185 } else {
186 info_->pipe_c2p_write.reset();
187 }
188 }
189
173 void Multiprocess::RunParent() { 190 void Multiprocess::RunParent() {
174 // The parent uses the read end of c2p and the write end of p2c. 191 // The parent uses the read end of c2p and the write end of p2c.
175 info_->pipe_c2p_write.reset(); 192 info_->pipe_c2p_write.reset();
176 info_->pipe_p2c_read.reset(); 193 info_->pipe_p2c_read.reset();
177 194
178 MultiprocessParent(); 195 MultiprocessParent();
179 196
180 info_->pipe_c2p_read.reset(); 197 info_->pipe_c2p_read.reset();
181 info_->pipe_p2c_write.reset(); 198 info_->pipe_p2c_write.reset();
182 } 199 }
(...skipping 13 matching lines...) Expand all
196 if (Test::HasFailure()) { 213 if (Test::HasFailure()) {
197 // Trigger the ScopedForbidReturn destructor. 214 // Trigger the ScopedForbidReturn destructor.
198 return; 215 return;
199 } 216 }
200 217
201 exit(0); 218 exit(0);
202 } 219 }
203 220
204 } // namespace test 221 } // namespace test
205 } // namespace crashpad 222 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/test/multiprocess.h ('k') | util/test/multiprocess_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698