OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (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 |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #ifndef CRASHPAD_TEST_WIN_WIN_MULTIPROCESS_H_ |
| 16 #define CRASHPAD_TEST_WIN_WIN_MULTIPROCESS_H_ |
| 17 |
| 18 #include <windows.h> |
| 19 |
| 20 #include "base/basictypes.h" |
| 21 #include "util/file/file_io.h" |
| 22 #include "util/win/scoped_handle.h" |
| 23 |
| 24 namespace crashpad { |
| 25 namespace test { |
| 26 |
| 27 //! \brief Manages a multiprocess test on Windows. |
| 28 class WinMultiprocess { |
| 29 public: |
| 30 WinMultiprocess(); |
| 31 |
| 32 //! \brief Runs the test. |
| 33 //! |
| 34 //! This method establishes the testing environment by respawning the process |
| 35 //! as a child with additional flags. |
| 36 //! |
| 37 //! In the parent process, WinMultiprocessParent() is run, and in the child |
| 38 //! WinMultiprocessChild(). |
| 39 void Run(); |
| 40 |
| 41 protected: |
| 42 virtual ~WinMultiprocess(); |
| 43 |
| 44 //! \brief Returns the read pipe's file handle. |
| 45 //! |
| 46 //! This method may be called by either the parent or the child process. |
| 47 //! Anything written to the write pipe in the partner process will appear |
| 48 //! on this file handle in this process. |
| 49 //! |
| 50 //! It is an error to call this after CloseReadPipe() has been called. |
| 51 //! |
| 52 //! \return The read pipe's file handle. |
| 53 FileHandle ReadPipeHandle() const; |
| 54 |
| 55 //! \brief Returns the write pipe's file handle. |
| 56 //! |
| 57 //! This method may be called by either the parent or the child process. |
| 58 //! Anything written to this file handle in this process will appear on |
| 59 //! the read pipe in the partner process. |
| 60 //! |
| 61 //! It is an error to call this after CloseWritePipe() has been called. |
| 62 //! |
| 63 //! \return The write pipe's file handle. |
| 64 FileHandle WritePipeHandle() const; |
| 65 |
| 66 //! \brief Closes the read pipe. |
| 67 //! |
| 68 //! This method may be called by either the parent or the child process. |
| 69 //! ReadPipeHandle() must not be called after this. |
| 70 void CloseReadPipe(); |
| 71 |
| 72 //! \brief Closes the write pipe. |
| 73 //! |
| 74 //! This method may be called by either the parent or the child process. An |
| 75 //! attempt to read from the read pipe in the partner process will indicate |
| 76 //! end-of-file. WritePipeHandle() must not be called after this. |
| 77 void CloseWritePipe(); |
| 78 |
| 79 //! \brief Returns a handle to the child process. |
| 80 //! |
| 81 //! This method may only be called by the parent process. |
| 82 HANDLE ChildProcess() const; |
| 83 |
| 84 private: |
| 85 //! \brief The subclass-provided parent routine. |
| 86 //! |
| 87 //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`, |
| 88 //! `FAIL()`, etc. |
| 89 //! |
| 90 //! This method must not use `WaitForSingleObject()`-family call to wait for |
| 91 //! the child process to exit, as this is handled by this class. |
| 92 //! |
| 93 //! Subclasses must implement this method to define how the parent operates. |
| 94 virtual void WinMultiprocessParent() = 0; |
| 95 |
| 96 //! \brief The subclass-provided child routine. |
| 97 //! |
| 98 //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`, |
| 99 //! `FAIL()`, etc. |
| 100 //! |
| 101 //! Subclasses must implement this method to define how the child operates. |
| 102 //! Subclasses may exit with a failure status by using `LOG(FATAL)`, |
| 103 //! `abort()`, or similar. They may exit cleanly by returning from this |
| 104 //! method. |
| 105 virtual void WinMultiprocessChild() = 0; |
| 106 |
| 107 ScopedFileHANDLE pipe_c2p_read_; |
| 108 ScopedFileHANDLE pipe_c2p_write_; |
| 109 ScopedFileHANDLE pipe_p2c_read_; |
| 110 ScopedFileHANDLE pipe_p2c_write_; |
| 111 ScopedKernelHANDLE child_handle_; |
| 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(WinMultiprocess); |
| 114 }; |
| 115 |
| 116 } // namespace test |
| 117 } // namespace crashpad |
| 118 |
| 119 #endif // CRASHPAD_TEST_WIN_WIN_MULTIPROCESS_H_ |
OLD | NEW |