| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 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_TEST_WIN_CHILD_LAUNCHER_H_ | 15 #ifndef CRASHPAD_TEST_WIN_CHILD_LAUNCHER_H_ |
| 16 #define CRASHPAD_TEST_WIN_CHILD_LAUNCHER_H_ | 16 #define CRASHPAD_TEST_WIN_CHILD_LAUNCHER_H_ |
| 17 | 17 |
| 18 #include <windows.h> | 18 #include <windows.h> |
| 19 | 19 |
| 20 #include <string> | 20 #include <string> |
| 21 | 21 |
| 22 #include "util/win/scoped_handle.h" | 22 #include "util/win/scoped_handle.h" |
| 23 | 23 |
| 24 namespace crashpad { | 24 namespace crashpad { |
| 25 namespace test { | 25 namespace test { |
| 26 | 26 |
| 27 //! \brief Creates a child process for testing. Uses gtest `ASSERT_*` to | 27 //! \brief Creates a child process for testing. Uses gtest `ASSERT_*` to |
| 28 //! indicate failure. The child's output is passed through a pipe and is | 28 //! indicate failure. The child's output is passed through a pipe and is |
| 29 //! available via stdout_read_handle(). | 29 //! available via stdout_read_handle(), and the child's input is attached to |
| 30 //! a second pipe available via stdin_write_handle(). |
| 30 class ChildLauncher { | 31 class ChildLauncher { |
| 31 public: | 32 public: |
| 32 //! \brief Creates the object. \a executable will be escaped and prepended to | 33 //! \brief Creates the object. \a executable will be escaped and prepended to |
| 33 //! \a command_line to build the command line of the child. | 34 //! \a command_line to build the command line of the child. |
| 34 ChildLauncher(const std::wstring& executable, | 35 ChildLauncher(const std::wstring& executable, |
| 35 const std::wstring& command_line); | 36 const std::wstring& command_line); |
| 36 | 37 |
| 37 ~ChildLauncher(); | 38 ~ChildLauncher(); |
| 38 | 39 |
| 39 //! \brief Starts the child process, after which the handle functions below | 40 //! \brief Starts the child process, after which the handle functions below |
| 40 //! will be valid. | 41 //! will be valid. |
| 41 void Start(); | 42 void Start(); |
| 42 | 43 |
| 44 //! \brief Waits for the child process to exit. |
| 45 //! |
| 46 //! \return The process exit code. |
| 47 DWORD WaitForExit(); |
| 48 |
| 43 //! \brief The child process's `HANDLE`. | 49 //! \brief The child process's `HANDLE`. |
| 44 HANDLE process_handle() const { return process_handle_.get(); } | 50 HANDLE process_handle() const { return process_handle_.get(); } |
| 45 | 51 |
| 46 //! \brief The child process's main thread's `HANDLE`. | 52 //! \brief The child process's main thread's `HANDLE`. |
| 47 HANDLE main_thread_handle() const { return main_thread_handle_.get(); } | 53 HANDLE main_thread_handle() const { return main_thread_handle_.get(); } |
| 48 | 54 |
| 49 //! \brief The read end of a pipe attached to the child's stdout. | 55 //! \brief The read end of a pipe attached to the child's stdout. |
| 50 HANDLE stdout_read_handle() const { return stdout_read_handle_.get(); } | 56 HANDLE stdout_read_handle() const { return stdout_read_handle_.get(); } |
| 51 | 57 |
| 58 //! \brief The write end of a pipe attached to the child's stdin. |
| 59 HANDLE stdin_write_handle() const { return stdin_write_handle_.get(); } |
| 60 |
| 52 private: | 61 private: |
| 53 std::wstring executable_; | 62 std::wstring executable_; |
| 54 std::wstring command_line_; | 63 std::wstring command_line_; |
| 55 ScopedKernelHANDLE process_handle_; | 64 ScopedKernelHANDLE process_handle_; |
| 56 ScopedKernelHANDLE main_thread_handle_; | 65 ScopedKernelHANDLE main_thread_handle_; |
| 57 ScopedFileHANDLE stdout_read_handle_; | 66 ScopedFileHANDLE stdout_read_handle_; |
| 67 ScopedFileHANDLE stdin_write_handle_; |
| 58 }; | 68 }; |
| 59 | 69 |
| 60 //! \brief Utility function for building escaped command lines. | 70 //! \brief Utility function for building escaped command lines. |
| 61 //! | 71 //! |
| 62 //! \param[in] argument Appended to \a command_line surrounded by properly | 72 //! \param[in] argument Appended to \a command_line surrounded by properly |
| 63 //! escaped quotation marks, if necessary. | 73 //! escaped quotation marks, if necessary. |
| 64 //! \param[inout] command_line The command line being constructed. | 74 //! \param[inout] command_line The command line being constructed. |
| 65 void AppendCommandLineArgument(const std::wstring& argument, | 75 void AppendCommandLineArgument(const std::wstring& argument, |
| 66 std::wstring* command_line); | 76 std::wstring* command_line); |
| 67 | 77 |
| 68 } // namespace test | 78 } // namespace test |
| 69 } // namespace crashpad | 79 } // namespace crashpad |
| 70 | 80 |
| 71 #endif // CRASHPAD_TEST_WIN_CHILD_LAUNCHER_H_ | 81 #endif // CRASHPAD_TEST_WIN_CHILD_LAUNCHER_H_ |
| OLD | NEW |