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

Side by Side Diff: util/test/multiprocess.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
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,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 base::ScopedFD pipe_c2p_read; // child to parent 46 base::ScopedFD pipe_c2p_read; // child to parent
47 base::ScopedFD pipe_c2p_write; // child to parent 47 base::ScopedFD pipe_c2p_write; // child to parent
48 base::ScopedFD pipe_p2c_read; // parent to child 48 base::ScopedFD pipe_p2c_read; // parent to child
49 base::ScopedFD pipe_p2c_write; // parent to child 49 base::ScopedFD pipe_p2c_write; // parent to child
50 pid_t child_pid; // valid only in parent 50 pid_t child_pid; // valid only in parent
51 }; 51 };
52 52
53 } // namespace internal 53 } // namespace internal
54 54
55 Multiprocess::Multiprocess() : info_(NULL) { 55 Multiprocess::Multiprocess()
56 : info_(NULL),
57 code_(EXIT_SUCCESS),
58 reason_(kTerminationNormal) {
56 } 59 }
57 60
58 void Multiprocess::Run() { 61 void Multiprocess::Run() {
59 ASSERT_EQ(NULL, info_); 62 ASSERT_EQ(NULL, info_);
60 scoped_ptr<internal::MultiprocessInfo> info(new internal::MultiprocessInfo); 63 scoped_ptr<internal::MultiprocessInfo> info(new internal::MultiprocessInfo);
61 base::AutoReset<internal::MultiprocessInfo*> reset_info(&info_, info.get()); 64 base::AutoReset<internal::MultiprocessInfo*> reset_info(&info_, info.get());
62 65
63 PreFork(); 66 PreFork();
64 if (testing::Test::HasFatalFailure()) { 67 if (testing::Test::HasFatalFailure()) {
65 return; 68 return;
(...skipping 16 matching lines...) Expand all
82 // be broken, the child’s remote port will become a dead name, and an 85 // be broken, the child’s remote port will become a dead name, and an
83 // attempt by the child to look up the service will fail. If this weren’t 86 // attempt by the child to look up the service will fail. If this weren’t
84 // done, the child might hang while waiting for a parent that has already 87 // done, the child might hang while waiting for a parent that has already
85 // triggered a fatal assertion failure to do something. 88 // triggered a fatal assertion failure to do something.
86 info.reset(); 89 info.reset();
87 info_ = NULL; 90 info_ = NULL;
88 91
89 int status; 92 int status;
90 pid_t wait_pid = waitpid(pid, &status, 0); 93 pid_t wait_pid = waitpid(pid, &status, 0);
91 ASSERT_EQ(pid, wait_pid) << ErrnoMessage("waitpid"); 94 ASSERT_EQ(pid, wait_pid) << ErrnoMessage("waitpid");
92 if (status != 0) { 95
93 std::string message; 96 TerminationReason reason;
94 if (WIFEXITED(status)) { 97 int code;
95 message = base::StringPrintf("Child exited with code %d", 98 std::string message;
96 WEXITSTATUS(status)); 99 if (WIFEXITED(status)) {
97 } else if (WIFSIGNALED(status)) { 100 reason = kTerminationNormal;
98 message = base::StringPrintf("Child terminated by signal %d (%s) %s", 101 code = WEXITSTATUS(status);
99 WTERMSIG(status), 102 message = base::StringPrintf("Child exited with code %d, expected", code);
100 strsignal(WTERMSIG(status)), 103 } else if (WIFSIGNALED(status)) {
101 WCOREDUMP(status) ? " (core dumped)" : ""); 104 reason = kTerminationSignal;
102 } 105 code = WTERMSIG(status);
103 ASSERT_EQ(0, status) << message; 106 message =
107 base::StringPrintf("Child terminated by signal %d (%s)%s, expected",
108 code,
109 strsignal(code),
110 WCOREDUMP(status) ? " (core dumped)" : "");
111 } else {
112 FAIL() << "Unknown termination reason";
113 }
114
115 if (reason_ == kTerminationNormal) {
116 message += base::StringPrintf("exit with code %d", code_);
117 } else if (reason == kTerminationSignal) {
118 message += base::StringPrintf("termination by signal %d", code_);
119 }
120
121 if (reason != reason_ || code != code_) {
122 ADD_FAILURE() << message;
104 } 123 }
105 } else { 124 } else {
106 RunChild(); 125 RunChild();
107 } 126 }
108 } 127 }
109 128
129 void Multiprocess::SetExpectedChildTermination(TerminationReason reason,
130 int code) {
131 reason_ = reason;
132 code_ = code;
133 }
134
110 Multiprocess::~Multiprocess() { 135 Multiprocess::~Multiprocess() {
111 } 136 }
112 137
113 void Multiprocess::PreFork() { 138 void Multiprocess::PreFork() {
114 int pipe_fds_c2p[2]; 139 int pipe_fds_c2p[2];
115 int rv = pipe(pipe_fds_c2p); 140 int rv = pipe(pipe_fds_c2p);
116 ASSERT_EQ(0, rv) << ErrnoMessage("pipe"); 141 ASSERT_EQ(0, rv) << ErrnoMessage("pipe");
117 142
118 info_->pipe_c2p_read.reset(pipe_fds_c2p[0]); 143 info_->pipe_c2p_read.reset(pipe_fds_c2p[0]);
119 info_->pipe_c2p_write.reset(pipe_fds_c2p[1]); 144 info_->pipe_c2p_write.reset(pipe_fds_c2p[1]);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if (Test::HasFailure()) { 196 if (Test::HasFailure()) {
172 // Trigger the ScopedForbidReturn destructor. 197 // Trigger the ScopedForbidReturn destructor.
173 return; 198 return;
174 } 199 }
175 200
176 exit(0); 201 exit(0);
177 } 202 }
178 203
179 } // namespace test 204 } // namespace test
180 } // namespace crashpad 205 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698