Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: util/test/mac/mach_multiprocess.h

Issue 482483002: Add MachMultiprocess and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@bootstrap
Patch Set: Further refinements Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | util/test/mac/mach_multiprocess.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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_UTIL_TEST_MAC_MACH_MULTIPROCESS_H_
16 #define CRASHPAD_UTIL_TEST_MAC_MACH_MULTIPROCESS_H_
17
18 #include <mach/mach.h>
19 #include <unistd.h>
20
21 #include "base/basictypes.h"
22
23 namespace crashpad {
24 namespace test {
25
26 namespace internal {
27 struct MachMultiprocessInfo;
28 } // namespace internal
29
30 //! \brief Manages a Mach-aware multiprocess test.
31 //!
32 //! These tests are `fork()`-based. The parent process has access to the child
33 //! process’ task port. The parent and child processes are able to communicate
34 //! via Mach IPC, and the child process can also send messages to the parent
35 //! process via a POSIX pipe.
36 //!
37 //! Subclasses are expected to implement the parent and child by overriding the
38 //! appropriate methods.
39 class MachMultiprocess {
40 public:
41 MachMultiprocess();
42
43 //! \brief Runs the test.
44 //!
45 //! This method establishes the proper testing environment and calls
46 //! RunParent() in the parent process and RunChild() in the child process.
47 //!
48 //! This method uses gtest assertions to validate the testing environment. If
49 //! the testing environment cannot be set up properly, it is possible that
50 //! Parent() or Child() will not be called. In the parent process, this method
51 //! also waits for the child process to exit after Parent() returns, and
52 //! verifies that it exited cleanly with gtest assertions.
53 void Run();
54
55 protected:
56 ~MachMultiprocess();
57
58 //! \brief The subclass-provided parent routine.
59 //!
60 //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`,
61 //! `FAIL()`, etc.
62 //!
63 //! This method must not use a `wait()`-family system call to wait for the
64 //! child process to exit, as this is handled by RunParent().
65 //!
66 //! Subclasses must implement this method to define how the parent operates.
67 virtual void Parent() = 0;
68
69 //! \brief The subclass-provided child routine.
70 //!
71 //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`,
72 //! `FAIL()`, etc.
73 //!
74 //! Subclasses must implement this method to define how the child operates.
75 virtual void Child() = 0;
76
77 //! \brief Returns the child process’ process ID.
78 //!
79 //! This method may only be called by the parent process.
80 pid_t ChildPID() const;
81
82 //! \brief Returns the pipe’s file descriptor.
83 //!
84 //! This method may be called by either the parent or the child process. In
85 //! the parent process, the pipe is read-only, and in the child process, it is
86 //! write-only.
87 int PipeFD() const;
88
89 //! \brief Returns a receive right for the local port.
90 //!
91 //! This method may be called by either the parent or the child process. It
92 //! returns a receive right, with a corresponding send right held in the
93 //! opposing process.
94 mach_port_t LocalPort() const;
95
96 //! \brief Returns a send right for the remote port.
97 //!
98 //! This method may be called by either the parent or the child process. It
99 //! returns a send right, with the corresponding receive right held in the
100 //! opposing process.
101 mach_port_t RemotePort() const;
102
103 //! \brief Returns a send right for the child’s task port.
104 //!
105 //! This method may only be called by the parent process.
106 mach_port_t ChildTask() const;
107
108 private:
109 //! \brief Runs the parent side of the test.
110 //!
111 //! This method establishes the parent’s environment, performs the handshake
112 //! with the child, calls Parent(), and waits for the child process to exit.
113 //! Assuming that the environment can be set up correctly and the child exits
114 //! successfully, the test will pass.
115 void RunParent();
116
117 //! \brief Runs the child side of the test.
118 //!
119 //! This method establishes the child’s environment, performs the handshake
120 //! with the parent, calls Child(), and exits cleanly. However, if any failure
121 //! (via fatal or nonfatal gtest assertion) is detected, the child will exit
122 //! with a failure status.
123 void RunChild();
124
125 internal::MachMultiprocessInfo* info_;
126
127 DISALLOW_COPY_AND_ASSIGN(MachMultiprocess);
128 };
129
130 } // namespace test
131 } // namespace crashpad
132
133 #endif // CRASHPAD_UTIL_TEST_MAC_MACH_MULTIPROCESS_H_
OLDNEW
« no previous file with comments | « no previous file | util/test/mac/mach_multiprocess.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698