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 //! \brief Sets the expected exit code of the child process. | |
42 //! | |
43 //! The default expected termination code is `EXIT_SUCCESS` (`0`). | |
44 //! | |
45 //! \param[in] code The expected exit status of the child. | |
46 void SetExpectedChildExitCode(unsigned int exit_code); | |
47 | |
48 protected: | |
49 virtual ~WinMultiprocess(); | |
50 | |
51 //! \brief Returns the read pipe's file handle. | |
52 //! | |
53 //! This method may be called by either the parent or the child process. | |
54 //! Anything written to the write pipe in the partner process will appear | |
55 //! on this file handle in this process. | |
56 //! | |
57 //! It is an error to call this after CloseReadPipe() has been called. | |
58 //! | |
59 //! \return The read pipe's file handle. | |
60 FileHandle ReadPipeHandle() const; | |
61 | |
62 //! \brief Returns the write pipe's file handle. | |
63 //! | |
64 //! This method may be called by either the parent or the child process. | |
65 //! Anything written to this file handle in this process will appear on | |
66 //! the read pipe in the partner process. | |
67 //! | |
68 //! It is an error to call this after CloseWritePipe() has been called. | |
69 //! | |
70 //! \return The write pipe's file handle. | |
71 FileHandle WritePipeHandle() const; | |
72 | |
73 //! \brief Closes the read pipe. | |
74 //! | |
75 //! This method may be called by either the parent or the child process. | |
76 //! ReadPipeHandle() must not be called after this. | |
77 void CloseReadPipe(); | |
78 | |
79 //! \brief Closes the write pipe. | |
80 //! | |
81 //! This method may be called by either the parent or the child process. An | |
82 //! attempt to read from the read pipe in the partner process will indicate | |
83 //! end-of-file. WritePipeHandle() must not be called after this. | |
84 void CloseWritePipe(); | |
85 | |
86 //! \brief Returns a handle to the child process. | |
87 //! | |
88 //! This method may only be called by the parent process. | |
89 HANDLE ChildProcess() const; | |
90 | |
91 private: | |
92 //! \brief The subclass-provided parent routine. | |
93 //! | |
94 //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`, | |
95 //! `FAIL()`, etc. | |
96 //! | |
97 //! This method need not use `WaitForSingleObject()`-family call to wait for | |
98 //! the child process to exit, as this is handled by this class. | |
99 //! | |
100 //! Subclasses must implement this method to define how the parent operates. | |
101 virtual void WinMultiprocessParent() = 0; | |
102 | |
103 //! \brief The subclass-provided child routine. | |
104 //! | |
105 //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`, | |
erikwright (departed)
2015/06/01 15:35:17
Is this true? What happens if a child process reco
| |
106 //! `FAIL()`, etc. | |
107 //! | |
108 //! Subclasses must implement this method to define how the child operates. | |
109 //! Subclasses may exit with a failure status by using `LOG(FATAL)`, | |
110 //! `abort()`, or similar. They may exit cleanly by returning from this | |
111 //! method. | |
112 virtual void WinMultiprocessChild() = 0; | |
113 | |
114 ScopedFileHANDLE pipe_c2p_read_; | |
115 ScopedFileHANDLE pipe_c2p_write_; | |
116 ScopedFileHANDLE pipe_p2c_read_; | |
117 ScopedFileHANDLE pipe_p2c_write_; | |
118 ScopedKernelHANDLE child_handle_; | |
119 unsigned int exit_code_; | |
120 | |
121 DISALLOW_COPY_AND_ASSIGN(WinMultiprocess); | |
122 }; | |
123 | |
124 } // namespace test | |
125 } // namespace crashpad | |
126 | |
127 #endif // CRASHPAD_TEST_WIN_WIN_MULTIPROCESS_H_ | |
OLD | NEW |