2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-10-17 12:30:55 -04:00
|
|
|
|
//
|
|
|
|
|
// 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 "client/simulate_crash.h"
|
|
|
|
|
|
|
|
|
|
#include <mach/mach.h>
|
|
|
|
|
#include <string.h>
|
2016-01-06 12:22:50 -05:00
|
|
|
|
#include <sys/types.h>
|
2014-10-17 12:30:55 -04:00
|
|
|
|
|
2022-02-28 20:57:19 -08:00
|
|
|
|
#include <iterator>
|
|
|
|
|
|
2014-10-17 12:30:55 -04:00
|
|
|
|
#include "base/strings/stringprintf.h"
|
|
|
|
|
#include "build/build_config.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-10-17 12:30:55 -04:00
|
|
|
|
#include "util/mach/exc_server_variants.h"
|
|
|
|
|
#include "util/mach/exception_behaviors.h"
|
|
|
|
|
#include "util/mach/exception_ports.h"
|
|
|
|
|
#include "util/mach/mach_extensions.h"
|
2014-12-10 11:11:21 -05:00
|
|
|
|
#include "util/mach/mach_message.h"
|
2014-10-17 12:30:55 -04:00
|
|
|
|
#include "util/mach/mach_message_server.h"
|
|
|
|
|
#include "util/mach/symbolic_constants_mach.h"
|
2015-09-14 11:09:46 -07:00
|
|
|
|
#include "util/misc/implicit_cast.h"
|
2014-10-17 12:30:55 -04:00
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace test {
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
class TestSimulateCrashMac final : public MachMultiprocess,
|
2014-12-04 10:18:24 -05:00
|
|
|
|
public UniversalMachExcServer::Interface {
|
2014-10-17 12:30:55 -04:00
|
|
|
|
public:
|
|
|
|
|
// Defines which targets the child should set an EXC_CRASH exception handler
|
|
|
|
|
// for.
|
|
|
|
|
enum ExceptionPortsTarget {
|
|
|
|
|
// The child should clear its EXC_CRASH handler for both its task and thread
|
|
|
|
|
// targets. SimulateCrash() will attempt to deliver the exception to the
|
|
|
|
|
// host target, which will fail if not running as root. In any case, the
|
|
|
|
|
// parent should not expect to receive any exception message from the child.
|
|
|
|
|
kExceptionPortsTargetNone = 0,
|
|
|
|
|
|
|
|
|
|
// The child will set an EXC_CRASH handler for its task target, and clear it
|
|
|
|
|
// for its thread target. The parent runs an exception server to receive
|
|
|
|
|
// the child’s simulated crash message.
|
|
|
|
|
kExceptionPortsTargetTask,
|
|
|
|
|
|
|
|
|
|
// The child will set an EXC_CRASH handler for its thread target, and clear
|
|
|
|
|
// it for its task target. The parent runs an exception server to receive
|
|
|
|
|
// the child’s simulated crash message.
|
|
|
|
|
kExceptionPortsTargetThread,
|
|
|
|
|
|
|
|
|
|
// The child sets an EXC_CRASH handler for both its task and thread targets.
|
|
|
|
|
// The parent runs an exception server to receive the message expected to be
|
|
|
|
|
// delivered to the thread target, but returns an error code. The child will
|
|
|
|
|
// then fall back to trying the server registered for the task target,
|
|
|
|
|
// sending a second message to the parent. The server in the parent will
|
|
|
|
|
// handle this one successfully.
|
|
|
|
|
kExceptionPortsTargetBoth,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TestSimulateCrashMac(ExceptionPortsTarget target,
|
|
|
|
|
exception_behavior_t behavior,
|
|
|
|
|
thread_state_flavor_t flavor)
|
2014-12-04 10:18:24 -05:00
|
|
|
|
: MachMultiprocess(),
|
|
|
|
|
UniversalMachExcServer::Interface(),
|
|
|
|
|
target_(target),
|
2014-10-17 12:30:55 -04:00
|
|
|
|
behavior_(behavior),
|
|
|
|
|
flavor_(flavor),
|
|
|
|
|
succeed_(true) {
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-20 12:55:12 -07:00
|
|
|
|
TestSimulateCrashMac(const TestSimulateCrashMac&) = delete;
|
|
|
|
|
TestSimulateCrashMac& operator=(const TestSimulateCrashMac&) = delete;
|
|
|
|
|
|
2014-10-17 12:30:55 -04:00
|
|
|
|
~TestSimulateCrashMac() {}
|
|
|
|
|
|
2014-12-04 10:18:24 -05:00
|
|
|
|
// UniversalMachExcServer::Interface:
|
2014-10-17 12:30:55 -04:00
|
|
|
|
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-10-17 12:30:55 -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-10-17 12:30:55 -04:00
|
|
|
|
bool* destroy_complex_request) override {
|
|
|
|
|
*destroy_complex_request = true;
|
|
|
|
|
|
|
|
|
|
// Check the entire exception message, because most or all of it was
|
|
|
|
|
// generated by SimulateCrash() instead of the kernel.
|
|
|
|
|
|
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, behavior_);
|
|
|
|
|
EXPECT_EQ(exception_port, LocalPort());
|
2014-10-17 12:30:55 -04:00
|
|
|
|
if (ExceptionBehaviorHasIdentity(behavior)) {
|
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(thread, THREAD_NULL);
|
|
|
|
|
EXPECT_EQ(task, ChildTask());
|
2014-10-17 12:30:55 -04:00
|
|
|
|
} else {
|
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(thread, THREAD_NULL);
|
|
|
|
|
EXPECT_EQ(task, TASK_NULL);
|
2014-10-17 12:30:55 -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, kMachExceptionSimulated);
|
|
|
|
|
EXPECT_EQ(code_count, 2u);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
if (code_count >= 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(code[0], 0);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
}
|
|
|
|
|
if (code_count >= 2) {
|
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(code[1], 0);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
}
|
|
|
|
|
if (!ExceptionBehaviorHasState(behavior)) {
|
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(*flavor, THREAD_STATE_NONE);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
} else {
|
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(*flavor, flavor_);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
switch (*flavor) {
|
|
|
|
|
#if defined(ARCH_CPU_X86_FAMILY)
|
|
|
|
|
case x86_THREAD_STATE: {
|
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(old_state_count, x86_THREAD_STATE_COUNT);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
const x86_thread_state* state =
|
|
|
|
|
reinterpret_cast<const x86_thread_state*>(old_state);
|
|
|
|
|
switch (state->tsh.flavor) {
|
|
|
|
|
case x86_THREAD_STATE32:
|
2017-06-13 14:00:36 -04:00
|
|
|
|
EXPECT_EQ(implicit_cast<uint32_t>(state->tsh.count),
|
|
|
|
|
implicit_cast<uint32_t>(x86_THREAD_STATE32_COUNT));
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
case x86_THREAD_STATE64:
|
2017-06-13 14:00:36 -04:00
|
|
|
|
EXPECT_EQ(implicit_cast<uint32_t>(state->tsh.count),
|
|
|
|
|
implicit_cast<uint32_t>(x86_THREAD_STATE64_COUNT));
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ADD_FAILURE() << "unexpected tsh.flavor " << state->tsh.flavor;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case x86_FLOAT_STATE: {
|
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(old_state_count, x86_FLOAT_STATE_COUNT);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
const x86_float_state* state =
|
|
|
|
|
reinterpret_cast<const x86_float_state*>(old_state);
|
|
|
|
|
switch (state->fsh.flavor) {
|
|
|
|
|
case x86_FLOAT_STATE32:
|
2017-06-13 14:00:36 -04:00
|
|
|
|
EXPECT_EQ(implicit_cast<uint32_t>(state->fsh.count),
|
|
|
|
|
implicit_cast<uint32_t>(x86_FLOAT_STATE32_COUNT));
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
case x86_FLOAT_STATE64:
|
2017-06-13 14:00:36 -04:00
|
|
|
|
EXPECT_EQ(implicit_cast<uint32_t>(state->fsh.count),
|
|
|
|
|
implicit_cast<uint32_t>(x86_FLOAT_STATE64_COUNT));
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ADD_FAILURE() << "unexpected fsh.flavor " << state->fsh.flavor;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case x86_DEBUG_STATE: {
|
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(old_state_count, x86_DEBUG_STATE_COUNT);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
const x86_debug_state* state =
|
|
|
|
|
reinterpret_cast<const x86_debug_state*>(old_state);
|
|
|
|
|
switch (state->dsh.flavor) {
|
|
|
|
|
case x86_DEBUG_STATE32:
|
2017-06-13 14:00:36 -04:00
|
|
|
|
EXPECT_EQ(implicit_cast<uint32_t>(state->dsh.count),
|
|
|
|
|
implicit_cast<uint32_t>(x86_DEBUG_STATE32_COUNT));
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
case x86_DEBUG_STATE64:
|
2017-06-13 14:00:36 -04:00
|
|
|
|
EXPECT_EQ(implicit_cast<uint32_t>(state->dsh.count),
|
|
|
|
|
implicit_cast<uint32_t>(x86_DEBUG_STATE64_COUNT));
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ADD_FAILURE() << "unexpected dsh.flavor " << state->dsh.flavor;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case x86_THREAD_STATE32:
|
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(old_state_count, x86_THREAD_STATE32_COUNT);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
case x86_FLOAT_STATE32:
|
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(old_state_count, x86_FLOAT_STATE32_COUNT);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
case x86_DEBUG_STATE32:
|
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(old_state_count, x86_DEBUG_STATE32_COUNT);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
case x86_THREAD_STATE64:
|
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(old_state_count, x86_THREAD_STATE64_COUNT);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
case x86_FLOAT_STATE64:
|
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(old_state_count, x86_FLOAT_STATE64_COUNT);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
|
|
|
|
case x86_DEBUG_STATE64:
|
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(old_state_count, x86_DEBUG_STATE64_COUNT);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
break;
|
2020-07-07 23:43:46 -04:00
|
|
|
|
#elif defined(ARCH_CPU_ARM64)
|
|
|
|
|
case ARM_UNIFIED_THREAD_STATE: {
|
|
|
|
|
EXPECT_EQ(old_state_count, ARM_UNIFIED_THREAD_STATE_COUNT);
|
|
|
|
|
const arm_unified_thread_state* state =
|
|
|
|
|
reinterpret_cast<const arm_unified_thread_state*>(old_state);
|
|
|
|
|
EXPECT_EQ(state->ash.flavor,
|
|
|
|
|
implicit_cast<uint32_t>(ARM_THREAD_STATE64));
|
|
|
|
|
if (state->ash.flavor == ARM_THREAD_STATE64) {
|
|
|
|
|
EXPECT_EQ(state->ash.count,
|
|
|
|
|
implicit_cast<uint32_t>(ARM_THREAD_STATE64_COUNT));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ARM_THREAD_STATE64:
|
|
|
|
|
EXPECT_EQ(old_state_count, ARM_THREAD_STATE64_COUNT);
|
|
|
|
|
break;
|
|
|
|
|
case ARM_NEON_STATE64:
|
|
|
|
|
EXPECT_EQ(old_state_count, ARM_NEON_STATE64_COUNT);
|
|
|
|
|
break;
|
|
|
|
|
case ARM_DEBUG_STATE64:
|
|
|
|
|
EXPECT_EQ(old_state_count, ARM_DEBUG_STATE64_COUNT);
|
|
|
|
|
break;
|
2014-10-17 12:30:55 -04:00
|
|
|
|
#else
|
|
|
|
|
#error Port to your CPU architecture
|
|
|
|
|
#endif
|
|
|
|
|
default:
|
|
|
|
|
ADD_FAILURE() << "unexpected flavor " << *flavor;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Attempt to set a garbage thread state, which would cause the child to
|
|
|
|
|
// crash inside SimulateCrash() if it actually succeeded. This tests that
|
|
|
|
|
// SimulateCrash() ignores new_state instead of attempting to set the
|
|
|
|
|
// state as the kernel would do. This operates in conjunction with the
|
|
|
|
|
// |true| argument to ExcServerSuccessfulReturnValue() below.
|
|
|
|
|
*new_state_count = old_state_count;
|
|
|
|
|
size_t new_state_size = sizeof(natural_t) * old_state_count;
|
|
|
|
|
memset(new_state, 0xa5, new_state_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!succeed_) {
|
|
|
|
|
// The client has registered EXC_CRASH handlers for both its thread and
|
|
|
|
|
// task targets, and sent a simulated exception message to its
|
|
|
|
|
// thread-level EXC_CRASH handler. To test that it will fall back to
|
|
|
|
|
// trying the task-level EXC_CRASH handler, return a failure code, which
|
|
|
|
|
// should cause SimulateCrash() to try the next target.
|
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(target_, kExceptionPortsTargetBoth);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
return KERN_ABORTED;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-01 12:16:22 -04:00
|
|
|
|
ExcServerCopyState(
|
|
|
|
|
behavior, old_state, old_state_count, new_state, new_state_count);
|
|
|
|
|
|
2015-09-04 14:29:12 -04:00
|
|
|
|
return ExcServerSuccessfulReturnValue(exception, behavior, true);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// MachMultiprocess:
|
|
|
|
|
|
|
|
|
|
void MachMultiprocessParent() override {
|
|
|
|
|
if (target_ == kExceptionPortsTargetNone) {
|
|
|
|
|
// The child does not have any EXC_CRASH handlers registered for its
|
|
|
|
|
// thread or task targets, so no exception message is expected to be
|
|
|
|
|
// generated. Don’t run the server at all.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 10:18:24 -05:00
|
|
|
|
UniversalMachExcServer universal_mach_exc_server(this);
|
|
|
|
|
|
2014-10-17 12:30:55 -04:00
|
|
|
|
mach_msg_return_t mr;
|
|
|
|
|
if (target_ == kExceptionPortsTargetBoth) {
|
|
|
|
|
// The client has registered EXC_CRASH handlers for both its thread and
|
|
|
|
|
// task targets. Run a server that will return a failure code when the
|
|
|
|
|
// exception message is sent to the thread target, which will cause the
|
|
|
|
|
// client to fall back to the task target and send another message.
|
|
|
|
|
succeed_ = false;
|
2014-12-04 10:18:24 -05:00
|
|
|
|
mr = MachMessageServer::Run(&universal_mach_exc_server,
|
2014-10-17 12:30:55 -04:00
|
|
|
|
LocalPort(),
|
|
|
|
|
MACH_MSG_OPTION_NONE,
|
|
|
|
|
MachMessageServer::kOneShot,
|
2014-11-25 14:48:44 -05:00
|
|
|
|
MachMessageServer::kReceiveLargeError,
|
2014-12-10 11:11:21 -05:00
|
|
|
|
kMachMessageTimeoutWaitIndefinitely);
|
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(mr, MACH_MSG_SUCCESS)
|
2014-10-17 12:30:55 -04:00
|
|
|
|
<< MachErrorMessage(mr, "MachMessageServer::Run");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
succeed_ = true;
|
2014-12-04 10:18:24 -05:00
|
|
|
|
mr = MachMessageServer::Run(&universal_mach_exc_server,
|
2014-10-17 12:30:55 -04:00
|
|
|
|
LocalPort(),
|
|
|
|
|
MACH_MSG_OPTION_NONE,
|
|
|
|
|
MachMessageServer::kOneShot,
|
2014-11-25 14:48:44 -05:00
|
|
|
|
MachMessageServer::kReceiveLargeError,
|
2014-12-10 11:11:21 -05:00
|
|
|
|
kMachMessageTimeoutWaitIndefinitely);
|
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(mr, MACH_MSG_SUCCESS)
|
2014-10-17 12:30:55 -04:00
|
|
|
|
<< MachErrorMessage(mr, "MachMessageServer::Run");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MachMultiprocessChild() override {
|
|
|
|
|
bool task_valid = target_ == kExceptionPortsTargetTask ||
|
|
|
|
|
target_ == kExceptionPortsTargetBoth;
|
|
|
|
|
ExceptionPorts task_exception_ports(ExceptionPorts::kTargetTypeTask,
|
|
|
|
|
TASK_NULL);
|
|
|
|
|
ASSERT_TRUE(task_exception_ports.SetExceptionPort(
|
|
|
|
|
EXC_MASK_CRASH,
|
|
|
|
|
task_valid ? RemotePort() : MACH_PORT_NULL,
|
|
|
|
|
behavior_,
|
|
|
|
|
flavor_));
|
|
|
|
|
|
|
|
|
|
bool thread_valid = target_ == kExceptionPortsTargetThread ||
|
|
|
|
|
target_ == kExceptionPortsTargetBoth;
|
|
|
|
|
ExceptionPorts thread_exception_ports(ExceptionPorts::kTargetTypeThread,
|
|
|
|
|
THREAD_NULL);
|
|
|
|
|
ASSERT_TRUE(thread_exception_ports.SetExceptionPort(
|
|
|
|
|
EXC_MASK_CRASH,
|
|
|
|
|
thread_valid ? RemotePort() : MACH_PORT_NULL,
|
|
|
|
|
behavior_,
|
|
|
|
|
flavor_));
|
|
|
|
|
|
|
|
|
|
CRASHPAD_SIMULATE_CRASH();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExceptionPortsTarget target_;
|
|
|
|
|
exception_behavior_t behavior_;
|
|
|
|
|
thread_state_flavor_t flavor_;
|
|
|
|
|
bool succeed_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST(SimulateCrash, SimulateCrash) {
|
2017-07-25 13:34:04 -04:00
|
|
|
|
static constexpr TestSimulateCrashMac::ExceptionPortsTarget kTargets[] = {
|
2014-10-17 12:30:55 -04:00
|
|
|
|
TestSimulateCrashMac::kExceptionPortsTargetNone,
|
|
|
|
|
TestSimulateCrashMac::kExceptionPortsTargetTask,
|
|
|
|
|
TestSimulateCrashMac::kExceptionPortsTargetThread,
|
|
|
|
|
TestSimulateCrashMac::kExceptionPortsTargetBoth,
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-25 13:34:04 -04:00
|
|
|
|
static constexpr exception_behavior_t kBehaviors[] = {
|
2014-10-17 12:30:55 -04:00
|
|
|
|
EXCEPTION_DEFAULT,
|
|
|
|
|
EXCEPTION_STATE,
|
|
|
|
|
EXCEPTION_STATE_IDENTITY,
|
|
|
|
|
EXCEPTION_DEFAULT | kMachExceptionCodes,
|
|
|
|
|
EXCEPTION_STATE | kMachExceptionCodes,
|
|
|
|
|
EXCEPTION_STATE_IDENTITY | kMachExceptionCodes,
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-25 13:34:04 -04:00
|
|
|
|
static constexpr thread_state_flavor_t kFlavors[] = {
|
2014-10-17 12:30:55 -04:00
|
|
|
|
#if defined(ARCH_CPU_X86_FAMILY)
|
2020-07-07 23:43:46 -04:00
|
|
|
|
x86_THREAD_STATE,
|
|
|
|
|
x86_FLOAT_STATE,
|
|
|
|
|
x86_DEBUG_STATE,
|
2014-10-17 12:30:55 -04:00
|
|
|
|
#if defined(ARCH_CPU_X86)
|
2020-07-07 23:43:46 -04:00
|
|
|
|
x86_THREAD_STATE32,
|
|
|
|
|
x86_FLOAT_STATE32,
|
|
|
|
|
x86_DEBUG_STATE32,
|
2014-10-17 12:30:55 -04:00
|
|
|
|
#elif defined(ARCH_CPU_X86_64)
|
2020-07-07 23:43:46 -04:00
|
|
|
|
x86_THREAD_STATE64,
|
|
|
|
|
x86_FLOAT_STATE64,
|
|
|
|
|
x86_DEBUG_STATE64,
|
2014-10-17 12:30:55 -04:00
|
|
|
|
#endif
|
2020-07-07 23:43:46 -04:00
|
|
|
|
#elif defined(ARCH_CPU_ARM64)
|
|
|
|
|
ARM_UNIFIED_THREAD_STATE,
|
|
|
|
|
ARM_THREAD_STATE64,
|
|
|
|
|
ARM_NEON_STATE64,
|
|
|
|
|
ARM_DEBUG_STATE64,
|
2014-10-17 12:30:55 -04:00
|
|
|
|
#else
|
|
|
|
|
#error Port to your CPU architecture
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-28 20:57:19 -08:00
|
|
|
|
for (size_t target_index = 0; target_index < std::size(kTargets);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
++target_index) {
|
|
|
|
|
TestSimulateCrashMac::ExceptionPortsTarget target = kTargets[target_index];
|
|
|
|
|
SCOPED_TRACE(base::StringPrintf(
|
|
|
|
|
"target_index %zu, target %d", target_index, target));
|
|
|
|
|
|
2022-02-28 20:57:19 -08:00
|
|
|
|
for (size_t behavior_index = 0; behavior_index < std::size(kBehaviors);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
++behavior_index) {
|
|
|
|
|
exception_behavior_t behavior = kBehaviors[behavior_index];
|
|
|
|
|
SCOPED_TRACE(base::StringPrintf(
|
|
|
|
|
"behavior_index %zu, behavior %s",
|
|
|
|
|
behavior_index,
|
|
|
|
|
ExceptionBehaviorToString(behavior, kUseFullName | kUnknownIsNumeric)
|
|
|
|
|
.c_str()));
|
|
|
|
|
|
|
|
|
|
if (!ExceptionBehaviorHasState(behavior)) {
|
|
|
|
|
TestSimulateCrashMac test_simulate_crash_mac(
|
|
|
|
|
target, behavior, THREAD_STATE_NONE);
|
|
|
|
|
test_simulate_crash_mac.Run();
|
|
|
|
|
} else {
|
2022-02-28 20:57:19 -08:00
|
|
|
|
for (size_t flavor_index = 0; flavor_index < std::size(kFlavors);
|
2014-10-17 12:30:55 -04:00
|
|
|
|
++flavor_index) {
|
|
|
|
|
thread_state_flavor_t flavor = kFlavors[flavor_index];
|
|
|
|
|
SCOPED_TRACE(base::StringPrintf(
|
|
|
|
|
"flavor_index %zu, flavor %s",
|
|
|
|
|
flavor_index,
|
|
|
|
|
ThreadStateFlavorToString(
|
|
|
|
|
flavor, kUseFullName | kUnknownIsNumeric).c_str()));
|
|
|
|
|
|
|
|
|
|
TestSimulateCrashMac test_simulate_crash_mac(
|
|
|
|
|
target, behavior, flavor);
|
|
|
|
|
test_simulate_crash_mac.Run();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace crashpad
|