| Index: util/test/multiprocess.h
|
| diff --git a/util/test/mac/mach_multiprocess.h b/util/test/multiprocess.h
|
| similarity index 52%
|
| copy from util/test/mac/mach_multiprocess.h
|
| copy to util/test/multiprocess.h
|
| index d68355462976888be6ae166c4895dc98f4d1a996..80ee8415968fc433d8e8c8c79dd6c2fdef9e6b80 100644
|
| --- a/util/test/mac/mach_multiprocess.h
|
| +++ b/util/test/multiprocess.h
|
| @@ -12,10 +12,9 @@
|
| // See the License for the specific language governing permissions and
|
| // limitations under the License.
|
|
|
| -#ifndef CRASHPAD_UTIL_TEST_MAC_MACH_MULTIPROCESS_H_
|
| -#define CRASHPAD_UTIL_TEST_MAC_MACH_MULTIPROCESS_H_
|
| +#ifndef CRASHPAD_UTIL_TEST_MULTIPROCESS_H_
|
| +#define CRASHPAD_UTIL_TEST_MULTIPROCESS_H_
|
|
|
| -#include <mach/mach.h>
|
| #include <unistd.h>
|
|
|
| #include "base/basictypes.h"
|
| @@ -24,54 +23,58 @@ namespace crashpad {
|
| namespace test {
|
|
|
| namespace internal {
|
| -struct MachMultiprocessInfo;
|
| -} // namespace internal
|
| +struct MultiprocessInfo;
|
| +};
|
|
|
| -//! \brief Manages a Mach-aware multiprocess test.
|
| +//! \brief Manages a multiprocess test.
|
| //!
|
| -//! These tests are `fork()`-based. The parent process has access to the child
|
| -//! process’ task port. The parent and child processes are able to communicate
|
| -//! via Mach IPC, and via a pair of POSIX pipes.
|
| +//! These tests are `fork()`-based. The parent and child processes are able to
|
| +//! communicate via a pair of POSIX pipes.
|
| //!
|
| //! Subclasses are expected to implement the parent and child by overriding the
|
| //! appropriate methods.
|
| -class MachMultiprocess {
|
| +class Multiprocess {
|
| public:
|
| - MachMultiprocess();
|
| + Multiprocess();
|
|
|
| //! \brief Runs the test.
|
| //!
|
| - //! This method establishes the proper testing environment and calls
|
| - //! RunParent() in the parent process and RunChild() in the child process.
|
| + //! This method establishes the proper testing environment by calling
|
| + //! PreFork(), then calls `fork()`. In the parent process, it calls
|
| + //! RunParent(), and in the child process, it calls RunChild().
|
| //!
|
| //! This method uses gtest assertions to validate the testing environment. If
|
| //! the testing environment cannot be set up properly, it is possible that
|
| - //! Parent() or Child() will not be called. In the parent process, this method
|
| - //! also waits for the child process to exit after Parent() returns, and
|
| - //! verifies that it exited cleanly with gtest assertions.
|
| + //! MultiprocessParent() or MultiprocessChild() will not be called. In the
|
| + //! parent process, this method also waits for the child process to exit after
|
| + //! MultiprocessParent() returns, and verifies that it exited cleanly without
|
| + //! raising any gtest assertions.
|
| void Run();
|
|
|
| protected:
|
| - ~MachMultiprocess();
|
| + ~Multiprocess();
|
|
|
| - //! \brief The subclass-provided parent routine.
|
| + //! \brief Establishes the proper testing environment prior to forking.
|
| //!
|
| - //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`,
|
| - //! `FAIL()`, etc.
|
| + //! Subclasses that solely implement a test should not need to override this
|
| + //! method. Subclasses that do not implement tests but instead implement
|
| + //! additional testing features on top of this class may override this method
|
| + //! provided that they call the superclass’ implementation first as follows:
|
| //!
|
| - //! This method must not use a `wait()`-family system call to wait for the
|
| - //! child process to exit, as this is handled by RunParent().
|
| - //!
|
| - //! Subclasses must implement this method to define how the parent operates.
|
| - virtual void Parent() = 0;
|
| -
|
| - //! \brief The subclass-provided child routine.
|
| + //! \code
|
| + //! virtual void PreFork() override {
|
| + //! Multiprocess::PreFork();
|
| + //! if (testing::Test::HasFatalAssertions()) {
|
| + //! return;
|
| + //! }
|
| //!
|
| - //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`,
|
| - //! `FAIL()`, etc.
|
| + //! // Place subclass-specific pre-fork code here.
|
| + //! }
|
| + //! \endcode
|
| //!
|
| - //! Subclasses must implement this method to define how the child operates.
|
| - virtual void Child() = 0;
|
| + //! Subclass implementations may signal failure by raising their own fatal
|
| + //! gtest assertions.
|
| + virtual void PreFork();
|
|
|
| //! \brief Returns the child process’ process ID.
|
| //!
|
| @@ -92,48 +95,46 @@ class MachMultiprocess {
|
| //! the read pipe in the partner process.
|
| int WritePipeFD() const;
|
|
|
| - //! \brief Returns a receive right for the local port.
|
| - //!
|
| - //! This method may be called by either the parent or the child process. It
|
| - //! returns a receive right, with a corresponding send right held in the
|
| - //! opposing process.
|
| - mach_port_t LocalPort() const;
|
| -
|
| - //! \brief Returns a send right for the remote port.
|
| - //!
|
| - //! This method may be called by either the parent or the child process. It
|
| - //! returns a send right, with the corresponding receive right held in the
|
| - //! opposing process.
|
| - mach_port_t RemotePort() const;
|
| -
|
| - //! \brief Returns a send right for the child’s task port.
|
| - //!
|
| - //! This method may only be called by the parent process.
|
| - mach_port_t ChildTask() const;
|
| -
|
| private:
|
| //! \brief Runs the parent side of the test.
|
| //!
|
| - //! This method establishes the parent’s environment, performs the handshake
|
| - //! with the child, calls Parent(), and waits for the child process to exit.
|
| - //! Assuming that the environment can be set up correctly and the child exits
|
| - //! successfully, the test will pass.
|
| + //! This method establishes the parent’s environment and calls
|
| + //! MultiprocessParent().
|
| void RunParent();
|
|
|
| //! \brief Runs the child side of the test.
|
| //!
|
| - //! This method establishes the child’s environment, performs the handshake
|
| - //! with the parent, calls Child(), and exits cleanly. However, if any failure
|
| - //! (via fatal or nonfatal gtest assertion) is detected, the child will exit
|
| - //! with a failure status.
|
| + //! This method establishes the child’s environment, calls
|
| + //! MultiprocessChild(), and exits cleanly. However, if any failure (via fatal
|
| + //! or nonfatal gtest assertion) is detected, the child will exit with a
|
| + //! failure status.
|
| void RunChild();
|
|
|
| - internal::MachMultiprocessInfo* info_;
|
| + //! \brief The subclass-provided parent routine.
|
| + //!
|
| + //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`,
|
| + //! `FAIL()`, etc.
|
| + //!
|
| + //! This method must not use a `wait()`-family system call to wait for the
|
| + //! child process to exit, as this is handled by this class.
|
| + //!
|
| + //! Subclasses must implement this method to define how the parent operates.
|
| + virtual void MultiprocessParent() = 0;
|
| +
|
| + //! \brief The subclass-provided child routine.
|
| + //!
|
| + //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`,
|
| + //! `FAIL()`, etc.
|
| + //!
|
| + //! Subclasses must implement this method to define how the child operates.
|
| + virtual void MultiprocessChild() = 0;
|
| +
|
| + internal::MultiprocessInfo* info_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(MachMultiprocess);
|
| + DISALLOW_COPY_AND_ASSIGN(Multiprocess);
|
| };
|
|
|
| } // namespace test
|
| } // namespace crashpad
|
|
|
| -#endif // CRASHPAD_UTIL_TEST_MAC_MACH_MULTIPROCESS_H_
|
| +#endif // CRASHPAD_UTIL_TEST_MULTIPROCESS_H_
|
|
|