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

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

Issue 1051533002: test: Move util/test to its own top-level directory, test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Rebase Created 5 years, 8 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
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 #include "util/test/multiprocess.h"
23
24 namespace crashpad {
25 namespace test {
26
27 namespace internal {
28 struct MachMultiprocessInfo;
29 } // namespace internal
30
31 //! \brief Manages a Mach-aware multiprocess test.
32 //!
33 //! This is similar to the base Multiprocess test, but adds Mach features. The
34 //! parent process has access to the child process’ task port. The parent and
35 //! child processes are able to communicate via Mach IPC: each process has a
36 //! receive right to its “local port” and a send right to a “remote port”, and
37 //! messages sent to the remote port in one process can be received on the local
38 //! port in the partner process.
39 //!
40 //! Subclasses are expected to implement the parent and child by overriding the
41 //! appropriate methods.
42 class MachMultiprocess : public Multiprocess {
43 public:
44 MachMultiprocess();
45
46 void Run();
47
48 protected:
49 ~MachMultiprocess();
50
51 // Multiprocess:
52 void PreFork() override;
53
54 //! \brief Returns a receive right for the local port.
55 //!
56 //! This method may be called by either the parent or the child process. It
57 //! returns a receive right, with a corresponding send right held in the
58 //! opposing process.
59 mach_port_t LocalPort() const;
60
61 //! \brief Returns a send right for the remote port.
62 //!
63 //! This method may be called by either the parent or the child process. It
64 //! returns a send right, with the corresponding receive right held in the
65 //! opposing process.
66 mach_port_t RemotePort() const;
67
68 //! \brief Returns a send right for the child’s task port.
69 //!
70 //! This method may only be called by the parent process.
71 task_t ChildTask() const;
72
73 private:
74 // Multiprocess:
75
76 //! \brief Runs the parent side of the test.
77 //!
78 //! This method establishes the parent’s environment and calls
79 //! MachMultiprocessParent().
80 //!
81 //! Subclasses must override MachMultiprocessParent() instead of this method.
82 void MultiprocessParent() final;
83
84 //! \brief Runs the child side of the test.
85 //!
86 //! This method establishes the child’s environment and calls
87 //! MachMultiprocessChild(). If any failure (via fatal or nonfatal gtest
88 //! assertion) is detected, the child will exit with a failure status.
89 //!
90 //! Subclasses must override MachMultiprocessChild() instead of this method.
91 void MultiprocessChild() final;
92
93 //! \brief The subclass-provided parent routine.
94 //!
95 //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`,
96 //! `FAIL()`, etc.
97 //!
98 //! This method must not use a `wait()`-family system call to wait for the
99 //! child process to exit, as this is handled by the superclass.
100 //!
101 //! Subclasses must implement this method to define how the parent operates.
102 virtual void MachMultiprocessParent() = 0;
103
104 //! \brief The subclass-provided child routine.
105 //!
106 //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`,
107 //! `FAIL()`, etc.
108 //!
109 //! Subclasses must implement this method to define how the child operates.
110 virtual void MachMultiprocessChild() = 0;
111
112 internal::MachMultiprocessInfo* info_;
113
114 DISALLOW_COPY_AND_ASSIGN(MachMultiprocess);
115 };
116
117 } // namespace test
118 } // namespace crashpad
119
120 #endif // CRASHPAD_UTIL_TEST_MAC_MACH_MULTIPROCESS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698