| 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, |
| 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/file_io.h" | 23 #include "util/file/file_io.h" |
| 24 #include "util/test/gtest_death_check.h" |
| 24 | 25 |
| 25 namespace crashpad { | 26 namespace crashpad { |
| 26 namespace test { | 27 namespace test { |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 class TestMultiprocess final : public Multiprocess { | 30 class TestMultiprocess final : public Multiprocess { |
| 30 public: | 31 public: |
| 31 TestMultiprocess() : Multiprocess() {} | 32 TestMultiprocess() : Multiprocess() {} |
| 32 | 33 |
| 33 ~TestMultiprocess() {} | 34 ~TestMultiprocess() {} |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } else if (what_closes_ == kReadAndWriteClose) { | 183 } else if (what_closes_ == kReadAndWriteClose) { |
| 183 CheckedReadFileAtEOF(ReadPipeHandle()); | 184 CheckedReadFileAtEOF(ReadPipeHandle()); |
| 184 char c = '\0'; | 185 char c = '\0'; |
| 185 | 186 |
| 186 // This will raise SIGPIPE. If fatal (the normal case), that will cause | 187 // This will raise SIGPIPE. If fatal (the normal case), that will cause |
| 187 // process termination. If SIGPIPE is being handled somewhere, the write | 188 // process termination. If SIGPIPE is being handled somewhere, the write |
| 188 // will still fail and set errno to EPIPE, and CheckedWriteFile() will | 189 // will still fail and set errno to EPIPE, and CheckedWriteFile() will |
| 189 // abort execution. Regardless of how SIGPIPE is handled, the process will | 190 // abort execution. Regardless of how SIGPIPE is handled, the process will |
| 190 // be terminated. Because the actual termination mechanism is not known, | 191 // be terminated. Because the actual termination mechanism is not known, |
| 191 // no regex can be specified. | 192 // no regex can be specified. |
| 192 EXPECT_DEATH(CheckedWriteFile(WritePipeHandle(), &c, 1), ""); | 193 EXPECT_DEATH_CHECK(CheckedWriteFile(WritePipeHandle(), &c, 1), ""); |
| 193 } | 194 } |
| 194 } | 195 } |
| 195 | 196 |
| 196 void Close() { | 197 void Close() { |
| 197 switch (what_closes_) { | 198 switch (what_closes_) { |
| 198 case kReadCloses: | 199 case kReadCloses: |
| 199 CloseReadPipe(); | 200 CloseReadPipe(); |
| 200 EXPECT_NE(-1, WritePipeHandle()); | 201 EXPECT_NE(-1, WritePipeHandle()); |
| 201 EXPECT_DEATH(ReadPipeHandle(), "fd"); | 202 EXPECT_DEATH_CHECK(ReadPipeHandle(), "fd"); |
| 202 break; | 203 break; |
| 203 case kWriteCloses: | 204 case kWriteCloses: |
| 204 CloseWritePipe(); | 205 CloseWritePipe(); |
| 205 EXPECT_NE(-1, ReadPipeHandle()); | 206 EXPECT_NE(-1, ReadPipeHandle()); |
| 206 EXPECT_DEATH(WritePipeHandle(), "fd"); | 207 EXPECT_DEATH_CHECK(WritePipeHandle(), "fd"); |
| 207 break; | 208 break; |
| 208 case kReadAndWriteClose: | 209 case kReadAndWriteClose: |
| 209 CloseReadPipe(); | 210 CloseReadPipe(); |
| 210 CloseWritePipe(); | 211 CloseWritePipe(); |
| 211 EXPECT_DEATH(ReadPipeHandle(), "fd"); | 212 EXPECT_DEATH_CHECK(ReadPipeHandle(), "fd"); |
| 212 EXPECT_DEATH(WritePipeHandle(), "fd"); | 213 EXPECT_DEATH_CHECK(WritePipeHandle(), "fd"); |
| 213 break; | 214 break; |
| 214 } | 215 } |
| 215 } | 216 } |
| 216 | 217 |
| 217 // Multiprocess: | 218 // Multiprocess: |
| 218 | 219 |
| 219 void MultiprocessParent() override { | 220 void MultiprocessParent() override { |
| 220 ASSERT_NO_FATAL_FAILURE(VerifyInitial()); | 221 ASSERT_NO_FATAL_FAILURE(VerifyInitial()); |
| 221 | 222 |
| 222 if (who_closes_ == kParentCloses) { | 223 if (who_closes_ == kParentCloses) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 TEST(MultiprocessDeathTest, ChildClosesReadAndWritePipe) { | 281 TEST(MultiprocessDeathTest, ChildClosesReadAndWritePipe) { |
| 281 TestMultiprocessClosePipe multiprocess( | 282 TestMultiprocessClosePipe multiprocess( |
| 282 TestMultiprocessClosePipe::kChildCloses, | 283 TestMultiprocessClosePipe::kChildCloses, |
| 283 TestMultiprocessClosePipe::kReadAndWriteClose); | 284 TestMultiprocessClosePipe::kReadAndWriteClose); |
| 284 multiprocess.Run(); | 285 multiprocess.Run(); |
| 285 } | 286 } |
| 286 | 287 |
| 287 } // namespace | 288 } // namespace |
| 288 } // namespace test | 289 } // namespace test |
| 289 } // namespace crashpad | 290 } // namespace crashpad |
| OLD | NEW |