2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-10-17 13:47:02 -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 "snapshot/mac/mach_o_image_annotations_reader.h"
|
|
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#include <mach/mach.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2016-01-06 12:22:50 -05:00
|
|
|
|
#include <sys/types.h>
|
2014-10-17 13:47:02 -04:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2015-08-05 18:24:53 -04:00
|
|
|
|
#include "base/files/file_path.h"
|
2017-10-31 17:14:27 -04:00
|
|
|
|
#include "client/annotation.h"
|
|
|
|
|
#include "client/annotation_list.h"
|
2014-10-17 13:47:02 -04:00
|
|
|
|
#include "client/crashpad_info.h"
|
|
|
|
|
#include "client/simple_string_dictionary.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
2018-02-22 12:12:26 -08:00
|
|
|
|
#include "snapshot/mac/process_reader_mac.h"
|
test: Move util/test to its own top-level directory, test.
After 9e79ea1da719, it no longer makes sense for crashpad_util_test_lib
to “hide” in util/util_test.gyp. All of util/test is moved to its own
top-level directory, test, which all other test code is allowed to
depend on. test, too, is allowed to depend on all other non-test code.
In a future change, when crashpad_util_test_lib gains a dependency on
crashpad_client, it won’t look so weird for something in util (even
though it’s in util/test) to depend on something in client, because the
thing that needs to depend on client will live in test, not util.
BUG=crashpad:33
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/1051533002
2015-03-31 17:44:14 -04:00
|
|
|
|
#include "test/errors.h"
|
|
|
|
|
#include "test/mac/mach_errors.h"
|
|
|
|
|
#include "test/mac/mach_multiprocess.h"
|
2017-04-03 13:53:11 -04:00
|
|
|
|
#include "test/test_paths.h"
|
2014-12-17 14:35:18 -08:00
|
|
|
|
#include "util/file/file_io.h"
|
2014-10-17 13:47:02 -04:00
|
|
|
|
#include "util/mac/mac_util.h"
|
|
|
|
|
#include "util/mach/exc_server_variants.h"
|
|
|
|
|
#include "util/mach/exception_ports.h"
|
2015-04-02 15:28:28 -04:00
|
|
|
|
#include "util/mach/mach_extensions.h"
|
2014-12-10 11:11:21 -05:00
|
|
|
|
#include "util/mach/mach_message.h"
|
2014-10-17 13:47:02 -04:00
|
|
|
|
#include "util/mach/mach_message_server.h"
|
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace test {
|
|
|
|
|
namespace {
|
|
|
|
|
|
2015-08-07 13:59:45 -04:00
|
|
|
|
// \return The path to crashpad_snapshot_test_module_crashy_initializer.so
|
2017-11-01 10:37:01 -04:00
|
|
|
|
base::FilePath ModuleWithCrashyInitializer() {
|
|
|
|
|
return TestPaths::BuildArtifact("snapshot",
|
|
|
|
|
"module_crashy_initializer",
|
|
|
|
|
TestPaths::FileType::kLoadableModule);
|
2015-08-07 13:59:45 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-05 18:24:53 -04:00
|
|
|
|
//! \return The path to the crashpad_snapshot_test_no_op executable.
|
|
|
|
|
base::FilePath NoOpExecutable() {
|
2017-11-01 10:37:01 -04:00
|
|
|
|
return TestPaths::BuildArtifact(
|
|
|
|
|
"snapshot", "no_op", TestPaths::FileType::kExecutable);
|
2015-08-05 18:24:53 -04:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 10:18:24 -05:00
|
|
|
|
class TestMachOImageAnnotationsReader final
|
|
|
|
|
: public MachMultiprocess,
|
|
|
|
|
public UniversalMachExcServer::Interface {
|
2014-10-17 13:47:02 -04:00
|
|
|
|
public:
|
|
|
|
|
enum TestType {
|
|
|
|
|
// Don’t crash, just test the CrashpadInfo interface.
|
|
|
|
|
kDontCrash = 0,
|
|
|
|
|
|
|
|
|
|
// The child process should crash by calling abort(). The parent verifies
|
|
|
|
|
// that the system libraries set the expected annotations.
|
2015-08-07 13:59:45 -04:00
|
|
|
|
//
|
|
|
|
|
// This test verifies that the message field in crashreporter_annotations_t
|
|
|
|
|
// can be recovered. Either 10.10.2 Libc-1044.1.2/stdlib/FreeBSD/abort.c
|
|
|
|
|
// abort() or 10.10.2 Libc-1044.10.1/sys/_libc_fork_child.c
|
|
|
|
|
// _libc_fork_child() calls CRSetCrashLogMessage() to set the message field.
|
2014-10-17 13:47:02 -04:00
|
|
|
|
kCrashAbort,
|
|
|
|
|
|
2015-08-07 13:59:45 -04:00
|
|
|
|
// The child process should crash at module initialization time, when dyld
|
|
|
|
|
// will have set an annotation matching the path of the module being
|
|
|
|
|
// initialized.
|
|
|
|
|
//
|
|
|
|
|
// This test exists to verify that the message2 field in
|
|
|
|
|
// crashreporter_annotations_t can be recovered. 10.10.2
|
|
|
|
|
// dyld-353.2.1/src/ImageLoaderMachO.cpp
|
|
|
|
|
// ImageLoaderMachO::doInitialization() calls CRSetCrashLogMessage2() to set
|
|
|
|
|
// the message2 field.
|
|
|
|
|
kCrashModuleInitialization,
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
// The child process should crash by setting DYLD_INSERT_LIBRARIES to
|
|
|
|
|
// contain a nonexistent library. The parent verifies that dyld sets the
|
|
|
|
|
// expected annotations.
|
|
|
|
|
kCrashDyld,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
explicit TestMachOImageAnnotationsReader(TestType test_type)
|
|
|
|
|
: MachMultiprocess(),
|
2014-12-04 10:18:24 -05:00
|
|
|
|
UniversalMachExcServer::Interface(),
|
2014-10-17 13:47:02 -04:00
|
|
|
|
test_type_(test_type) {
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
switch (test_type_) {
|
|
|
|
|
case kDontCrash:
|
|
|
|
|
// SetExpectedChildTermination(kTerminationNormal, EXIT_SUCCESS) is the
|
|
|
|
|
// default.
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kCrashAbort:
|
|
|
|
|
SetExpectedChildTermination(kTerminationSignal, SIGABRT);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kCrashModuleInitialization:
|
2020-09-01 01:16:21 -04:00
|
|
|
|
SetExpectedChildTerminationBuiltinTrap();
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kCrashDyld:
|
|
|
|
|
// Prior to 10.12, dyld fatal errors result in the execution of an
|
|
|
|
|
// int3 instruction on x86 and a trap instruction on ARM, both of
|
|
|
|
|
// which raise SIGTRAP. 10.9.5 dyld-239.4/src/dyldStartup.s
|
|
|
|
|
// _dyld_fatal_error. This changed in 10.12 to use
|
|
|
|
|
// abort_with_payload(), which appears as SIGABRT to a waiting parent.
|
|
|
|
|
SetExpectedChildTermination(
|
2020-09-01 17:09:37 -04:00
|
|
|
|
kTerminationSignal,
|
|
|
|
|
MacOSVersionNumber() < 10'12'00 ? SIGTRAP : SIGABRT);
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
|
break;
|
|
|
|
|
}
|
2014-10-17 13:47:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-20 12:55:12 -07:00
|
|
|
|
TestMachOImageAnnotationsReader(const TestMachOImageAnnotationsReader&) =
|
|
|
|
|
delete;
|
|
|
|
|
TestMachOImageAnnotationsReader& operator=(
|
|
|
|
|
const TestMachOImageAnnotationsReader&) = delete;
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
~TestMachOImageAnnotationsReader() {}
|
|
|
|
|
|
2014-12-04 10:18:24 -05:00
|
|
|
|
// UniversalMachExcServer::Interface:
|
2014-10-17 13:47:02 -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 13:47:02 -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 13:47:02 -04:00
|
|
|
|
bool* destroy_complex_request) override {
|
|
|
|
|
*destroy_complex_request = true;
|
|
|
|
|
|
2017-03-07 17:12:22 -05:00
|
|
|
|
if (test_type_ != kCrashDyld) {
|
|
|
|
|
// In 10.12.1 and later, the task port will not match ChildTask() in the
|
|
|
|
|
// kCrashDyld case, because kCrashDyld uses execl(), which results in a
|
|
|
|
|
// new task port being assigned.
|
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(task, ChildTask());
|
2017-03-07 17:12:22 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The process ID should always compare favorably.
|
2016-11-02 20:06:39 -04:00
|
|
|
|
pid_t task_pid;
|
|
|
|
|
kern_return_t kr = pid_for_task(task, &task_pid);
|
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) << MachErrorMessage(kr, "pid_for_task");
|
|
|
|
|
EXPECT_EQ(task_pid, ChildPID());
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
2018-02-22 12:12:26 -08:00
|
|
|
|
ProcessReaderMac process_reader;
|
2014-10-17 13:47:02 -04:00
|
|
|
|
bool rv = process_reader.Initialize(task);
|
|
|
|
|
if (!rv) {
|
|
|
|
|
ADD_FAILURE();
|
|
|
|
|
} else {
|
2018-02-22 12:12:26 -08:00
|
|
|
|
const std::vector<ProcessReaderMac::Module>& modules =
|
2014-10-17 13:47:02 -04:00
|
|
|
|
process_reader.Modules();
|
|
|
|
|
std::vector<std::string> all_annotations_vector;
|
2018-02-22 12:12:26 -08:00
|
|
|
|
for (const ProcessReaderMac::Module& module : modules) {
|
2015-03-08 21:02:42 -04:00
|
|
|
|
if (module.reader) {
|
|
|
|
|
MachOImageAnnotationsReader module_annotations_reader(
|
|
|
|
|
&process_reader, module.reader, module.name);
|
|
|
|
|
std::vector<std::string> module_annotations_vector =
|
|
|
|
|
module_annotations_reader.Vector();
|
|
|
|
|
all_annotations_vector.insert(all_annotations_vector.end(),
|
|
|
|
|
module_annotations_vector.begin(),
|
|
|
|
|
module_annotations_vector.end());
|
|
|
|
|
} else {
|
|
|
|
|
EXPECT_TRUE(module.reader);
|
|
|
|
|
}
|
2014-10-17 13:47:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mac OS X 10.6 doesn’t have support for CrashReporter annotations
|
|
|
|
|
// (CrashReporterClient.h), so don’t look for any special annotations in
|
|
|
|
|
// that version.
|
2020-09-01 17:09:37 -04:00
|
|
|
|
const int macos_version_number = MacOSVersionNumber();
|
|
|
|
|
if (macos_version_number > 10'07'00) {
|
2014-10-17 13:47:02 -04:00
|
|
|
|
EXPECT_GE(all_annotations_vector.size(), 1u);
|
|
|
|
|
|
2015-08-07 13:59:45 -04:00
|
|
|
|
std::string expected_annotation;
|
2014-10-17 13:47:02 -04:00
|
|
|
|
switch (test_type_) {
|
|
|
|
|
case kCrashAbort:
|
|
|
|
|
// The child process calls abort(), so the expected annotation
|
|
|
|
|
// reflects this, with a string set by 10.7.5
|
|
|
|
|
// Libc-763.13/stdlib/abort-fbsd.c abort(). This string is still
|
|
|
|
|
// present in 10.9.5 Libc-997.90.3/stdlib/FreeBSD/abort.c abort(),
|
|
|
|
|
// but because abort() tests to see if a message is already set and
|
|
|
|
|
// something else in Libc will have set a message, this string is
|
|
|
|
|
// not the expectation on 10.9 or higher. Instead, after fork(), the
|
|
|
|
|
// child process has a message indicating that a fork() without
|
|
|
|
|
// exec() occurred. See 10.9.5 Libc-997.90.3/sys/_libc_fork_child.c
|
|
|
|
|
// _libc_fork_child().
|
|
|
|
|
expected_annotation =
|
2020-09-01 17:09:37 -04:00
|
|
|
|
macos_version_number <= 10'08'00
|
2014-10-17 13:47:02 -04:00
|
|
|
|
? "abort() called"
|
|
|
|
|
: "crashed on child side of fork pre-exec";
|
|
|
|
|
break;
|
|
|
|
|
|
2015-08-07 13:59:45 -04:00
|
|
|
|
case kCrashModuleInitialization:
|
|
|
|
|
// This message is set by dyld-353.2.1/src/ImageLoaderMachO.cpp
|
|
|
|
|
// ImageLoaderMachO::doInitialization().
|
2022-08-16 17:10:57 -04:00
|
|
|
|
// dyld4 no longer sets this, so instead check for fork() without
|
|
|
|
|
// exec() like above.
|
|
|
|
|
expected_annotation =
|
|
|
|
|
macos_version_number < 12'00'00
|
|
|
|
|
? ModuleWithCrashyInitializer().value()
|
|
|
|
|
: "crashed on child side of fork pre-exec";
|
2015-08-07 13:59:45 -04:00
|
|
|
|
break;
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
case kCrashDyld:
|
|
|
|
|
// This is independent of dyld’s error_string, which is tested
|
2022-08-16 17:10:57 -04:00
|
|
|
|
// below. dyld4 no longer sets this.
|
|
|
|
|
expected_annotation =
|
|
|
|
|
macos_version_number < 12'00'00
|
|
|
|
|
? "dyld: launch, loading dependent libraries"
|
|
|
|
|
: "";
|
2014-10-17 13:47:02 -04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
ADD_FAILURE();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (const std::string& annotation : all_annotations_vector) {
|
|
|
|
|
// Look for the expectation as a leading susbtring, because the actual
|
|
|
|
|
// string that dyld uses will have the contents of the
|
2016-11-07 09:01:20 -05:00
|
|
|
|
// DYLD_INSERT_LIBRARIES environment variable appended to it on OS X
|
|
|
|
|
// 10.10.
|
2015-08-07 13:59:45 -04:00
|
|
|
|
if (annotation.substr(0, expected_annotation.length()) ==
|
2014-10-17 13:47:02 -04:00
|
|
|
|
expected_annotation) {
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-07 13:59:45 -04:00
|
|
|
|
EXPECT_TRUE(found) << expected_annotation;
|
2014-10-17 13:47:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// dyld exposes its error_string at least as far back as Mac OS X 10.4.
|
|
|
|
|
if (test_type_ == kCrashDyld) {
|
2022-08-16 17:10:57 -04:00
|
|
|
|
std::string couldnt_load_annotation =
|
|
|
|
|
macos_version_number < 12'00'00
|
|
|
|
|
? "could not load inserted library"
|
|
|
|
|
// dyld4 no longer writes an annotation for the primary error
|
|
|
|
|
// See https://crbug.com/1334418/#c26
|
|
|
|
|
: "tried: '/var/empty/NoDirectory/NoLibrary' (no such file)";
|
2014-10-17 13:47:02 -04:00
|
|
|
|
bool found = false;
|
|
|
|
|
for (const std::string& annotation : all_annotations_vector) {
|
2022-08-16 17:10:57 -04:00
|
|
|
|
// Look for the expectation as a substring, because the actual
|
|
|
|
|
// string will contain the library’s pathname and a reason, or on
|
|
|
|
|
// macOS 12, only the reason.
|
|
|
|
|
if (annotation.find(couldnt_load_annotation) != std::string::npos) {
|
2014-10-17 13:47:02 -04:00
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 17:10:57 -04:00
|
|
|
|
EXPECT_TRUE(found) << couldnt_load_annotation;
|
2014-10-17 13:47:02 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-04 14:29:12 -04:00
|
|
|
|
ExcServerCopyState(
|
|
|
|
|
behavior, old_state, old_state_count, new_state, new_state_count);
|
|
|
|
|
return ExcServerSuccessfulReturnValue(exception, behavior, false);
|
2014-10-17 13:47:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// MachMultiprocess:
|
|
|
|
|
|
|
|
|
|
void MachMultiprocessParent() override {
|
2018-02-22 12:12:26 -08:00
|
|
|
|
ProcessReaderMac process_reader;
|
2014-10-17 13:47:02 -04:00
|
|
|
|
ASSERT_TRUE(process_reader.Initialize(ChildTask()));
|
|
|
|
|
|
|
|
|
|
// Wait for the child process to indicate that it’s done setting up its
|
|
|
|
|
// annotations via the CrashpadInfo interface.
|
|
|
|
|
char c;
|
Make file_io reads more rational and predictable
ReadFile() attempted to continue reading after a short read. In most
cases, this is fine. However, ReadFile() would keep trying to fill a
partially-filled buffer until experiencing a 0-length read(), signaling
end-of-file. For certain weird file descriptors like terminal input, EOF
is an ephemeral condition, and attempting to read beyond EOF doesn’t
actually return 0 (EOF) provided that they remain open, it will block
waiting for more input. Consequently, ReadFile() and anything based on
ReadFile() had an undocumented and quirky interface, which was that any
short read that it returned (not an underlying short read) actually
indicated EOF.
This facet of ReadFile() was unexpected, so it’s being removed. The new
behavior is that ReadFile() will return an underlying short read. The
behavior of FileReaderInterface::Read() is updated in accordance with
this change.
Upon experiencing a short read, the caller can determine the best
action. Most callers were already prepared for this behavior. Outside of
util/file, only crashpad_database_util properly implemented EOF
detection according to previous semantics, and adapting it to new
semantics is trivial.
Callers who require an exact-length read can use the new
ReadFileExactly(), or the newly renamed LoggingReadFileExactly() or
CheckedReadFileExactly(). These functions will retry following a short
read. The renamed functions were previously called LoggingReadFile() and
CheckedReadFile(), but those names implied that they were simply
wrapping ReadFile(), which is not the case. They wrapped ReadFile() and
further, insisted on a full read. Since ReadFile()’s semantics are now
changing but these functions’ are not, they’re now even more distinct
from ReadFile(), and must be renamed to avoid confusion.
Test: *
Change-Id: I06b77e0d6ad8719bd2eb67dab93a8740542dd908
Reviewed-on: https://chromium-review.googlesource.com/456676
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-03-16 13:36:38 -04:00
|
|
|
|
CheckedReadFileExactly(ReadPipeHandle(), &c, sizeof(c));
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
2017-10-31 17:14:27 -04:00
|
|
|
|
// Verify the “simple map” and object-based annotations set via the
|
|
|
|
|
// CrashpadInfo interface.
|
2018-02-22 12:12:26 -08:00
|
|
|
|
const std::vector<ProcessReaderMac::Module>& modules =
|
2014-10-17 13:47:02 -04:00
|
|
|
|
process_reader.Modules();
|
|
|
|
|
std::map<std::string, std::string> all_annotations_simple_map;
|
2017-10-31 17:14:27 -04:00
|
|
|
|
std::vector<AnnotationSnapshot> all_annotations;
|
2018-02-22 12:12:26 -08:00
|
|
|
|
for (const ProcessReaderMac::Module& module : modules) {
|
2014-10-17 13:47:02 -04:00
|
|
|
|
MachOImageAnnotationsReader module_annotations_reader(
|
|
|
|
|
&process_reader, module.reader, module.name);
|
|
|
|
|
std::map<std::string, std::string> module_annotations_simple_map =
|
|
|
|
|
module_annotations_reader.SimpleMap();
|
|
|
|
|
all_annotations_simple_map.insert(module_annotations_simple_map.begin(),
|
|
|
|
|
module_annotations_simple_map.end());
|
2017-10-31 17:14:27 -04:00
|
|
|
|
|
|
|
|
|
std::vector<AnnotationSnapshot> annotations =
|
|
|
|
|
module_annotations_reader.AnnotationsList();
|
|
|
|
|
all_annotations.insert(
|
|
|
|
|
all_annotations.end(), annotations.begin(), annotations.end());
|
2014-10-17 13:47:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EXPECT_GE(all_annotations_simple_map.size(), 5u);
|
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(all_annotations_simple_map["#TEST# pad"], "crash");
|
|
|
|
|
EXPECT_EQ(all_annotations_simple_map["#TEST# key"], "value");
|
|
|
|
|
EXPECT_EQ(all_annotations_simple_map["#TEST# x"], "y");
|
|
|
|
|
EXPECT_EQ(all_annotations_simple_map["#TEST# longer"], "shorter");
|
|
|
|
|
EXPECT_EQ(all_annotations_simple_map["#TEST# empty_value"], "");
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
2017-10-31 17:14:27 -04:00
|
|
|
|
EXPECT_EQ(all_annotations.size(), 3u);
|
|
|
|
|
bool saw_same_name_3 = false, saw_same_name_4 = false;
|
|
|
|
|
for (const auto& annotation : all_annotations) {
|
|
|
|
|
EXPECT_EQ(annotation.type,
|
|
|
|
|
static_cast<uint16_t>(Annotation::Type::kString));
|
|
|
|
|
std::string value(reinterpret_cast<const char*>(annotation.value.data()),
|
|
|
|
|
annotation.value.size());
|
|
|
|
|
|
|
|
|
|
if (annotation.name == "#TEST# one") {
|
|
|
|
|
EXPECT_EQ(value, "moocow");
|
|
|
|
|
} else if (annotation.name == "#TEST# same-name") {
|
|
|
|
|
if (value == "same-name 3") {
|
|
|
|
|
EXPECT_FALSE(saw_same_name_3);
|
|
|
|
|
saw_same_name_3 = true;
|
|
|
|
|
} else if (value == "same-name 4") {
|
|
|
|
|
EXPECT_FALSE(saw_same_name_4);
|
|
|
|
|
saw_same_name_4 = true;
|
|
|
|
|
} else {
|
|
|
|
|
ADD_FAILURE() << "unexpected annotation value " << value;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ADD_FAILURE() << "unexpected annotation " << annotation.name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
// Tell the child process that it’s permitted to crash.
|
2015-01-28 14:49:42 -08:00
|
|
|
|
CheckedWriteFile(WritePipeHandle(), &c, sizeof(c));
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
|
|
|
|
if (test_type_ != kDontCrash) {
|
|
|
|
|
// Handle the child’s crash. Further validation will be done in
|
|
|
|
|
// CatchMachException().
|
2014-12-04 10:18:24 -05:00
|
|
|
|
UniversalMachExcServer universal_mach_exc_server(this);
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
mach_msg_return_t mr =
|
2014-12-04 10:18:24 -05:00
|
|
|
|
MachMessageServer::Run(&universal_mach_exc_server,
|
2014-10-17 13:47:02 -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 13:47:02 -04:00
|
|
|
|
<< MachErrorMessage(mr, "MachMessageServer::Run");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MachMultiprocessChild() override {
|
|
|
|
|
CrashpadInfo* crashpad_info = CrashpadInfo::GetCrashpadInfo();
|
|
|
|
|
|
|
|
|
|
// This is “leaked” to crashpad_info.
|
|
|
|
|
SimpleStringDictionary* simple_annotations = new SimpleStringDictionary();
|
|
|
|
|
simple_annotations->SetKeyValue("#TEST# pad", "break");
|
|
|
|
|
simple_annotations->SetKeyValue("#TEST# key", "value");
|
|
|
|
|
simple_annotations->SetKeyValue("#TEST# pad", "crash");
|
|
|
|
|
simple_annotations->SetKeyValue("#TEST# x", "y");
|
|
|
|
|
simple_annotations->SetKeyValue("#TEST# longer", "shorter");
|
|
|
|
|
simple_annotations->SetKeyValue("#TEST# empty_value", "");
|
|
|
|
|
|
|
|
|
|
crashpad_info->set_simple_annotations(simple_annotations);
|
|
|
|
|
|
2017-10-31 17:14:27 -04:00
|
|
|
|
AnnotationList::Register(); // This is “leaked” to crashpad_info.
|
|
|
|
|
|
|
|
|
|
static StringAnnotation<32> test_annotation_one{"#TEST# one"};
|
|
|
|
|
static StringAnnotation<32> test_annotation_two{"#TEST# two"};
|
|
|
|
|
static StringAnnotation<32> test_annotation_three{"#TEST# same-name"};
|
|
|
|
|
static StringAnnotation<32> test_annotation_four{"#TEST# same-name"};
|
|
|
|
|
|
|
|
|
|
test_annotation_one.Set("moocow");
|
|
|
|
|
test_annotation_two.Set("this will be cleared");
|
|
|
|
|
test_annotation_three.Set("same-name 3");
|
|
|
|
|
test_annotation_four.Set("same-name 4");
|
|
|
|
|
test_annotation_two.Clear();
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
// Tell the parent that the environment has been set up.
|
|
|
|
|
char c = '\0';
|
2015-01-28 14:49:42 -08:00
|
|
|
|
CheckedWriteFile(WritePipeHandle(), &c, sizeof(c));
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
|
|
|
|
// Wait for the parent to indicate that it’s safe to crash.
|
Make file_io reads more rational and predictable
ReadFile() attempted to continue reading after a short read. In most
cases, this is fine. However, ReadFile() would keep trying to fill a
partially-filled buffer until experiencing a 0-length read(), signaling
end-of-file. For certain weird file descriptors like terminal input, EOF
is an ephemeral condition, and attempting to read beyond EOF doesn’t
actually return 0 (EOF) provided that they remain open, it will block
waiting for more input. Consequently, ReadFile() and anything based on
ReadFile() had an undocumented and quirky interface, which was that any
short read that it returned (not an underlying short read) actually
indicated EOF.
This facet of ReadFile() was unexpected, so it’s being removed. The new
behavior is that ReadFile() will return an underlying short read. The
behavior of FileReaderInterface::Read() is updated in accordance with
this change.
Upon experiencing a short read, the caller can determine the best
action. Most callers were already prepared for this behavior. Outside of
util/file, only crashpad_database_util properly implemented EOF
detection according to previous semantics, and adapting it to new
semantics is trivial.
Callers who require an exact-length read can use the new
ReadFileExactly(), or the newly renamed LoggingReadFileExactly() or
CheckedReadFileExactly(). These functions will retry following a short
read. The renamed functions were previously called LoggingReadFile() and
CheckedReadFile(), but those names implied that they were simply
wrapping ReadFile(), which is not the case. They wrapped ReadFile() and
further, insisted on a full read. Since ReadFile()’s semantics are now
changing but these functions’ are not, they’re now even more distinct
from ReadFile(), and must be renamed to avoid confusion.
Test: *
Change-Id: I06b77e0d6ad8719bd2eb67dab93a8740542dd908
Reviewed-on: https://chromium-review.googlesource.com/456676
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-03-16 13:36:38 -04:00
|
|
|
|
CheckedReadFileExactly(ReadPipeHandle(), &c, sizeof(c));
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
|
|
|
|
// Direct an exception message to the exception server running in the
|
|
|
|
|
// parent.
|
|
|
|
|
ExceptionPorts exception_ports(ExceptionPorts::kTargetTypeTask,
|
|
|
|
|
mach_task_self());
|
|
|
|
|
ASSERT_TRUE(exception_ports.SetExceptionPort(
|
|
|
|
|
EXC_MASK_CRASH, RemotePort(), EXCEPTION_DEFAULT, THREAD_STATE_NONE));
|
|
|
|
|
|
|
|
|
|
switch (test_type_) {
|
2015-08-07 13:59:45 -04:00
|
|
|
|
case kDontCrash: {
|
2014-10-17 13:47:02 -04:00
|
|
|
|
break;
|
2015-08-07 13:59:45 -04:00
|
|
|
|
}
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
2015-08-07 13:59:45 -04:00
|
|
|
|
case kCrashAbort: {
|
2014-10-17 13:47:02 -04:00
|
|
|
|
abort();
|
2015-08-07 13:59:45 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case kCrashModuleInitialization: {
|
|
|
|
|
// Load a module that crashes while executing a module initializer.
|
2017-11-01 10:37:01 -04:00
|
|
|
|
void* dl_handle = dlopen(ModuleWithCrashyInitializer().value().c_str(),
|
2015-08-07 13:59:45 -04:00
|
|
|
|
RTLD_LAZY | RTLD_LOCAL);
|
|
|
|
|
|
|
|
|
|
// This should have crashed in the dlopen(). If dlopen() failed, the
|
|
|
|
|
// ASSERT_NE() will show the message. If it succeeded without crashing,
|
|
|
|
|
// the FAIL() will fail the test.
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(dl_handle, nullptr) << dlerror();
|
2015-08-07 13:59:45 -04:00
|
|
|
|
FAIL();
|
|
|
|
|
}
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
|
|
|
|
case kCrashDyld: {
|
|
|
|
|
// Set DYLD_INSERT_LIBRARIES to contain a library that does not exist.
|
|
|
|
|
// Unable to load it, dyld will abort with a fatal error.
|
|
|
|
|
ASSERT_EQ(
|
|
|
|
|
setenv(
|
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
|
|
|
|
"DYLD_INSERT_LIBRARIES", "/var/empty/NoDirectory/NoLibrary", 1),
|
|
|
|
|
0)
|
2014-10-17 13:47:02 -04:00
|
|
|
|
<< ErrnoMessage("setenv");
|
|
|
|
|
|
|
|
|
|
// The actual executable doesn’t matter very much, because dyld won’t
|
|
|
|
|
// ever launch it. It just needs to be an executable that uses dyld as
|
2015-08-05 18:24:53 -04:00
|
|
|
|
// its LC_LOAD_DYLINKER (all normal executables do). A custom no-op
|
|
|
|
|
// executable is provided because DYLD_INSERT_LIBRARIES does not work
|
|
|
|
|
// with system executables on OS X 10.11 due to System Integrity
|
|
|
|
|
// Protection.
|
|
|
|
|
base::FilePath no_op_executable = NoOpExecutable();
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(execl(no_op_executable.value().c_str(),
|
|
|
|
|
no_op_executable.BaseName().value().c_str(),
|
|
|
|
|
nullptr),
|
|
|
|
|
0)
|
2014-10-17 13:47:02 -04:00
|
|
|
|
<< ErrnoMessage("execl");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestType test_type_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST(MachOImageAnnotationsReader, DontCrash) {
|
|
|
|
|
TestMachOImageAnnotationsReader test_mach_o_image_annotations_reader(
|
|
|
|
|
TestMachOImageAnnotationsReader::kDontCrash);
|
|
|
|
|
test_mach_o_image_annotations_reader.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MachOImageAnnotationsReader, CrashAbort) {
|
|
|
|
|
TestMachOImageAnnotationsReader test_mach_o_image_annotations_reader(
|
|
|
|
|
TestMachOImageAnnotationsReader::kCrashAbort);
|
|
|
|
|
test_mach_o_image_annotations_reader.Run();
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 17:10:57 -04:00
|
|
|
|
TEST(MachOImageAnnotationsReader, CrashModuleInitialization) {
|
2015-08-07 13:59:45 -04:00
|
|
|
|
TestMachOImageAnnotationsReader test_mach_o_image_annotations_reader(
|
|
|
|
|
TestMachOImageAnnotationsReader::kCrashModuleInitialization);
|
|
|
|
|
test_mach_o_image_annotations_reader.Run();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
TEST(MachOImageAnnotationsReader, CrashDyld) {
|
|
|
|
|
TestMachOImageAnnotationsReader test_mach_o_image_annotations_reader(
|
|
|
|
|
TestMachOImageAnnotationsReader::kCrashDyld);
|
|
|
|
|
test_mach_o_image_annotations_reader.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace crashpad
|