2014-09-16 17:36:33 -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.
|
|
|
|
|
|
|
|
|
|
#include "util/mach/exception_ports.h"
|
|
|
|
|
|
|
|
|
|
#include <mach/mach.h>
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
|
#include "base/mac/mach_logging.h"
|
|
|
|
|
#include "base/mac/scoped_mach_port.h"
|
2016-01-06 12:22:50 -05:00
|
|
|
|
#include "base/macros.h"
|
2014-09-16 17:36:33 -04:00
|
|
|
|
#include "base/strings/stringprintf.h"
|
|
|
|
|
#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/mac/mach_errors.h"
|
|
|
|
|
#include "test/mac/mach_multiprocess.h"
|
2014-12-17 14:35:18 -08:00
|
|
|
|
#include "util/file/file_io.h"
|
2014-09-16 17:36:33 -04:00
|
|
|
|
#include "util/mach/exc_server_variants.h"
|
2015-04-08 17:46:09 -04:00
|
|
|
|
#include "util/mach/exception_types.h"
|
2014-09-16 17:36:33 -04:00
|
|
|
|
#include "util/mach/mach_extensions.h"
|
2014-12-10 11:11:21 -05:00
|
|
|
|
#include "util/mach/mach_message.h"
|
|
|
|
|
#include "util/mach/mach_message_server.h"
|
2014-09-16 17:36:33 -04:00
|
|
|
|
#include "util/misc/scoped_forbid_return.h"
|
2014-09-24 13:32:31 -04:00
|
|
|
|
#include "util/synchronization/semaphore.h"
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
2014-10-07 17:28:50 -04:00
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace test {
|
2014-09-16 17:36:33 -04:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
// Calls GetExceptionPorts() on its |exception_ports| argument to look up the
|
|
|
|
|
// EXC_MASK_CRASH handler. If |expect_port| is not MACH_PORT_NULL, it expects to
|
|
|
|
|
// find a handler for this mask whose port matches |expect_port| and whose
|
|
|
|
|
// behavior matches |expect_behavior| exactly. In this case, if
|
|
|
|
|
// |expect_behavior| is a state-carrying behavior, the looked-up thread state
|
|
|
|
|
// flavor is expected to be MACHINE_THREAD_STATE, otherwise, it is expected to
|
|
|
|
|
// be THREAD_STATE_NONE. If |expect_port| is MACH_PORT_NULL, no handler for
|
|
|
|
|
// EXC_MASK_CRASH is expected to be found.
|
|
|
|
|
//
|
|
|
|
|
// A second GetExceptionPorts() lookup is also performed on a wider exception
|
|
|
|
|
// mask, EXC_MASK_ALL | EXC_MASK_CRASH. The EXC_MASK_CRASH handler’s existence
|
|
|
|
|
// and properties from this second lookup are validated in the same way.
|
|
|
|
|
//
|
|
|
|
|
// This function uses gtest EXPECT_* and ASSERT_* macros to perform its
|
|
|
|
|
// validation.
|
|
|
|
|
void TestGetExceptionPorts(const ExceptionPorts& exception_ports,
|
|
|
|
|
mach_port_t expect_port,
|
|
|
|
|
exception_behavior_t expect_behavior) {
|
2017-07-25 19:15:48 -04:00
|
|
|
|
constexpr exception_mask_t kExceptionMask = EXC_MASK_CRASH;
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
thread_state_flavor_t expect_flavor = (expect_behavior == EXCEPTION_DEFAULT)
|
|
|
|
|
? THREAD_STATE_NONE
|
|
|
|
|
: MACHINE_THREAD_STATE;
|
|
|
|
|
|
2015-10-06 16:14:29 -04:00
|
|
|
|
ExceptionPorts::ExceptionHandlerVector crash_handler;
|
2014-09-16 17:36:33 -04:00
|
|
|
|
ASSERT_TRUE(
|
|
|
|
|
exception_ports.GetExceptionPorts(kExceptionMask, &crash_handler));
|
|
|
|
|
|
|
|
|
|
if (expect_port != MACH_PORT_NULL) {
|
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(crash_handler.size(), 1u);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
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_EQ(crash_handler[0].mask, kExceptionMask);
|
|
|
|
|
EXPECT_EQ(crash_handler[0].port, expect_port);
|
|
|
|
|
EXPECT_EQ(crash_handler[0].behavior, expect_behavior);
|
|
|
|
|
EXPECT_EQ(crash_handler[0].flavor, expect_flavor);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
} else {
|
|
|
|
|
EXPECT_TRUE(crash_handler.empty());
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-06 16:14:29 -04:00
|
|
|
|
ExceptionPorts::ExceptionHandlerVector handlers;
|
2015-09-04 14:29:12 -04:00
|
|
|
|
ASSERT_TRUE(exception_ports.GetExceptionPorts(ExcMaskValid(), &handlers));
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
EXPECT_GE(handlers.size(), crash_handler.size());
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (const ExceptionPorts::ExceptionHandler& handler : handlers) {
|
|
|
|
|
if ((handler.mask & kExceptionMask) != 0) {
|
|
|
|
|
EXPECT_FALSE(found);
|
|
|
|
|
found = true;
|
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_EQ(handler.port, expect_port);
|
|
|
|
|
EXPECT_EQ(handler.behavior, expect_behavior);
|
|
|
|
|
EXPECT_EQ(handler.flavor, expect_flavor);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (expect_port != MACH_PORT_NULL) {
|
|
|
|
|
EXPECT_TRUE(found);
|
|
|
|
|
} else {
|
|
|
|
|
EXPECT_FALSE(found);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 10:18:24 -05:00
|
|
|
|
class TestExceptionPorts : public MachMultiprocess,
|
|
|
|
|
public UniversalMachExcServer::Interface {
|
2014-09-16 17:36:33 -04:00
|
|
|
|
public:
|
2015-03-10 11:16:24 -04:00
|
|
|
|
// Which entities to set exception ports for.
|
|
|
|
|
enum SetOn {
|
|
|
|
|
kSetOnTaskOnly = 0,
|
|
|
|
|
kSetOnTaskAndThreads,
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-16 17:36:33 -04:00
|
|
|
|
// Where to call ExceptionPorts::SetExceptionPort() from.
|
|
|
|
|
enum SetType {
|
|
|
|
|
// Call it from the child process on itself.
|
|
|
|
|
kSetInProcess = 0,
|
|
|
|
|
|
|
|
|
|
// Call it from the parent process on the child.
|
|
|
|
|
kSetOutOfProcess,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Which thread in the child process is expected to crash.
|
|
|
|
|
enum WhoCrashes {
|
|
|
|
|
kNobodyCrashes = 0,
|
|
|
|
|
kMainThreadCrashes,
|
|
|
|
|
kOtherThreadCrashes,
|
|
|
|
|
};
|
|
|
|
|
|
2015-03-10 11:16:24 -04:00
|
|
|
|
TestExceptionPorts(SetOn set_on, SetType set_type, WhoCrashes who_crashes)
|
2014-12-04 10:18:24 -05:00
|
|
|
|
: MachMultiprocess(),
|
|
|
|
|
UniversalMachExcServer::Interface(),
|
2014-09-16 17:36:33 -04:00
|
|
|
|
set_on_(set_on),
|
2015-03-10 11:16:24 -04:00
|
|
|
|
set_type_(set_type),
|
2014-09-16 17:36:33 -04:00
|
|
|
|
who_crashes_(who_crashes),
|
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
|
|
|
|
handled_(false) {
|
|
|
|
|
if (who_crashes_ != kNobodyCrashes) {
|
|
|
|
|
// This is how the __builtin_trap() in Child::Crash() appears.
|
|
|
|
|
SetExpectedChildTermination(kTerminationSignal, SIGILL);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
SetOn set_on() const { return set_on_; }
|
2015-03-10 11:16:24 -04:00
|
|
|
|
SetType set_type() const { return set_type_; }
|
2014-09-16 17:36:33 -04:00
|
|
|
|
WhoCrashes who_crashes() const { return who_crashes_; }
|
|
|
|
|
|
2014-12-04 10:18:24 -05:00
|
|
|
|
// UniversalMachExcServer::Interface:
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
virtual kern_return_t CatchMachException(
|
|
|
|
|
exception_behavior_t behavior,
|
|
|
|
|
exception_handler_t exception_port,
|
|
|
|
|
thread_t thread,
|
|
|
|
|
task_t task,
|
|
|
|
|
exception_type_t exception,
|
|
|
|
|
const mach_exception_data_type_t* code,
|
|
|
|
|
mach_msg_type_number_t code_count,
|
|
|
|
|
thread_state_flavor_t* flavor,
|
2015-04-02 15:28:28 -04:00
|
|
|
|
ConstThreadState old_state,
|
2014-09-16 17:36:33 -04:00
|
|
|
|
mach_msg_type_number_t old_state_count,
|
|
|
|
|
thread_state_t new_state,
|
|
|
|
|
mach_msg_type_number_t* new_state_count,
|
2014-12-01 16:06:56 -05:00
|
|
|
|
const mach_msg_trailer_t* trailer,
|
2014-09-16 17:36:33 -04:00
|
|
|
|
bool* destroy_complex_request) override {
|
|
|
|
|
*destroy_complex_request = true;
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(handled_);
|
|
|
|
|
handled_ = true;
|
|
|
|
|
|
|
|
|
|
// To be able to distinguish between which handler was actually triggered,
|
|
|
|
|
// the different handlers are registered with different behavior values.
|
|
|
|
|
exception_behavior_t expect_behavior;
|
|
|
|
|
if (set_on_ == kSetOnTaskOnly) {
|
|
|
|
|
expect_behavior = EXCEPTION_DEFAULT;
|
|
|
|
|
} else if (who_crashes_ == kMainThreadCrashes) {
|
|
|
|
|
expect_behavior = EXCEPTION_STATE;
|
|
|
|
|
} else if (who_crashes_ == kOtherThreadCrashes) {
|
|
|
|
|
expect_behavior = EXCEPTION_STATE_IDENTITY;
|
|
|
|
|
} else {
|
|
|
|
|
NOTREACHED();
|
|
|
|
|
expect_behavior = 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
|
|
|
|
EXPECT_EQ(behavior, expect_behavior);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
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_EQ(exception_port, LocalPort());
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
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_EQ(exception, EXC_CRASH);
|
|
|
|
|
EXPECT_EQ(code_count, 2u);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
2014-09-17 17:59:35 -04:00
|
|
|
|
// The exception and code_count checks above would ideally use ASSERT_EQ so
|
|
|
|
|
// that the next conditional would not be necessary, but ASSERT_* requires a
|
|
|
|
|
// function returning type void, and the interface dictates otherwise here.
|
|
|
|
|
if (exception == EXC_CRASH && code_count >= 1) {
|
|
|
|
|
int signal;
|
2014-10-14 11:10:45 -04:00
|
|
|
|
ExcCrashRecoverOriginalException(code[0], nullptr, &signal);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
2015-03-10 11:16:24 -04:00
|
|
|
|
// The child crashed with __builtin_trap(), which shows up as SIGILL.
|
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_EQ(signal, SIGILL);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
}
|
|
|
|
|
|
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_EQ(AuditPIDFromMachMessageTrailer(trailer), 0);
|
2015-03-12 14:00:38 -04:00
|
|
|
|
|
2015-09-04 14:29:12 -04:00
|
|
|
|
ExcServerCopyState(
|
|
|
|
|
behavior, old_state, old_state_count, new_state, new_state_count);
|
|
|
|
|
return ExcServerSuccessfulReturnValue(exception, behavior, false);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
class Child {
|
|
|
|
|
public:
|
|
|
|
|
explicit Child(TestExceptionPorts* test_exception_ports)
|
|
|
|
|
: test_exception_ports_(test_exception_ports),
|
|
|
|
|
thread_(),
|
2014-09-24 13:32:31 -04:00
|
|
|
|
init_semaphore_(0),
|
|
|
|
|
crash_semaphore_(0) {}
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
2014-09-24 13:32:31 -04:00
|
|
|
|
~Child() {}
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
void Run() {
|
|
|
|
|
ExceptionPorts self_task_ports(ExceptionPorts::kTargetTypeTask,
|
2014-10-13 12:59:21 -04:00
|
|
|
|
TASK_NULL);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
ExceptionPorts self_thread_ports(ExceptionPorts::kTargetTypeThread,
|
2014-10-13 12:59:21 -04:00
|
|
|
|
THREAD_NULL);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
mach_port_t remote_port = test_exception_ports_->RemotePort();
|
|
|
|
|
|
|
|
|
|
// Set the task’s and this thread’s exception ports, if appropriate.
|
|
|
|
|
if (test_exception_ports_->set_type() == kSetInProcess) {
|
|
|
|
|
ASSERT_TRUE(self_task_ports.SetExceptionPort(
|
|
|
|
|
EXC_MASK_CRASH, remote_port, EXCEPTION_DEFAULT, THREAD_STATE_NONE));
|
|
|
|
|
|
|
|
|
|
if (test_exception_ports_->set_on() == kSetOnTaskAndThreads) {
|
|
|
|
|
ASSERT_TRUE(self_thread_ports.SetExceptionPort(EXC_MASK_CRASH,
|
|
|
|
|
remote_port,
|
|
|
|
|
EXCEPTION_STATE,
|
|
|
|
|
MACHINE_THREAD_STATE));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 11:10:45 -04:00
|
|
|
|
int rv_int = pthread_create(&thread_, nullptr, ThreadMainThunk, this);
|
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_int, 0);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// Wait for the new thread to be ready.
|
2014-09-24 13:32:31 -04:00
|
|
|
|
init_semaphore_.Wait();
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// Tell the parent process that everything is set up.
|
|
|
|
|
char c = '\0';
|
2015-01-28 14:49:42 -08:00
|
|
|
|
CheckedWriteFile(test_exception_ports_->WritePipeHandle(), &c, 1);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// Wait for the parent process to say that its end is set up.
|
Make file_io reads more rational and predictable
ReadFile() attempted to continue reading after a short read. In most
cases, this is fine. However, ReadFile() would keep trying to fill a
partially-filled buffer until experiencing a 0-length read(), signaling
end-of-file. For certain weird file descriptors like terminal input, EOF
is an ephemeral condition, and attempting to read beyond EOF doesn’t
actually return 0 (EOF) provided that they remain open, it will block
waiting for more input. Consequently, ReadFile() and anything based on
ReadFile() had an undocumented and quirky interface, which was that any
short read that it returned (not an underlying short read) actually
indicated EOF.
This facet of ReadFile() was unexpected, so it’s being removed. The new
behavior is that ReadFile() will return an underlying short read. The
behavior of FileReaderInterface::Read() is updated in accordance with
this change.
Upon experiencing a short read, the caller can determine the best
action. Most callers were already prepared for this behavior. Outside of
util/file, only crashpad_database_util properly implemented EOF
detection according to previous semantics, and adapting it to new
semantics is trivial.
Callers who require an exact-length read can use the new
ReadFileExactly(), or the newly renamed LoggingReadFileExactly() or
CheckedReadFileExactly(). These functions will retry following a short
read. The renamed functions were previously called LoggingReadFile() and
CheckedReadFile(), but those names implied that they were simply
wrapping ReadFile(), which is not the case. They wrapped ReadFile() and
further, insisted on a full read. Since ReadFile()’s semantics are now
changing but these functions’ are not, they’re now even more distinct
from ReadFile(), and must be renamed to avoid confusion.
Test: *
Change-Id: I06b77e0d6ad8719bd2eb67dab93a8740542dd908
Reviewed-on: https://chromium-review.googlesource.com/456676
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-03-16 13:36:38 -04:00
|
|
|
|
CheckedReadFileExactly(test_exception_ports_->ReadPipeHandle(), &c, 1);
|
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_EQ(c, '\0');
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// Regardless of where ExceptionPorts::SetExceptionPort() ran,
|
|
|
|
|
// ExceptionPorts::GetExceptionPorts() can always be tested in-process.
|
|
|
|
|
{
|
|
|
|
|
SCOPED_TRACE("task");
|
|
|
|
|
TestGetExceptionPorts(self_task_ports, remote_port, EXCEPTION_DEFAULT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
SCOPED_TRACE("main_thread");
|
|
|
|
|
mach_port_t thread_handler =
|
|
|
|
|
(test_exception_ports_->set_on() == kSetOnTaskAndThreads)
|
|
|
|
|
? remote_port
|
|
|
|
|
: MACH_PORT_NULL;
|
|
|
|
|
TestGetExceptionPorts(
|
|
|
|
|
self_thread_ports, thread_handler, EXCEPTION_STATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Let the other thread know it’s safe to proceed.
|
2014-09-24 13:32:31 -04:00
|
|
|
|
crash_semaphore_.Signal();
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// If this thread is the one that crashes, do it.
|
|
|
|
|
if (test_exception_ports_->who_crashes() == kMainThreadCrashes) {
|
|
|
|
|
Crash();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reap the other thread.
|
2014-10-14 11:10:45 -04:00
|
|
|
|
rv_int = pthread_join(thread_, nullptr);
|
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_int, 0);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Calls ThreadMain().
|
|
|
|
|
static void* ThreadMainThunk(void* argument) {
|
|
|
|
|
Child* self = reinterpret_cast<Child*>(argument);
|
|
|
|
|
return self->ThreadMain();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Runs the “other” thread.
|
|
|
|
|
void* ThreadMain() {
|
|
|
|
|
ExceptionPorts self_thread_ports(ExceptionPorts::kTargetTypeThread,
|
2014-10-13 12:59:21 -04:00
|
|
|
|
THREAD_NULL);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
mach_port_t remote_port = test_exception_ports_->RemotePort();
|
|
|
|
|
|
|
|
|
|
// Set this thread’s exception handler, if appropriate.
|
|
|
|
|
if (test_exception_ports_->set_type() == kSetInProcess &&
|
|
|
|
|
test_exception_ports_->set_on() == kSetOnTaskAndThreads) {
|
|
|
|
|
CHECK(self_thread_ports.SetExceptionPort(EXC_MASK_CRASH,
|
|
|
|
|
remote_port,
|
|
|
|
|
EXCEPTION_STATE_IDENTITY,
|
|
|
|
|
MACHINE_THREAD_STATE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Let the main thread know that this thread is ready.
|
2014-09-24 13:32:31 -04:00
|
|
|
|
init_semaphore_.Signal();
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// Wait for the main thread to signal that it’s safe to proceed.
|
2014-09-24 13:32:31 -04:00
|
|
|
|
crash_semaphore_.Wait();
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// Regardless of where ExceptionPorts::SetExceptionPort() ran,
|
|
|
|
|
// ExceptionPorts::GetExceptionPorts() can always be tested in-process.
|
|
|
|
|
{
|
|
|
|
|
SCOPED_TRACE("other_thread");
|
|
|
|
|
mach_port_t thread_handler =
|
|
|
|
|
(test_exception_ports_->set_on() == kSetOnTaskAndThreads)
|
|
|
|
|
? remote_port
|
|
|
|
|
: MACH_PORT_NULL;
|
|
|
|
|
TestGetExceptionPorts(
|
|
|
|
|
self_thread_ports, thread_handler, EXCEPTION_STATE_IDENTITY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If this thread is the one that crashes, do it.
|
|
|
|
|
if (test_exception_ports_->who_crashes() == kOtherThreadCrashes) {
|
|
|
|
|
Crash();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 11:10:45 -04:00
|
|
|
|
return nullptr;
|
2014-09-16 17:36:33 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 11:16:24 -04:00
|
|
|
|
static void Crash() {
|
|
|
|
|
__builtin_trap();
|
|
|
|
|
}
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// The parent object.
|
|
|
|
|
TestExceptionPorts* test_exception_ports_; // weak
|
|
|
|
|
|
|
|
|
|
// The “other” thread.
|
|
|
|
|
pthread_t thread_;
|
|
|
|
|
|
|
|
|
|
// The main thread waits on this for the other thread to start up and
|
|
|
|
|
// perform its own initialization.
|
2014-09-24 13:32:31 -04:00
|
|
|
|
Semaphore init_semaphore_;
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// The child thread waits on this for the parent thread to indicate that the
|
|
|
|
|
// child can test its exception ports and possibly crash, as appropriate.
|
2014-09-24 13:32:31 -04:00
|
|
|
|
Semaphore crash_semaphore_;
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Child);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// MachMultiprocess:
|
|
|
|
|
|
2014-10-14 11:11:57 -04:00
|
|
|
|
void MachMultiprocessParent() override {
|
2014-09-16 17:36:33 -04:00
|
|
|
|
// Wait for the child process to be ready. It needs to have all of its
|
|
|
|
|
// threads set up before proceeding if in kSetOutOfProcess mode.
|
|
|
|
|
char c;
|
Make file_io reads more rational and predictable
ReadFile() attempted to continue reading after a short read. In most
cases, this is fine. However, ReadFile() would keep trying to fill a
partially-filled buffer until experiencing a 0-length read(), signaling
end-of-file. For certain weird file descriptors like terminal input, EOF
is an ephemeral condition, and attempting to read beyond EOF doesn’t
actually return 0 (EOF) provided that they remain open, it will block
waiting for more input. Consequently, ReadFile() and anything based on
ReadFile() had an undocumented and quirky interface, which was that any
short read that it returned (not an underlying short read) actually
indicated EOF.
This facet of ReadFile() was unexpected, so it’s being removed. The new
behavior is that ReadFile() will return an underlying short read. The
behavior of FileReaderInterface::Read() is updated in accordance with
this change.
Upon experiencing a short read, the caller can determine the best
action. Most callers were already prepared for this behavior. Outside of
util/file, only crashpad_database_util properly implemented EOF
detection according to previous semantics, and adapting it to new
semantics is trivial.
Callers who require an exact-length read can use the new
ReadFileExactly(), or the newly renamed LoggingReadFileExactly() or
CheckedReadFileExactly(). These functions will retry following a short
read. The renamed functions were previously called LoggingReadFile() and
CheckedReadFile(), but those names implied that they were simply
wrapping ReadFile(), which is not the case. They wrapped ReadFile() and
further, insisted on a full read. Since ReadFile()’s semantics are now
changing but these functions’ are not, they’re now even more distinct
from ReadFile(), and must be renamed to avoid confusion.
Test: *
Change-Id: I06b77e0d6ad8719bd2eb67dab93a8740542dd908
Reviewed-on: https://chromium-review.googlesource.com/456676
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-03-16 13:36:38 -04:00
|
|
|
|
CheckedReadFileExactly(ReadPipeHandle(), &c, 1);
|
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_EQ(c, '\0');
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
mach_port_t local_port = LocalPort();
|
|
|
|
|
|
|
|
|
|
// Get an ExceptionPorts object for the task and each of its threads.
|
|
|
|
|
ExceptionPorts task_ports(ExceptionPorts::kTargetTypeTask, ChildTask());
|
2015-08-19 18:47:51 -04:00
|
|
|
|
EXPECT_STREQ("task", task_ports.TargetTypeName());
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// Hopefully the threads returned by task_threads() are in order, with the
|
|
|
|
|
// main thread first and the other thread second. This is currently always
|
|
|
|
|
// the case, although nothing guarantees that it will remain so.
|
|
|
|
|
thread_act_array_t threads;
|
|
|
|
|
mach_msg_type_number_t thread_count = 0;
|
|
|
|
|
kern_return_t kr = task_threads(ChildTask(), &threads, &thread_count);
|
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(kr, KERN_SUCCESS) << MachErrorMessage(kr, "task_threads");
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
ScopedForbidReturn threads_need_owners;
|
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(thread_count, 2u);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
base::mac::ScopedMachSendRight main_thread(threads[0]);
|
|
|
|
|
base::mac::ScopedMachSendRight other_thread(threads[1]);
|
|
|
|
|
threads_need_owners.Disarm();
|
|
|
|
|
|
|
|
|
|
ExceptionPorts main_thread_ports(ExceptionPorts::kTargetTypeThread,
|
2015-10-20 11:03:25 -04:00
|
|
|
|
main_thread.get());
|
2014-09-16 17:36:33 -04:00
|
|
|
|
ExceptionPorts other_thread_ports(ExceptionPorts::kTargetTypeThread,
|
2015-10-20 11:03:25 -04:00
|
|
|
|
other_thread.get());
|
2015-08-19 18:47:51 -04:00
|
|
|
|
EXPECT_STREQ("thread", main_thread_ports.TargetTypeName());
|
|
|
|
|
EXPECT_STREQ("thread", other_thread_ports.TargetTypeName());
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
if (set_type_ == kSetOutOfProcess) {
|
|
|
|
|
// Test ExceptionPorts::SetExceptionPorts() being called from
|
|
|
|
|
// out-of-process.
|
|
|
|
|
//
|
|
|
|
|
// local_port is only a receive right, but a send right is needed for
|
|
|
|
|
// ExceptionPorts::SetExceptionPort(). Make a send right, which can be
|
|
|
|
|
// deallocated once the calls to ExceptionPorts::SetExceptionPort() are
|
|
|
|
|
// done.
|
|
|
|
|
kr = mach_port_insert_right(
|
|
|
|
|
mach_task_self(), local_port, local_port, MACH_MSG_TYPE_MAKE_SEND);
|
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(kr, KERN_SUCCESS)
|
2014-09-16 17:36:33 -04:00
|
|
|
|
<< MachErrorMessage(kr, "mach_port_insert_right");
|
|
|
|
|
base::mac::ScopedMachSendRight send_owner(local_port);
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(task_ports.SetExceptionPort(
|
|
|
|
|
EXC_MASK_CRASH, local_port, EXCEPTION_DEFAULT, THREAD_STATE_NONE));
|
|
|
|
|
|
|
|
|
|
if (set_on_ == kSetOnTaskAndThreads) {
|
|
|
|
|
ASSERT_TRUE(main_thread_ports.SetExceptionPort(
|
|
|
|
|
EXC_MASK_CRASH, local_port, EXCEPTION_STATE, MACHINE_THREAD_STATE));
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(
|
|
|
|
|
other_thread_ports.SetExceptionPort(EXC_MASK_CRASH,
|
|
|
|
|
local_port,
|
|
|
|
|
EXCEPTION_STATE_IDENTITY,
|
|
|
|
|
MACHINE_THREAD_STATE));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Regardless of where ExceptionPorts::SetExceptionPort() ran,
|
|
|
|
|
// ExceptionPorts::GetExceptionPorts() can always be tested out-of-process.
|
|
|
|
|
{
|
|
|
|
|
SCOPED_TRACE("task");
|
|
|
|
|
TestGetExceptionPorts(task_ports, local_port, EXCEPTION_DEFAULT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mach_port_t thread_handler =
|
|
|
|
|
(set_on_ == kSetOnTaskAndThreads) ? local_port : MACH_PORT_NULL;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
SCOPED_TRACE("main_thread");
|
|
|
|
|
TestGetExceptionPorts(main_thread_ports, thread_handler, EXCEPTION_STATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
SCOPED_TRACE("other_thread");
|
|
|
|
|
TestGetExceptionPorts(
|
|
|
|
|
other_thread_ports, thread_handler, EXCEPTION_STATE_IDENTITY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Let the child process know that everything in the parent process is set
|
|
|
|
|
// up.
|
|
|
|
|
c = '\0';
|
2015-01-28 14:49:42 -08:00
|
|
|
|
CheckedWriteFile(WritePipeHandle(), &c, 1);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
if (who_crashes_ != kNobodyCrashes) {
|
2014-12-04 10:18:24 -05:00
|
|
|
|
UniversalMachExcServer universal_mach_exc_server(this);
|
|
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
|
constexpr mach_msg_timeout_t kTimeoutMs = 50;
|
2014-11-25 14:48:44 -05:00
|
|
|
|
kern_return_t kr =
|
2014-12-04 10:18:24 -05:00
|
|
|
|
MachMessageServer::Run(&universal_mach_exc_server,
|
2014-11-25 14:48:44 -05:00
|
|
|
|
local_port,
|
2015-03-12 14:00:38 -04:00
|
|
|
|
kMachMessageReceiveAuditTrailer,
|
2014-11-25 14:48:44 -05:00
|
|
|
|
MachMessageServer::kOneShot,
|
|
|
|
|
MachMessageServer::kReceiveLargeError,
|
2015-03-10 11:16:24 -04:00
|
|
|
|
kTimeoutMs);
|
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_EQ(kr, KERN_SUCCESS)
|
2014-09-16 17:36:33 -04:00
|
|
|
|
<< MachErrorMessage(kr, "MachMessageServer::Run");
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(handled_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wait for the child process to exit or terminate, as indicated by it
|
|
|
|
|
// closing its pipe. This keeps LocalPort() alive in the child as
|
|
|
|
|
// RemotePort(), for the child’s use in its TestGetExceptionPorts().
|
2015-01-28 14:49:42 -08:00
|
|
|
|
CheckedReadFileAtEOF(ReadPipeHandle());
|
2014-09-16 17:36:33 -04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 11:11:57 -04:00
|
|
|
|
void MachMultiprocessChild() override {
|
2014-09-16 17:36:33 -04:00
|
|
|
|
Child child(this);
|
|
|
|
|
child.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetOn set_on_;
|
2015-03-10 11:16:24 -04:00
|
|
|
|
SetType set_type_;
|
2014-09-16 17:36:33 -04:00
|
|
|
|
WhoCrashes who_crashes_;
|
|
|
|
|
|
|
|
|
|
// true if an exception message was handled.
|
|
|
|
|
bool handled_;
|
|
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestExceptionPorts);
|
|
|
|
|
};
|
|
|
|
|
|
2015-03-10 11:16:24 -04:00
|
|
|
|
TEST(ExceptionPorts, TaskExceptionPorts_SetInProcess_NoCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskOnly,
|
|
|
|
|
TestExceptionPorts::kSetInProcess,
|
|
|
|
|
TestExceptionPorts::kNobodyCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
2015-03-10 11:16:24 -04:00
|
|
|
|
TEST(ExceptionPorts, TaskExceptionPorts_SetInProcess_MainThreadCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskOnly,
|
|
|
|
|
TestExceptionPorts::kSetInProcess,
|
|
|
|
|
TestExceptionPorts::kMainThreadCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
2015-03-10 11:16:24 -04:00
|
|
|
|
TEST(ExceptionPorts, TaskExceptionPorts_SetInProcess_OtherThreadCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskOnly,
|
|
|
|
|
TestExceptionPorts::kSetInProcess,
|
|
|
|
|
TestExceptionPorts::kOtherThreadCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ExceptionPorts, TaskAndThreadExceptionPorts_SetInProcess_NoCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskAndThreads,
|
|
|
|
|
TestExceptionPorts::kSetInProcess,
|
|
|
|
|
TestExceptionPorts::kNobodyCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ExceptionPorts, TaskAndThreadExceptionPorts_SetInProcess_MainThreadCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskAndThreads,
|
|
|
|
|
TestExceptionPorts::kSetInProcess,
|
|
|
|
|
TestExceptionPorts::kMainThreadCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ExceptionPorts,
|
|
|
|
|
TaskAndThreadExceptionPorts_SetInProcess_OtherThreadCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskAndThreads,
|
|
|
|
|
TestExceptionPorts::kSetInProcess,
|
|
|
|
|
TestExceptionPorts::kOtherThreadCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ExceptionPorts, TaskExceptionPorts_SetOutOfProcess_NoCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskOnly,
|
|
|
|
|
TestExceptionPorts::kSetOutOfProcess,
|
|
|
|
|
TestExceptionPorts::kNobodyCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ExceptionPorts, TaskExceptionPorts_SetOutOfProcess_MainThreadCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskOnly,
|
|
|
|
|
TestExceptionPorts::kSetOutOfProcess,
|
|
|
|
|
TestExceptionPorts::kMainThreadCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ExceptionPorts, TaskExceptionPorts_SetOutOfProcess_OtherThreadCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskOnly,
|
|
|
|
|
TestExceptionPorts::kSetOutOfProcess,
|
|
|
|
|
TestExceptionPorts::kOtherThreadCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ExceptionPorts, TaskAndThreadExceptionPorts_SetOutOfProcess_NoCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskAndThreads,
|
|
|
|
|
TestExceptionPorts::kSetOutOfProcess,
|
|
|
|
|
TestExceptionPorts::kNobodyCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ExceptionPorts,
|
|
|
|
|
TaskAndThreadExceptionPorts_SetOutOfProcess_MainThreadCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskAndThreads,
|
|
|
|
|
TestExceptionPorts::kSetOutOfProcess,
|
|
|
|
|
TestExceptionPorts::kMainThreadCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ExceptionPorts,
|
|
|
|
|
TaskAndThreadExceptionPorts_SetOutOfProcess_OtherThreadCrash) {
|
|
|
|
|
TestExceptionPorts test_exception_ports(
|
|
|
|
|
TestExceptionPorts::kSetOnTaskAndThreads,
|
|
|
|
|
TestExceptionPorts::kSetOutOfProcess,
|
|
|
|
|
TestExceptionPorts::kOtherThreadCrashes);
|
|
|
|
|
test_exception_ports.Run();
|
2014-09-16 17:36:33 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ExceptionPorts, HostExceptionPorts) {
|
|
|
|
|
// ExceptionPorts isn’t expected to work as non-root. Just do a quick test to
|
|
|
|
|
// make sure that TargetTypeName() returns the right string, and that the
|
|
|
|
|
// underlying host_get_exception_ports() function appears to be called by
|
|
|
|
|
// looking for a KERN_INVALID_ARGUMENT return value. Or, on the off chance
|
|
|
|
|
// that the test is being run as root, just look for KERN_SUCCESS.
|
|
|
|
|
// host_set_exception_ports() is not tested, because if the test were running
|
|
|
|
|
// as root and the call succeeded, it would have global effects.
|
|
|
|
|
|
2015-10-06 16:14:29 -04:00
|
|
|
|
const bool expect_success = geteuid() == 0;
|
|
|
|
|
|
2014-09-16 17:36:33 -04:00
|
|
|
|
base::mac::ScopedMachSendRight host(mach_host_self());
|
2015-10-20 11:03:25 -04:00
|
|
|
|
ExceptionPorts explicit_host_ports(ExceptionPorts::kTargetTypeHost,
|
|
|
|
|
host.get());
|
2015-08-19 18:47:51 -04:00
|
|
|
|
EXPECT_STREQ("host", explicit_host_ports.TargetTypeName());
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
2015-10-06 16:14:29 -04:00
|
|
|
|
ExceptionPorts::ExceptionHandlerVector explicit_handlers;
|
|
|
|
|
bool rv =
|
|
|
|
|
explicit_host_ports.GetExceptionPorts(ExcMaskValid(), &explicit_handlers);
|
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_EQ(rv, expect_success);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
ExceptionPorts implicit_host_ports(ExceptionPorts::kTargetTypeHost,
|
2014-10-13 12:59:21 -04:00
|
|
|
|
HOST_NULL);
|
2015-08-19 18:47:51 -04:00
|
|
|
|
EXPECT_STREQ("host", implicit_host_ports.TargetTypeName());
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
2015-10-06 16:14:29 -04:00
|
|
|
|
ExceptionPorts::ExceptionHandlerVector implicit_handlers;
|
|
|
|
|
rv =
|
|
|
|
|
implicit_host_ports.GetExceptionPorts(ExcMaskValid(), &implicit_handlers);
|
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_EQ(rv, expect_success);
|
2015-10-06 16:14:29 -04:00
|
|
|
|
|
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_EQ(implicit_handlers.size(), explicit_handlers.size());
|
2014-09-16 17:36:33 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
2014-10-07 17:28:50 -04:00
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace crashpad
|