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

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

Issue 880763002: Reorganize Multiprocess and implement for Windows (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: fixes 2 Created 5 years, 10 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_posix.cc ('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,
(...skipping 18 matching lines...) Expand all
29 class TestMultiprocess final : public Multiprocess { 29 class TestMultiprocess final : public Multiprocess {
30 public: 30 public:
31 TestMultiprocess() : Multiprocess() {} 31 TestMultiprocess() : Multiprocess() {}
32 32
33 ~TestMultiprocess() {} 33 ~TestMultiprocess() {}
34 34
35 private: 35 private:
36 // Multiprocess: 36 // Multiprocess:
37 37
38 void MultiprocessParent() override { 38 void MultiprocessParent() override {
39 int read_fd = ReadPipeFD(); 39 FileHandle read_handle = ReadPipeHandle();
40 char c; 40 char c;
41 CheckedReadFile(read_fd, &c, 1); 41 CheckedReadFile(read_handle, &c, 1);
42 EXPECT_EQ('M', c); 42 EXPECT_EQ('M', c);
43 43
44 pid_t pid; 44 pid_t pid;
45 CheckedReadFile(read_fd, &pid, sizeof(pid)); 45 CheckedReadFile(read_handle, &pid, sizeof(pid));
46 EXPECT_EQ(pid, ChildPID()); 46 EXPECT_EQ(pid, ChildPID());
47 47
48 c = 'm'; 48 c = 'm';
49 CheckedWriteFile(WritePipeFD(), &c, 1); 49 CheckedWriteFile(WritePipeHandle(), &c, 1);
50 50
51 // The child will close its end of the pipe and exit. Make sure that the 51 // The child will close its end of the pipe and exit. Make sure that the
52 // parent sees EOF. 52 // parent sees EOF.
53 CheckedReadFileAtEOF(read_fd); 53 CheckedReadFileAtEOF(read_handle);
54 } 54 }
55 55
56 void MultiprocessChild() override { 56 void MultiprocessChild() override {
57 int write_fd = WritePipeFD(); 57 FileHandle write_handle = WritePipeHandle();
58 58
59 char c = 'M'; 59 char c = 'M';
60 CheckedWriteFile(write_fd, &c, 1); 60 CheckedWriteFile(write_handle, &c, 1);
61 61
62 pid_t pid = getpid(); 62 pid_t pid = getpid();
63 CheckedWriteFile(write_fd, &pid, sizeof(pid)); 63 CheckedWriteFile(write_handle, &pid, sizeof(pid));
64 64
65 CheckedReadFile(ReadPipeFD(), &c, 1); 65 CheckedReadFile(ReadPipeHandle(), &c, 1);
66 EXPECT_EQ('m', c); 66 EXPECT_EQ('m', c);
67 } 67 }
68 68
69 DISALLOW_COPY_AND_ASSIGN(TestMultiprocess); 69 DISALLOW_COPY_AND_ASSIGN(TestMultiprocess);
70 }; 70 };
71 71
72 TEST(Multiprocess, Multiprocess) { 72 TEST(Multiprocess, Multiprocess) {
73 TestMultiprocess multiprocess; 73 TestMultiprocess multiprocess;
74 multiprocess.Run(); 74 multiprocess.Run();
75 } 75 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 TestMultiprocessClosePipe(WhoCloses who_closes, WhatCloses what_closes) 153 TestMultiprocessClosePipe(WhoCloses who_closes, WhatCloses what_closes)
154 : Multiprocess(), 154 : Multiprocess(),
155 who_closes_(who_closes), 155 who_closes_(who_closes),
156 what_closes_(what_closes) { 156 what_closes_(what_closes) {
157 } 157 }
158 158
159 ~TestMultiprocessClosePipe() {} 159 ~TestMultiprocessClosePipe() {}
160 160
161 private: 161 private:
162 void VerifyInitial() { 162 void VerifyInitial() {
163 ASSERT_NE(-1, ReadPipeFD()); 163 ASSERT_NE(-1, ReadPipeHandle());
164 ASSERT_NE(-1, WritePipeFD()); 164 ASSERT_NE(-1, WritePipeHandle());
165 } 165 }
166 166
167 // Verifies that the partner process did what it was supposed to do. This must 167 // Verifies that the partner process did what it was supposed to do. This must
168 // only be called when who_closes_ names the partner process, not this 168 // only be called when who_closes_ names the partner process, not this
169 // process. 169 // process.
170 // 170 //
171 // If the partner was supposed to close its write pipe, the read pipe will be 171 // If the partner was supposed to close its write pipe, the read pipe will be
172 // checked to ensure that it shows end-of-file. 172 // checked to ensure that it shows end-of-file.
173 // 173 //
174 // If the partner was supposed to close its read pipe, the write pipe will be 174 // If the partner was supposed to close its read pipe, the write pipe will be
175 // checked to ensure that a checked write causes death. This can only be done 175 // checked to ensure that a checked write causes death. This can only be done
176 // if the partner also provides some type of signal when it has closed its 176 // if the partner also provides some type of signal when it has closed its
177 // read pipe, which is done in the form of it closing its write pipe, causing 177 // read pipe, which is done in the form of it closing its write pipe, causing
178 // the read pipe in this process to show end-of-file. 178 // the read pipe in this process to show end-of-file.
179 void VerifyPartner() { 179 void VerifyPartner() {
180 if (what_closes_ == kWriteCloses) { 180 if (what_closes_ == kWriteCloses) {
181 CheckedReadFileAtEOF(ReadPipeFD()); 181 CheckedReadFileAtEOF(ReadPipeHandle());
182 } else if (what_closes_ == kReadAndWriteClose) { 182 } else if (what_closes_ == kReadAndWriteClose) {
183 CheckedReadFileAtEOF(ReadPipeFD()); 183 CheckedReadFileAtEOF(ReadPipeHandle());
184 char c = '\0'; 184 char c = '\0';
185 185
186 // This will raise SIGPIPE. If fatal (the normal case), that will cause 186 // This will raise SIGPIPE. If fatal (the normal case), that will cause
187 // process termination. If SIGPIPE is being handled somewhere, the write 187 // process termination. If SIGPIPE is being handled somewhere, the write
188 // will still fail and set errno to EPIPE, and CheckedWriteFile() will 188 // will still fail and set errno to EPIPE, and CheckedWriteFile() will
189 // abort execution. Regardless of how SIGPIPE is handled, the process will 189 // abort execution. Regardless of how SIGPIPE is handled, the process will
190 // be terminated. Because the actual termination mechanism is not known, 190 // be terminated. Because the actual termination mechanism is not known,
191 // no regex can be specified. 191 // no regex can be specified.
192 EXPECT_DEATH(CheckedWriteFile(WritePipeFD(), &c, 1), ""); 192 EXPECT_DEATH(CheckedWriteFile(WritePipeHandle(), &c, 1), "");
193 } 193 }
194 } 194 }
195 195
196 void Close() { 196 void Close() {
197 switch (what_closes_) { 197 switch (what_closes_) {
198 case kReadCloses: 198 case kReadCloses:
199 CloseReadPipe(); 199 CloseReadPipe();
200 EXPECT_NE(-1, WritePipeFD()); 200 EXPECT_NE(-1, WritePipeHandle());
201 EXPECT_DEATH(ReadPipeFD(), "fd"); 201 EXPECT_DEATH(ReadPipeHandle(), "fd");
202 break; 202 break;
203 case kWriteCloses: 203 case kWriteCloses:
204 CloseWritePipe(); 204 CloseWritePipe();
205 EXPECT_NE(-1, ReadPipeFD()); 205 EXPECT_NE(-1, ReadPipeHandle());
206 EXPECT_DEATH(WritePipeFD(), "fd"); 206 EXPECT_DEATH(WritePipeHandle(), "fd");
207 break; 207 break;
208 case kReadAndWriteClose: 208 case kReadAndWriteClose:
209 CloseReadPipe(); 209 CloseReadPipe();
210 CloseWritePipe(); 210 CloseWritePipe();
211 EXPECT_DEATH(ReadPipeFD(), "fd"); 211 EXPECT_DEATH(ReadPipeHandle(), "fd");
212 EXPECT_DEATH(WritePipeFD(), "fd"); 212 EXPECT_DEATH(WritePipeHandle(), "fd");
213 break; 213 break;
214 } 214 }
215 } 215 }
216 216
217 // Multiprocess: 217 // Multiprocess:
218 218
219 void MultiprocessParent() override { 219 void MultiprocessParent() override {
220 ASSERT_NO_FATAL_FAILURE(VerifyInitial()); 220 ASSERT_NO_FATAL_FAILURE(VerifyInitial());
221 221
222 if (who_closes_ == kParentCloses) { 222 if (who_closes_ == kParentCloses) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 TEST(MultiprocessDeathTest, ChildClosesReadAndWritePipe) { 280 TEST(MultiprocessDeathTest, ChildClosesReadAndWritePipe) {
281 TestMultiprocessClosePipe multiprocess( 281 TestMultiprocessClosePipe multiprocess(
282 TestMultiprocessClosePipe::kChildCloses, 282 TestMultiprocessClosePipe::kChildCloses,
283 TestMultiprocessClosePipe::kReadAndWriteClose); 283 TestMultiprocessClosePipe::kReadAndWriteClose);
284 multiprocess.Run(); 284 multiprocess.Run();
285 } 285 }
286 286
287 } // namespace 287 } // namespace
288 } // namespace test 288 } // namespace test
289 } // namespace crashpad 289 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/test/multiprocess_posix.cc ('k') | util/test/multiprocess_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698