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

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

Issue 811823003: Cross platform low level file IO wrappers (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 6 years 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
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 <stdlib.h> 17 #include <stdlib.h>
18 #include <sys/signal.h> 18 #include <sys/signal.h>
19 #include <unistd.h> 19 #include <unistd.h>
20 20
21 #include "base/basictypes.h" 21 #include "base/basictypes.h"
22 #include "gtest/gtest.h" 22 #include "gtest/gtest.h"
23 #include "util/file/fd_io.h" 23 #include "util/file/file_io.h"
24 24
25 namespace crashpad { 25 namespace crashpad {
26 namespace test { 26 namespace test {
27 namespace { 27 namespace {
28 28
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 int read_fd = ReadPipeFD();
40 char c; 40 char c;
41 CheckedReadFD(read_fd, &c, 1); 41 CheckedReadFile(read_fd, &c, 1);
42 EXPECT_EQ('M', c); 42 EXPECT_EQ('M', c);
43 43
44 pid_t pid; 44 pid_t pid;
45 CheckedReadFD(read_fd, &pid, sizeof(pid)); 45 CheckedReadFile(read_fd, &pid, sizeof(pid));
46 EXPECT_EQ(pid, ChildPID()); 46 EXPECT_EQ(pid, ChildPID());
47 47
48 c = 'm'; 48 c = 'm';
49 CheckedWriteFD(WritePipeFD(), &c, 1); 49 CheckedWriteFile(WritePipeFD(), &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 CheckedReadFDAtEOF(read_fd); 53 CheckedReadFileAtEOF(read_fd);
54 } 54 }
55 55
56 void MultiprocessChild() override { 56 void MultiprocessChild() override {
57 int write_fd = WritePipeFD(); 57 int write_fd = WritePipeFD();
58 58
59 char c = 'M'; 59 char c = 'M';
60 CheckedWriteFD(write_fd, &c, 1); 60 CheckedWriteFile(write_fd, &c, 1);
61 61
62 pid_t pid = getpid(); 62 pid_t pid = getpid();
63 CheckedWriteFD(write_fd, &pid, sizeof(pid)); 63 CheckedWriteFile(write_fd, &pid, sizeof(pid));
64 64
65 CheckedReadFD(ReadPipeFD(), &c, 1); 65 CheckedReadFile(ReadPipeFD(), &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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 CheckedReadFDAtEOF(ReadPipeFD()); 181 CheckedReadFileAtEOF(ReadPipeFD());
182 } else if (what_closes_ == kReadAndWriteClose) { 182 } else if (what_closes_ == kReadAndWriteClose) {
183 CheckedReadFDAtEOF(ReadPipeFD()); 183 CheckedReadFileAtEOF(ReadPipeFD());
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 CheckedWriteFD() will abort 188 // will still fail and set errno to EPIPE, and CheckedWriteFile() will
189 // execution. Regardless of how SIGPIPE is handled, the process will be 189 // abort execution. Regardless of how SIGPIPE is handled, the process will
190 // terminated. Because the actual termination mechanism is not known, no 190 // be terminated. Because the actual termination mechanism is not known,
191 // regex can be specified. 191 // no regex can be specified.
192 EXPECT_DEATH(CheckedWriteFD(WritePipeFD(), &c, 1), ""); 192 EXPECT_DEATH(CheckedWriteFile(WritePipeFD(), &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, WritePipeFD());
201 EXPECT_DEATH(ReadPipeFD(), "fd"); 201 EXPECT_DEATH(ReadPipeFD(), "fd");
202 break; 202 break;
(...skipping 77 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
« util/file/file_io.h ('K') | « util/test/multiprocess_exec_test.cc ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698