2014-08-26 17:10:19 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
test: Move util/test to its own top-level directory, test.
After 9e79ea1da719, it no longer makes sense for crashpad_util_test_lib
to “hide” in util/util_test.gyp. All of util/test is moved to its own
top-level directory, test, which all other test code is allowed to
depend on. test, too, is allowed to depend on all other non-test code.
In a future change, when crashpad_util_test_lib gains a dependency on
crashpad_client, it won’t look so weird for something in util (even
though it’s in util/test) to depend on something in client, because the
thing that needs to depend on client will live in test, not util.
BUG=crashpad:33
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/1051533002
2015-03-31 17:44:14 -04:00
|
|
|
|
#include "test/multiprocess.h"
|
2014-08-26 17:10:19 -04:00
|
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <sys/wait.h>
|
2015-01-28 14:49:42 -08:00
|
|
|
|
#include <unistd.h>
|
2014-08-26 17:10:19 -04:00
|
|
|
|
|
2016-04-25 12:13:07 -07:00
|
|
|
|
#include <memory>
|
2014-08-26 17:10:19 -04:00
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "base/auto_reset.h"
|
|
|
|
|
#include "base/files/scoped_file.h"
|
2014-09-22 13:06:12 -04:00
|
|
|
|
#include "base/logging.h"
|
2014-09-22 13:17:17 -04:00
|
|
|
|
#include "base/posix/eintr_wrapper.h"
|
2014-08-26 17:10:19 -04:00
|
|
|
|
#include "base/strings/stringprintf.h"
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
#include "build/build_config.h"
|
2014-08-26 17:10:19 -04:00
|
|
|
|
#include "gtest/gtest.h"
|
test: Move util/test to its own top-level directory, test.
After 9e79ea1da719, it no longer makes sense for crashpad_util_test_lib
to “hide” in util/util_test.gyp. All of util/test is moved to its own
top-level directory, test, which all other test code is allowed to
depend on. test, too, is allowed to depend on all other non-test code.
In a future change, when crashpad_util_test_lib gains a dependency on
crashpad_client, it won’t look so weird for something in util (even
though it’s in util/test) to depend on something in client, because the
thing that needs to depend on client will live in test, not util.
BUG=crashpad:33
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/1051533002
2015-03-31 17:44:14 -04:00
|
|
|
|
#include "test/errors.h"
|
2014-08-26 17:10:19 -04:00
|
|
|
|
#include "util/misc/scoped_forbid_return.h"
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
#include "util/posix/signals.h"
|
|
|
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
|
#include "test/mac/exception_swallower.h"
|
|
|
|
|
#endif
|
2014-08-26 17:10:19 -04:00
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
struct MultiprocessInfo {
|
|
|
|
|
MultiprocessInfo()
|
|
|
|
|
: pipe_c2p_read(-1),
|
|
|
|
|
pipe_c2p_write(-1),
|
|
|
|
|
pipe_p2c_read(-1),
|
|
|
|
|
pipe_p2c_write(-1),
|
|
|
|
|
child_pid(0) {}
|
|
|
|
|
|
|
|
|
|
base::ScopedFD pipe_c2p_read; // child to parent
|
|
|
|
|
base::ScopedFD pipe_c2p_write; // child to parent
|
|
|
|
|
base::ScopedFD pipe_p2c_read; // parent to child
|
|
|
|
|
base::ScopedFD pipe_p2c_write; // parent to child
|
|
|
|
|
pid_t child_pid; // valid only in parent
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
2014-09-09 17:04:47 -04:00
|
|
|
|
Multiprocess::Multiprocess()
|
2014-10-14 11:10:45 -04:00
|
|
|
|
: info_(nullptr),
|
2014-09-09 17:04:47 -04:00
|
|
|
|
code_(EXIT_SUCCESS),
|
|
|
|
|
reason_(kTerminationNormal) {
|
2014-08-26 17:10:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Multiprocess::Run() {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(info_, nullptr);
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<internal::MultiprocessInfo> info(
|
|
|
|
|
new internal::MultiprocessInfo);
|
2014-08-26 17:10:19 -04:00
|
|
|
|
base::AutoReset<internal::MultiprocessInfo*> reset_info(&info_, info.get());
|
|
|
|
|
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(PreFork());
|
2014-08-26 17:10:19 -04:00
|
|
|
|
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
#if defined(OS_MACOSX)
|
2017-11-20 14:36:54 -05:00
|
|
|
|
// If the child is expected to crash, set up an exception swallower to swallow
|
|
|
|
|
// the exception instead of allowing it to be seen by the system’s crash
|
|
|
|
|
// reporter.
|
|
|
|
|
std::unique_ptr<ExceptionSwallower> exception_swallower;
|
|
|
|
|
if (reason_ == kTerminationSignal && Signals::IsCrashSignal(code_)) {
|
|
|
|
|
exception_swallower.reset(new ExceptionSwallower());
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
}
|
|
|
|
|
#endif // OS_MACOSX
|
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
pid_t pid = fork();
|
|
|
|
|
ASSERT_GE(pid, 0) << ErrnoMessage("fork");
|
|
|
|
|
|
|
|
|
|
if (pid > 0) {
|
|
|
|
|
info_->child_pid = pid;
|
|
|
|
|
|
|
|
|
|
RunParent();
|
|
|
|
|
|
|
|
|
|
// Waiting for the child happens here instead of in RunParent() because even
|
|
|
|
|
// if RunParent() returns early due to a gtest fatal assertion failure, the
|
|
|
|
|
// child should still be reaped.
|
|
|
|
|
|
|
|
|
|
// This will make the parent hang up on the child as much as would be
|
|
|
|
|
// visible from the child’s perspective. The child’s side of the pipe will
|
|
|
|
|
// be broken, the child’s remote port will become a dead name, and an
|
|
|
|
|
// attempt by the child to look up the service will fail. If this weren’t
|
|
|
|
|
// done, the child might hang while waiting for a parent that has already
|
|
|
|
|
// triggered a fatal assertion failure to do something.
|
|
|
|
|
info.reset();
|
2014-10-14 11:10:45 -04:00
|
|
|
|
info_ = nullptr;
|
2014-08-26 17:10:19 -04:00
|
|
|
|
|
|
|
|
|
int status;
|
2014-09-22 13:17:17 -04:00
|
|
|
|
pid_t wait_pid = HANDLE_EINTR(waitpid(pid, &status, 0));
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(wait_pid, pid) << ErrnoMessage("waitpid");
|
2014-09-09 17:04:47 -04:00
|
|
|
|
|
|
|
|
|
TerminationReason reason;
|
|
|
|
|
int code;
|
|
|
|
|
std::string message;
|
|
|
|
|
if (WIFEXITED(status)) {
|
|
|
|
|
reason = kTerminationNormal;
|
|
|
|
|
code = WEXITSTATUS(status);
|
2016-06-20 13:41:40 -04:00
|
|
|
|
message = base::StringPrintf("Child exited with code %d", code);
|
2014-09-09 17:04:47 -04:00
|
|
|
|
} else if (WIFSIGNALED(status)) {
|
|
|
|
|
reason = kTerminationSignal;
|
|
|
|
|
code = WTERMSIG(status);
|
|
|
|
|
message =
|
2016-06-20 13:41:40 -04:00
|
|
|
|
base::StringPrintf("Child terminated by signal %d (%s)%s",
|
2014-09-09 17:04:47 -04:00
|
|
|
|
code,
|
|
|
|
|
strsignal(code),
|
|
|
|
|
WCOREDUMP(status) ? " (core dumped)" : "");
|
|
|
|
|
} else {
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
FAIL() << base::StringPrintf("Unknown termination reason 0x%x", status);
|
2014-09-09 17:04:47 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reason_ == kTerminationNormal) {
|
2016-06-20 13:41:40 -04:00
|
|
|
|
message += base::StringPrintf(", expected exit with code %d", code_);
|
|
|
|
|
} else if (reason_ == kTerminationSignal) {
|
|
|
|
|
message += base::StringPrintf(", expected termination by signal %d (%s)",
|
|
|
|
|
code_,
|
|
|
|
|
strsignal(code_));
|
2014-09-09 17:04:47 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reason != reason_ || code != code_) {
|
|
|
|
|
ADD_FAILURE() << message;
|
2014-08-26 17:10:19 -04:00
|
|
|
|
}
|
|
|
|
|
} else {
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
#if defined(OS_MACOSX)
|
2017-11-20 14:36:54 -05:00
|
|
|
|
if (exception_swallower.get()) {
|
|
|
|
|
ExceptionSwallower::SwallowExceptions();
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
}
|
2018-07-11 08:59:41 -07:00
|
|
|
|
#elif defined(OS_LINUX) || defined(OS_ANDROID)
|
|
|
|
|
if (reason_ == kTerminationSignal && Signals::IsCrashSignal(code_)) {
|
|
|
|
|
Signals::InstallDefaultHandler(code_);
|
|
|
|
|
}
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
#endif // OS_MACOSX
|
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
RunChild();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-09 17:04:47 -04:00
|
|
|
|
void Multiprocess::SetExpectedChildTermination(TerminationReason reason,
|
2019-02-25 08:31:11 -08:00
|
|
|
|
ReturnCodeType code) {
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
EXPECT_EQ(info_, nullptr)
|
|
|
|
|
<< "SetExpectedChildTermination() must be called before Run()";
|
2014-09-09 17:04:47 -04:00
|
|
|
|
reason_ = reason;
|
|
|
|
|
code_ = code;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 12:45:42 -08:00
|
|
|
|
void Multiprocess::SetExpectedChildTerminationBuiltinTrap() {
|
2018-07-10 11:17:22 +02:00
|
|
|
|
#if defined(ARCH_CPU_ARM64) || defined(ARCH_CPU_MIPS_FAMILY)
|
2018-02-22 12:45:42 -08:00
|
|
|
|
SetExpectedChildTermination(kTerminationSignal, SIGTRAP);
|
|
|
|
|
#else
|
|
|
|
|
SetExpectedChildTermination(kTerminationSignal, SIGILL);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
Multiprocess::~Multiprocess() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Multiprocess::PreFork() {
|
|
|
|
|
int pipe_fds_c2p[2];
|
|
|
|
|
int rv = pipe(pipe_fds_c2p);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(rv, 0) << ErrnoMessage("pipe");
|
2014-08-26 17:10:19 -04:00
|
|
|
|
|
|
|
|
|
info_->pipe_c2p_read.reset(pipe_fds_c2p[0]);
|
|
|
|
|
info_->pipe_c2p_write.reset(pipe_fds_c2p[1]);
|
|
|
|
|
|
|
|
|
|
int pipe_fds_p2c[2];
|
|
|
|
|
rv = pipe(pipe_fds_p2c);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(rv, 0) << ErrnoMessage("pipe");
|
2014-08-26 17:10:19 -04:00
|
|
|
|
|
|
|
|
|
info_->pipe_p2c_read.reset(pipe_fds_p2c[0]);
|
|
|
|
|
info_->pipe_p2c_write.reset(pipe_fds_p2c[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pid_t Multiprocess::ChildPID() const {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_NE(info_->child_pid, 0);
|
2014-08-26 17:10:19 -04:00
|
|
|
|
return info_->child_pid;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 14:49:42 -08:00
|
|
|
|
FileHandle Multiprocess::ReadPipeHandle() const {
|
2014-08-26 17:10:19 -04:00
|
|
|
|
int fd = info_->child_pid ? info_->pipe_c2p_read.get()
|
|
|
|
|
: info_->pipe_p2c_read.get();
|
2014-09-22 13:06:12 -04:00
|
|
|
|
CHECK_NE(fd, -1);
|
2014-08-26 17:10:19 -04:00
|
|
|
|
return fd;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 14:49:42 -08:00
|
|
|
|
FileHandle Multiprocess::WritePipeHandle() const {
|
2014-08-26 17:10:19 -04:00
|
|
|
|
int fd = info_->child_pid ? info_->pipe_p2c_write.get()
|
|
|
|
|
: info_->pipe_c2p_write.get();
|
2014-09-22 13:06:12 -04:00
|
|
|
|
CHECK_NE(fd, -1);
|
2014-08-26 17:10:19 -04:00
|
|
|
|
return fd;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-22 13:06:12 -04:00
|
|
|
|
void Multiprocess::CloseReadPipe() {
|
|
|
|
|
if (info_->child_pid) {
|
|
|
|
|
info_->pipe_c2p_read.reset();
|
|
|
|
|
} else {
|
|
|
|
|
info_->pipe_p2c_read.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Multiprocess::CloseWritePipe() {
|
|
|
|
|
if (info_->child_pid) {
|
|
|
|
|
info_->pipe_p2c_write.reset();
|
|
|
|
|
} else {
|
|
|
|
|
info_->pipe_c2p_write.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 17:10:19 -04:00
|
|
|
|
void Multiprocess::RunParent() {
|
|
|
|
|
// The parent uses the read end of c2p and the write end of p2c.
|
|
|
|
|
info_->pipe_c2p_write.reset();
|
|
|
|
|
info_->pipe_p2c_read.reset();
|
|
|
|
|
|
|
|
|
|
MultiprocessParent();
|
|
|
|
|
|
|
|
|
|
info_->pipe_c2p_read.reset();
|
|
|
|
|
info_->pipe_p2c_write.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Multiprocess::RunChild() {
|
|
|
|
|
ScopedForbidReturn forbid_return;
|
|
|
|
|
|
|
|
|
|
// The child uses the write end of c2p and the read end of p2c.
|
|
|
|
|
info_->pipe_c2p_read.reset();
|
|
|
|
|
info_->pipe_p2c_write.reset();
|
|
|
|
|
|
|
|
|
|
MultiprocessChild();
|
|
|
|
|
|
|
|
|
|
info_->pipe_c2p_write.reset();
|
|
|
|
|
info_->pipe_p2c_read.reset();
|
|
|
|
|
|
2014-10-07 17:28:50 -04:00
|
|
|
|
if (testing::Test::HasFailure()) {
|
2014-08-26 17:10:19 -04:00
|
|
|
|
// Trigger the ScopedForbidReturn destructor.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 13:59:46 -04:00
|
|
|
|
// In a forked child, exit() is unsafe. Use _exit() instead.
|
|
|
|
|
_exit(EXIT_SUCCESS);
|
2014-08-26 17:10:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace crashpad
|