| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 ~TestMultiprocess() {} | 34 ~TestMultiprocess() {} |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 // Multiprocess: | 37 // Multiprocess: |
| 38 | 38 |
| 39 void MultiprocessParent() override { | 39 void MultiprocessParent() override { |
| 40 FileHandle read_handle = ReadPipeHandle(); | 40 FileHandle read_handle = ReadPipeHandle(); |
| 41 char c; | 41 char c; |
| 42 CheckedReadFileExactly(read_handle, &c, 1); | 42 CheckedReadFileExactly(read_handle, &c, 1); |
| 43 EXPECT_EQ('M', c); | 43 EXPECT_EQ(c, 'M'); |
| 44 | 44 |
| 45 pid_t pid; | 45 pid_t pid; |
| 46 CheckedReadFileExactly(read_handle, &pid, sizeof(pid)); | 46 CheckedReadFileExactly(read_handle, &pid, sizeof(pid)); |
| 47 EXPECT_EQ(pid, ChildPID()); | 47 EXPECT_EQ(ChildPID(), pid); |
| 48 | 48 |
| 49 c = 'm'; | 49 c = 'm'; |
| 50 CheckedWriteFile(WritePipeHandle(), &c, 1); | 50 CheckedWriteFile(WritePipeHandle(), &c, 1); |
| 51 | 51 |
| 52 // The child will close its end of the pipe and exit. Make sure that the | 52 // The child will close its end of the pipe and exit. Make sure that the |
| 53 // parent sees EOF. | 53 // parent sees EOF. |
| 54 CheckedReadFileAtEOF(read_handle); | 54 CheckedReadFileAtEOF(read_handle); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void MultiprocessChild() override { | 57 void MultiprocessChild() override { |
| 58 FileHandle write_handle = WritePipeHandle(); | 58 FileHandle write_handle = WritePipeHandle(); |
| 59 | 59 |
| 60 char c = 'M'; | 60 char c = 'M'; |
| 61 CheckedWriteFile(write_handle, &c, 1); | 61 CheckedWriteFile(write_handle, &c, 1); |
| 62 | 62 |
| 63 pid_t pid = getpid(); | 63 pid_t pid = getpid(); |
| 64 CheckedWriteFile(write_handle, &pid, sizeof(pid)); | 64 CheckedWriteFile(write_handle, &pid, sizeof(pid)); |
| 65 | 65 |
| 66 CheckedReadFileExactly(ReadPipeHandle(), &c, 1); | 66 CheckedReadFileExactly(ReadPipeHandle(), &c, 1); |
| 67 EXPECT_EQ('m', c); | 67 EXPECT_EQ(c, 'm'); |
| 68 } | 68 } |
| 69 | 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(TestMultiprocess); | 70 DISALLOW_COPY_AND_ASSIGN(TestMultiprocess); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 TEST(Multiprocess, Multiprocess) { | 73 TEST(Multiprocess, Multiprocess) { |
| 74 TestMultiprocess multiprocess; | 74 TestMultiprocess multiprocess; |
| 75 multiprocess.Run(); | 75 multiprocess.Run(); |
| 76 } | 76 } |
| 77 | 77 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 TestMultiprocessClosePipe(WhoCloses who_closes, WhatCloses what_closes) | 154 TestMultiprocessClosePipe(WhoCloses who_closes, WhatCloses what_closes) |
| 155 : Multiprocess(), | 155 : Multiprocess(), |
| 156 who_closes_(who_closes), | 156 who_closes_(who_closes), |
| 157 what_closes_(what_closes) { | 157 what_closes_(what_closes) { |
| 158 } | 158 } |
| 159 | 159 |
| 160 ~TestMultiprocessClosePipe() {} | 160 ~TestMultiprocessClosePipe() {} |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 void VerifyInitial() { | 163 void VerifyInitial() { |
| 164 ASSERT_NE(-1, ReadPipeHandle()); | 164 ASSERT_NE(ReadPipeHandle(), -1); |
| 165 ASSERT_NE(-1, WritePipeHandle()); | 165 ASSERT_NE(WritePipeHandle(), -1); |
| 166 } | 166 } |
| 167 | 167 |
| 168 // Verifies that the partner process did what it was supposed to do. This must | 168 // Verifies that the partner process did what it was supposed to do. This must |
| 169 // only be called when who_closes_ names the partner process, not this | 169 // only be called when who_closes_ names the partner process, not this |
| 170 // process. | 170 // process. |
| 171 // | 171 // |
| 172 // If the partner was supposed to close its write pipe, the read pipe will be | 172 // If the partner was supposed to close its write pipe, the read pipe will be |
| 173 // checked to ensure that it shows end-of-file. | 173 // checked to ensure that it shows end-of-file. |
| 174 // | 174 // |
| 175 // If the partner was supposed to close its read pipe, the write pipe will be | 175 // If the partner was supposed to close its read pipe, the write pipe will be |
| (...skipping 15 matching lines...) Expand all Loading... |
| 191 // be terminated. Because the actual termination mechanism is not known, | 191 // be terminated. Because the actual termination mechanism is not known, |
| 192 // no regex can be specified. | 192 // no regex can be specified. |
| 193 EXPECT_DEATH_CHECK(CheckedWriteFile(WritePipeHandle(), &c, 1), ""); | 193 EXPECT_DEATH_CHECK(CheckedWriteFile(WritePipeHandle(), &c, 1), ""); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 void Close() { | 197 void Close() { |
| 198 switch (what_closes_) { | 198 switch (what_closes_) { |
| 199 case kReadCloses: | 199 case kReadCloses: |
| 200 CloseReadPipe(); | 200 CloseReadPipe(); |
| 201 EXPECT_NE(-1, WritePipeHandle()); | 201 EXPECT_NE(WritePipeHandle(), -1); |
| 202 EXPECT_DEATH_CHECK(ReadPipeHandle(), "fd"); | 202 EXPECT_DEATH_CHECK(ReadPipeHandle(), "fd"); |
| 203 break; | 203 break; |
| 204 case kWriteCloses: | 204 case kWriteCloses: |
| 205 CloseWritePipe(); | 205 CloseWritePipe(); |
| 206 EXPECT_NE(-1, ReadPipeHandle()); | 206 EXPECT_NE(ReadPipeHandle(), -1); |
| 207 EXPECT_DEATH_CHECK(WritePipeHandle(), "fd"); | 207 EXPECT_DEATH_CHECK(WritePipeHandle(), "fd"); |
| 208 break; | 208 break; |
| 209 case kReadAndWriteClose: | 209 case kReadAndWriteClose: |
| 210 CloseReadPipe(); | 210 CloseReadPipe(); |
| 211 CloseWritePipe(); | 211 CloseWritePipe(); |
| 212 EXPECT_DEATH_CHECK(ReadPipeHandle(), "fd"); | 212 EXPECT_DEATH_CHECK(ReadPipeHandle(), "fd"); |
| 213 EXPECT_DEATH_CHECK(WritePipeHandle(), "fd"); | 213 EXPECT_DEATH_CHECK(WritePipeHandle(), "fd"); |
| 214 break; | 214 break; |
| 215 } | 215 } |
| 216 } | 216 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 TEST(MultiprocessDeathTest, ChildClosesReadAndWritePipe) { | 281 TEST(MultiprocessDeathTest, ChildClosesReadAndWritePipe) { |
| 282 TestMultiprocessClosePipe multiprocess( | 282 TestMultiprocessClosePipe multiprocess( |
| 283 TestMultiprocessClosePipe::kChildCloses, | 283 TestMultiprocessClosePipe::kChildCloses, |
| 284 TestMultiprocessClosePipe::kReadAndWriteClose); | 284 TestMultiprocessClosePipe::kReadAndWriteClose); |
| 285 multiprocess.Run(); | 285 multiprocess.Run(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 } // namespace | 288 } // namespace |
| 289 } // namespace test | 289 } // namespace test |
| 290 } // namespace crashpad | 290 } // namespace crashpad |
| OLD | NEW |