| 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 #ifndef CRASHPAD_UTIL_TEST_MULTIPROCESS_H_ | 15 #ifndef CRASHPAD_UTIL_TEST_MULTIPROCESS_H_ | 
| 16 #define CRASHPAD_UTIL_TEST_MULTIPROCESS_H_ | 16 #define CRASHPAD_UTIL_TEST_MULTIPROCESS_H_ | 
| 17 | 17 | 
| 18 #include <unistd.h> | 18 #include <sys/types.h> | 
| 19 | 19 | 
| 20 #include "base/basictypes.h" | 20 #include "base/basictypes.h" | 
|  | 21 #include "build/build_config.h" | 
|  | 22 #include "util/file/file_io.h" | 
| 21 | 23 | 
| 22 namespace crashpad { | 24 namespace crashpad { | 
| 23 namespace test { | 25 namespace test { | 
| 24 | 26 | 
| 25 namespace internal { | 27 namespace internal { | 
| 26 struct MultiprocessInfo; | 28 struct MultiprocessInfo; | 
| 27 }; | 29 }; | 
| 28 | 30 | 
| 29 //! \brief Manages a multiprocess test. | 31 //! \brief Manages a multiprocess test. | 
| 30 //! | 32 //! | 
| 31 //! These tests are `fork()`-based. The parent and child processes are able to | 33 //! These tests are `fork()`-based. The parent and child processes are able to | 
| 32 //! communicate via a pair of POSIX pipes. | 34 //! communicate via a pair of POSIX pipes. | 
| 33 //! | 35 //! | 
| 34 //! Subclasses are expected to implement the parent and child by overriding the | 36 //! Subclasses are expected to implement the parent and child by overriding the | 
| 35 //! appropriate methods. | 37 //! appropriate methods. | 
|  | 38 //! | 
|  | 39 //! On Windows, this class is only an internal implementation detail of | 
|  | 40 //! MultiprocessExec and all tests must use that class. | 
| 36 class Multiprocess { | 41 class Multiprocess { | 
| 37  public: | 42  public: | 
| 38   //! \brief The termination type for a child process. | 43   //! \brief The termination type for a child process. | 
| 39   enum TerminationReason : bool { | 44   enum TerminationReason : bool { | 
| 40     //! \brief The child terminated normally. | 45     //! \brief The child terminated normally. | 
| 41     //! | 46     //! | 
| 42     //! A normal return happens when a test returns from RunChild(), or for | 47     //! A normal return happens when a test returns from RunChild(), or for | 
| 43     //! tests that `exec()`, returns from `main()`. This also happens for tests | 48     //! tests that `exec()`, returns from `main()`. This also happens for tests | 
| 44     //! that call `exit()` or `_exit()`. | 49     //! that call `exit()` or `_exit()`. | 
| 45     kTerminationNormal = false, | 50     kTerminationNormal = false, | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 96   //!     ASSERT_NO_FATAL_FAILURE(Multiprocess::PreFork()); | 101   //!     ASSERT_NO_FATAL_FAILURE(Multiprocess::PreFork()); | 
| 97   //! | 102   //! | 
| 98   //!     // Place subclass-specific pre-fork code here. | 103   //!     // Place subclass-specific pre-fork code here. | 
| 99   //!   } | 104   //!   } | 
| 100   //! \endcode | 105   //! \endcode | 
| 101   //! | 106   //! | 
| 102   //! Subclass implementations may signal failure by raising their own fatal | 107   //! Subclass implementations may signal failure by raising their own fatal | 
| 103   //! gtest assertions. | 108   //! gtest assertions. | 
| 104   virtual void PreFork(); | 109   virtual void PreFork(); | 
| 105 | 110 | 
|  | 111 #if !defined(OS_WIN) | 
| 106   //! \brief Returns the child process’ process ID. | 112   //! \brief Returns the child process’ process ID. | 
| 107   //! | 113   //! | 
| 108   //! This method may only be called by the parent process. | 114   //! This method may only be called by the parent process. | 
| 109   pid_t ChildPID() const; | 115   pid_t ChildPID() const; | 
|  | 116 #endif  // !OS_WIN | 
| 110 | 117 | 
| 111   //! \brief Returns the read pipe’s file descriptor. | 118   //! \brief Returns the read pipe’s file handle. | 
| 112   //! | 119   //! | 
| 113   //! This method may be called by either the parent or the child process. | 120   //! This method may be called by either the parent or the child process. | 
| 114   //! Anything written to the write pipe in the partner process will appear | 121   //! Anything written to the write pipe in the partner process will appear | 
| 115   //! on the this file descriptor in this process. | 122   //! on this file handle in this process. | 
| 116   //! | 123   //! | 
| 117   //! It is an error to call this after CloseReadPipe() has been called. | 124   //! It is an error to call this after CloseReadPipe() has been called. | 
| 118   //! | 125   //! | 
| 119   //! \return The read pipe’s file descriptor. | 126   //! \return The read pipe’s file handle. | 
| 120   int ReadPipeFD() const; | 127   FileHandle ReadPipeHandle() const; | 
| 121 | 128 | 
| 122   //! \brief Returns the write pipe’s file descriptor. | 129   //! \brief Returns the write pipe’s file handle. | 
| 123   //! | 130   //! | 
| 124   //! This method may be called by either the parent or the child process. | 131   //! This method may be called by either the parent or the child process. | 
| 125   //! Anything written to this file descriptor in this process will appear on | 132   //! Anything written to this file handle in this process will appear on | 
| 126   //! the read pipe in the partner process. | 133   //! the read pipe in the partner process. | 
| 127   //! | 134   //! | 
| 128   //! It is an error to call this after CloseWritePipe() has been called. | 135   //! It is an error to call this after CloseWritePipe() has been called. | 
| 129   //! | 136   //! | 
| 130   //! \return The write pipe’s file descriptor. | 137   //! \return The write pipe’s file handle. | 
| 131   int WritePipeFD() const; | 138   FileHandle WritePipeHandle() const; | 
| 132 | 139 | 
| 133   //! \brief Closes the read pipe. | 140   //! \brief Closes the read pipe. | 
| 134   //! | 141   //! | 
| 135   //! This method may be called by either the parent or the child process. An | 142   //! This method may be called by either the parent or the child process. An | 
| 136   //! attempt to write to the write pipe in the partner process will fail with | 143   //! attempt to write to the write pipe in the partner process will fail with | 
| 137   //! `EPIPE` or `SIGPIPE`. ReadPipeFD() must not be called after this. | 144   //! `EPIPE` or `SIGPIPE`. ReadPipeHandle() must not be called after this. | 
| 138   void CloseReadPipe(); | 145   void CloseReadPipe(); | 
| 139 | 146 | 
| 140   //! \brief Closes the write pipe. | 147   //! \brief Closes the write pipe. | 
| 141   //! | 148   //! | 
| 142   //! This method may be called by either the parent or the child process. An | 149   //! This method may be called by either the parent or the child process. An | 
| 143   //! attempt to read from the read pipe in the partner process will indicate | 150   //! attempt to read from the read pipe in the partner process will indicate | 
| 144   //! end-of-file. WritePipeFD() must not be called after this. | 151   //! end-of-file. WritePipeHandle() must not be called after this. | 
| 145   void CloseWritePipe(); | 152   void CloseWritePipe(); | 
| 146 | 153 | 
|  | 154   void set_info(internal::MultiprocessInfo* info) { info_ = info; } | 
|  | 155   internal::MultiprocessInfo* info() const { return info_; } | 
|  | 156 | 
| 147  private: | 157  private: | 
| 148   //! \brief Runs the parent side of the test. | 158   //! \brief Runs the parent side of the test. | 
| 149   //! | 159   //! | 
| 150   //! This method establishes the parent’s environment and calls | 160   //! This method establishes the parent’s environment and calls | 
| 151   //! MultiprocessParent(). | 161   //! MultiprocessParent(). | 
| 152   void RunParent(); | 162   void RunParent(); | 
| 153 | 163 | 
| 154   //! \brief Runs the child side of the test. | 164   //! \brief Runs the child side of the test. | 
| 155   //! | 165   //! | 
| 156   //! This method establishes the child’s environment, calls | 166   //! This method establishes the child’s environment, calls | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 182   int code_; | 192   int code_; | 
| 183   TerminationReason reason_; | 193   TerminationReason reason_; | 
| 184 | 194 | 
| 185   DISALLOW_COPY_AND_ASSIGN(Multiprocess); | 195   DISALLOW_COPY_AND_ASSIGN(Multiprocess); | 
| 186 }; | 196 }; | 
| 187 | 197 | 
| 188 }  // namespace test | 198 }  // namespace test | 
| 189 }  // namespace crashpad | 199 }  // namespace crashpad | 
| 190 | 200 | 
| 191 #endif  // CRASHPAD_UTIL_TEST_MULTIPROCESS_H_ | 201 #endif  // CRASHPAD_UTIL_TEST_MULTIPROCESS_H_ | 
| OLD | NEW | 
|---|