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

Side by Side Diff: util/test/multiprocess_test.cc

Issue 553153002: Add Multiprocess::SetExpectedChildTermination() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 3 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
« util/test/multiprocess.h ('K') | « util/test/multiprocess.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 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 #include "util/test/multiprocess.h" 15 #include "util/test/multiprocess.h"
16 16
17 #include <stdlib.h>
18 #include <sys/signal.h>
17 #include <unistd.h> 19 #include <unistd.h>
18 20
19 #include "base/basictypes.h" 21 #include "base/basictypes.h"
20 #include "gtest/gtest.h" 22 #include "gtest/gtest.h"
21 #include "util/file/fd_io.h" 23 #include "util/file/fd_io.h"
22 #include "util/test/errors.h" 24 #include "util/test/errors.h"
23 25
24 namespace { 26 namespace {
25 27
26 using namespace crashpad; 28 using namespace crashpad;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 76 }
75 77
76 DISALLOW_COPY_AND_ASSIGN(TestMultiprocess); 78 DISALLOW_COPY_AND_ASSIGN(TestMultiprocess);
77 }; 79 };
78 80
79 TEST(Multiprocess, Multiprocess) { 81 TEST(Multiprocess, Multiprocess) {
80 TestMultiprocess multiprocess; 82 TestMultiprocess multiprocess;
81 multiprocess.Run(); 83 multiprocess.Run();
82 } 84 }
83 85
86 class TestMultiprocessUnclean final : public Multiprocess {
87 public:
88 enum TerminationType {
89 kExitSuccess = 0,
90 kExitFailure,
91 kExit2,
92 kAbort,
93 };
94
95 explicit TestMultiprocessUnclean(TerminationType type)
96 : Multiprocess(),
97 type_(type) {
98 if (type_ == kAbort) {
99 SetExpectedChildTermination(kTerminationSignal, SIGABRT);
100 } else {
101 SetExpectedChildTermination(kTerminationNormal, ExitCode());
102 }
103 }
104
105 ~TestMultiprocessUnclean() {}
106
107 private:
108 int ExitCode() const {
109 return type_;
110 }
111
112 virtual void MultiprocessParent() override {
113 }
114
115 virtual void MultiprocessChild() override {
116 if (type_ == kAbort) {
117 abort();
118 } else {
119 _exit(ExitCode());
120 }
121 }
122
123 TerminationType type_;
124
125 DISALLOW_COPY_AND_ASSIGN(TestMultiprocessUnclean);
126 };
127
128 TEST(Multiprocess, MultiprocessSuccessfulExit) {
129 TestMultiprocessUnclean multiprocess(TestMultiprocessUnclean::kExitSuccess);
130 multiprocess.Run();
131 }
132
133 TEST(Multiprocess, MultiprocessUnsuccessfulExit) {
134 TestMultiprocessUnclean multiprocess(TestMultiprocessUnclean::kExitFailure);
135 multiprocess.Run();
136 }
137
138 TEST(Multiprocess, MultiprocessExit2) {
139 TestMultiprocessUnclean multiprocess(TestMultiprocessUnclean::kExit2);
140 multiprocess.Run();
141 }
142
143 TEST(Multiprocess, MultiprocessAbortSignal) {
144 TestMultiprocessUnclean multiprocess(TestMultiprocessUnclean::kAbort);
145 multiprocess.Run();
146 }
147
84 } // namespace 148 } // namespace
OLDNEW
« util/test/multiprocess.h ('K') | « util/test/multiprocess.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698