2014-09-16 09:48:01 -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/exc_client_variants.h"
|
|
|
|
|
|
|
|
|
|
#include <mach/mach.h>
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <string.h>
|
2016-01-06 12:22:50 -05:00
|
|
|
|
#include <sys/types.h>
|
2014-09-16 09:48:01 -04:00
|
|
|
|
|
2021-05-25 14:24:55 -07:00
|
|
|
|
#include "base/cxx17_backports.h"
|
2016-01-06 12:22:50 -05:00
|
|
|
|
#include "base/macros.h"
|
2014-09-16 09:48:01 -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-09-16 09:48:01 -04:00
|
|
|
|
#include "util/mach/exc_server_variants.h"
|
2014-09-16 17:32:35 -04:00
|
|
|
|
#include "util/mach/exception_behaviors.h"
|
2014-09-16 09:48:01 -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"
|
2015-09-14 14:51:05 -07:00
|
|
|
|
#include "util/misc/implicit_cast.h"
|
2014-09-16 09:48:01 -04:00
|
|
|
|
|
2014-10-07 17:28:50 -04:00
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace test {
|
2014-09-16 09:48:01 -04:00
|
|
|
|
namespace {
|
|
|
|
|
|
2014-12-04 10:18:24 -05:00
|
|
|
|
class TestExcClientVariants : public MachMultiprocess,
|
|
|
|
|
public UniversalMachExcServer::Interface {
|
2014-09-16 09:48:01 -04:00
|
|
|
|
public:
|
|
|
|
|
TestExcClientVariants(exception_behavior_t behavior, bool all_fields)
|
2014-12-04 10:18:24 -05:00
|
|
|
|
: MachMultiprocess(),
|
|
|
|
|
UniversalMachExcServer::Interface(),
|
2014-09-16 09:48:01 -04:00
|
|
|
|
behavior_(behavior),
|
|
|
|
|
all_fields_(all_fields),
|
|
|
|
|
handled_(false) {
|
|
|
|
|
++exception_;
|
|
|
|
|
++exception_code_;
|
|
|
|
|
++exception_subcode_;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 10:18:24 -05:00
|
|
|
|
// UniversalMachExcServer::Interface:
|
2014-09-16 09:48:01 -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 09:48:01 -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 09:48:01 -04:00
|
|
|
|
bool* destroy_complex_request) override {
|
|
|
|
|
*destroy_complex_request = true;
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(handled_);
|
|
|
|
|
handled_ = 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(behavior, behavior_);
|
|
|
|
|
EXPECT_EQ(exception_port, LocalPort());
|
2014-09-16 09:48:01 -04:00
|
|
|
|
|
|
|
|
|
if (HasIdentity()) {
|
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-09-16 09:48:01 -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-09-16 09:48:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mach_exception_code_t expect_code = exception_code_;
|
|
|
|
|
mach_exception_subcode_t expect_subcode = exception_subcode_;
|
|
|
|
|
if ((behavior & MACH_EXCEPTION_CODES) == 0) {
|
2014-11-06 16:44:38 -05:00
|
|
|
|
expect_code = implicit_cast<exception_data_type_t>(expect_code);
|
|
|
|
|
expect_subcode = implicit_cast<exception_data_type_t>(expect_subcode);
|
2014-09-16 09:48:01 -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, exception_);
|
|
|
|
|
EXPECT_EQ(code_count, 2u);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
|
|
|
|
|
// The code_count check above would ideally use ASSERT_EQ so that the next
|
|
|
|
|
// conditionals would not be necessary, but ASSERT_* requires a function
|
|
|
|
|
// returning type void, and the interface dictates otherwise here.
|
|
|
|
|
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], expect_code);
|
2014-09-16 17:36:33 -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], expect_subcode);
|
2014-09-16 17:36:33 -04:00
|
|
|
|
}
|
2014-09-16 09:48:01 -04:00
|
|
|
|
|
|
|
|
|
if (HasState()) {
|
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, exception_ + 10);
|
|
|
|
|
EXPECT_EQ(old_state_count, MACHINE_THREAD_STATE_COUNT);
|
|
|
|
|
EXPECT_NE(old_state, nullptr);
|
|
|
|
|
EXPECT_EQ(*new_state_count,
|
|
|
|
|
implicit_cast<mach_msg_type_number_t>(THREAD_STATE_MAX));
|
|
|
|
|
EXPECT_NE(new_state, nullptr);
|
2014-09-16 09:48:01 -04:00
|
|
|
|
|
|
|
|
|
for (size_t index = 0; index < old_state_count; ++index) {
|
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[index], index);
|
2014-09-16 09:48:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use a flavor known to be different from the incoming flavor, for a test
|
doc: Fix all Doxygen warnings, cleaning up some generated documentation
This makes Doxygen’s output more actionable by setting QUIET = YES to
suppress verbose progress spew, and WARN_IF_UNDOCUMENTED = NO to prevent
warnings for undocumented classes and members from being generated. The
latter is too noisy, producing 721 warnings in the current codebase.
The remaining warnings produced by Doxygen were useful and actionable.
They fell into two categories: abuses of Doxygen’s markup syntax, and
missing (or misspelled) parameter documentation. In a small number of
cases, pass-through parameters had intentionally been left undocumented.
In these cases, they are now given blank \param descriptions. This is
not optimal, but there doesn’t appear to be any other way to tell
Doxygen to allow a single parameter to be undocumented.
Some tricky Doxygen errors were resolved by asking it to not enter
directiores that we do not provide documentation in (such as the
“on-platform” compat directories, compat/mac and compat/win, as well as
compat/non_cxx11_lib) while allowing it to enter the
“off-platform” directories that we do document (compat/non_mac and
compat/non_win).
A Doxygen run (doc/support/generate_doxygen.sh) now produces no output
at all. It would produce warnings if any were triggered.
Not directly related, but still relevant to documentation,
doc/support/generate.sh is updated to remove temporary removals of
now-extinct files and directories. doc/appengine/README is updated so
that a consistent path to “goapp” is used throughout the file.
Change-Id: I300730c04de4d3340551ea3086ca70cc5ff862d1
Reviewed-on: https://chromium-review.googlesource.com/408812
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-08 14:23:09 -05:00
|
|
|
|
// of the “out” side of the in-out flavor parameter.
|
2014-09-16 09:48:01 -04:00
|
|
|
|
*flavor = exception_ + 20;
|
|
|
|
|
*new_state_count = MACHINE_THREAD_STATE_COUNT;
|
|
|
|
|
|
|
|
|
|
// Send a new state back to the client.
|
|
|
|
|
for (size_t index = 0; index < *new_state_count; ++index) {
|
|
|
|
|
new_state[index] = MACHINE_THREAD_STATE_COUNT - index;
|
|
|
|
|
}
|
|
|
|
|
} 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, THREAD_STATE_NONE);
|
|
|
|
|
EXPECT_EQ(old_state_count, 0u);
|
|
|
|
|
EXPECT_EQ(old_state, nullptr);
|
|
|
|
|
EXPECT_EQ(*new_state_count, 0u);
|
|
|
|
|
EXPECT_EQ(new_state, nullptr);
|
2014-09-16 09:48:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return KERN_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// MachMultiprocess:
|
|
|
|
|
|
2014-10-14 11:11:57 -04:00
|
|
|
|
void MachMultiprocessParent() override {
|
2014-12-04 10:18:24 -05:00
|
|
|
|
UniversalMachExcServer universal_mach_exc_server(this);
|
|
|
|
|
|
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
|
|
|
|
LocalPort(),
|
|
|
|
|
MACH_MSG_OPTION_NONE,
|
|
|
|
|
MachMessageServer::kOneShot,
|
|
|
|
|
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(kr, KERN_SUCCESS)
|
2014-09-16 09:48:01 -04:00
|
|
|
|
<< MachErrorMessage(kr, "MachMessageServer::Run");
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(handled_);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 11:11:57 -04:00
|
|
|
|
void MachMultiprocessChild() override {
|
2014-09-16 09:48:01 -04:00
|
|
|
|
const exception_type_t exception = exception_;
|
|
|
|
|
const mach_exception_data_type_t code[] = {
|
|
|
|
|
exception_code_,
|
|
|
|
|
exception_subcode_
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-13 12:59:21 -04:00
|
|
|
|
thread_t thread = THREAD_NULL;
|
|
|
|
|
task_t task = TASK_NULL;
|
2014-09-16 09:48:01 -04:00
|
|
|
|
if (all_fields_ || HasIdentity()) {
|
|
|
|
|
thread = MachThreadSelf();
|
|
|
|
|
task = mach_task_self();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
thread_state_flavor_t flavor;
|
2014-10-14 11:10:45 -04:00
|
|
|
|
thread_state_flavor_t* flavor_p = nullptr;
|
2014-09-16 09:48:01 -04:00
|
|
|
|
natural_t old_state[MACHINE_THREAD_STATE_COUNT];
|
2014-10-14 11:10:45 -04:00
|
|
|
|
thread_state_t old_state_p = nullptr;
|
2014-09-16 09:48:01 -04:00
|
|
|
|
mach_msg_type_number_t old_state_count = 0;
|
|
|
|
|
natural_t new_state[THREAD_STATE_MAX];
|
2014-10-14 11:10:45 -04:00
|
|
|
|
thread_state_t new_state_p = nullptr;
|
2014-09-16 09:48:01 -04:00
|
|
|
|
mach_msg_type_number_t new_state_count;
|
2014-10-14 11:10:45 -04:00
|
|
|
|
mach_msg_type_number_t* new_state_count_p = nullptr;
|
2014-09-16 09:48:01 -04:00
|
|
|
|
if (all_fields_ || HasState()) {
|
|
|
|
|
// Pick a different flavor each time based on the value of exception_.
|
|
|
|
|
// These aren’t real flavors, it’s just for testing.
|
|
|
|
|
flavor = exception_ + 10;
|
|
|
|
|
flavor_p = &flavor;
|
2019-01-04 16:57:57 -05:00
|
|
|
|
for (size_t index = 0; index < base::size(old_state); ++index) {
|
2014-09-16 09:48:01 -04:00
|
|
|
|
old_state[index] = index;
|
|
|
|
|
}
|
|
|
|
|
old_state_p = reinterpret_cast<thread_state_t>(&old_state);
|
2019-01-04 16:57:57 -05:00
|
|
|
|
old_state_count = base::size(old_state);
|
2014-09-16 09:48:01 -04:00
|
|
|
|
|
|
|
|
|
// new_state and new_state_count are out parameters that the server should
|
|
|
|
|
// never see or use, so set them to bogus values. The call to the server
|
|
|
|
|
// should overwrite these.
|
|
|
|
|
memset(new_state, 0xa5, sizeof(new_state));
|
|
|
|
|
new_state_p = reinterpret_cast<thread_state_t>(&new_state);
|
|
|
|
|
new_state_count = 0x5a;
|
|
|
|
|
new_state_count_p = &new_state_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
|
|
|
|
EXPECT_EQ(UniversalExceptionRaise(behavior_,
|
|
|
|
|
RemotePort(),
|
|
|
|
|
thread,
|
|
|
|
|
task,
|
|
|
|
|
exception,
|
|
|
|
|
code,
|
2019-01-04 16:57:57 -05:00
|
|
|
|
base::size(code),
|
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
|
|
|
|
flavor_p,
|
|
|
|
|
old_state_p,
|
|
|
|
|
old_state_count,
|
|
|
|
|
new_state_p,
|
|
|
|
|
new_state_count_p),
|
|
|
|
|
KERN_SUCCESS);
|
2014-09-16 09:48:01 -04:00
|
|
|
|
|
|
|
|
|
if (HasState()) {
|
|
|
|
|
// Verify the out parameters.
|
|
|
|
|
|
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, exception_ + 20);
|
|
|
|
|
EXPECT_EQ(new_state_count, MACHINE_THREAD_STATE_COUNT);
|
2014-09-16 09:48:01 -04:00
|
|
|
|
|
|
|
|
|
for (size_t index = 0; index < new_state_count; ++index) {
|
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(new_state[index], MACHINE_THREAD_STATE_COUNT - index);
|
2014-09-16 09:48:01 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool HasIdentity() const {
|
2014-09-16 17:32:35 -04:00
|
|
|
|
return ExceptionBehaviorHasIdentity(behavior_);
|
2014-09-16 09:48:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool HasState() const {
|
2014-09-16 17:32:35 -04:00
|
|
|
|
return ExceptionBehaviorHasState(behavior_);
|
2014-09-16 09:48:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The behavior to test.
|
|
|
|
|
exception_behavior_t behavior_;
|
|
|
|
|
|
|
|
|
|
// If false, only fields required for the current value of behavior_ are set
|
|
|
|
|
// in a call to UniversalExceptionRaise(). The thread and task fields are only
|
|
|
|
|
// set for identity-carrying behaviors, and the flavor and state fields are
|
|
|
|
|
// only set for state-carrying behaviors. If true, all fields are set
|
|
|
|
|
// regardless of the behavior. Testing in both ways verifies that
|
|
|
|
|
// UniversalExceptionRaise() can tolerate the null arguments documented as
|
|
|
|
|
// usable when the behavior allows it, and that it ignores these arguments
|
|
|
|
|
// even when set when the behavior does not make use of them.
|
|
|
|
|
bool all_fields_;
|
|
|
|
|
|
|
|
|
|
// true if an exception message was handled.
|
|
|
|
|
bool handled_;
|
|
|
|
|
|
|
|
|
|
// These fields will increment for each instantiation of the test class.
|
|
|
|
|
static exception_type_t exception_;
|
|
|
|
|
static mach_exception_code_t exception_code_;
|
|
|
|
|
static mach_exception_subcode_t exception_subcode_;
|
|
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestExcClientVariants);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exception_type_t TestExcClientVariants::exception_ = 0;
|
|
|
|
|
|
|
|
|
|
// exception_code_ and exception_subcode_ are always large enough to require
|
|
|
|
|
// 64 bits, so that when the 32-bit-only variants not using MACH_EXCEPITON_CODES
|
|
|
|
|
// are tested, the code and subcode fields can be checked for proper truncation.
|
|
|
|
|
mach_exception_code_t TestExcClientVariants::exception_code_ = 0x100000000;
|
|
|
|
|
mach_exception_subcode_t TestExcClientVariants::exception_subcode_ =
|
|
|
|
|
0xffffffff00000000;
|
|
|
|
|
|
|
|
|
|
TEST(ExcClientVariants, UniversalExceptionRaise) {
|
2017-07-25 13:34:04 -04:00
|
|
|
|
static constexpr exception_behavior_t kBehaviors[] = {
|
2014-09-16 09:48:01 -04:00
|
|
|
|
EXCEPTION_DEFAULT,
|
|
|
|
|
EXCEPTION_STATE,
|
|
|
|
|
EXCEPTION_STATE_IDENTITY,
|
|
|
|
|
kMachExceptionCodes | EXCEPTION_DEFAULT,
|
|
|
|
|
kMachExceptionCodes | EXCEPTION_STATE,
|
|
|
|
|
kMachExceptionCodes | EXCEPTION_STATE_IDENTITY,
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-04 16:57:57 -05:00
|
|
|
|
for (size_t index = 0; index < base::size(kBehaviors); ++index) {
|
2014-09-16 09:48:01 -04:00
|
|
|
|
exception_behavior_t behavior = kBehaviors[index];
|
|
|
|
|
SCOPED_TRACE(base::StringPrintf("index %zu, behavior %d", index, behavior));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
SCOPED_TRACE("all_fields = false");
|
|
|
|
|
|
|
|
|
|
TestExcClientVariants test_exc_client_variants(behavior, false);
|
|
|
|
|
test_exc_client_variants.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
SCOPED_TRACE("all_fields = true");
|
|
|
|
|
|
|
|
|
|
TestExcClientVariants test_exc_client_variants(behavior, true);
|
|
|
|
|
test_exc_client_variants.Run();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
2014-10-07 17:28:50 -04:00
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace crashpad
|