2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-10-09 15:13:13 -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 "minidump/minidump_exception_writer.h"
|
|
|
|
|
2022-02-28 20:57:19 -08:00
|
|
|
#include <iterator>
|
2014-10-09 15:13:13 -04:00
|
|
|
#include <string>
|
2015-12-09 17:36:32 -05:00
|
|
|
#include <utility>
|
2014-10-09 15:13:13 -04:00
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "minidump/minidump_context.h"
|
|
|
|
#include "minidump/minidump_context_writer.h"
|
|
|
|
#include "minidump/minidump_extensions.h"
|
|
|
|
#include "minidump/minidump_file_writer.h"
|
2014-10-20 12:11:14 -04:00
|
|
|
#include "minidump/test/minidump_context_test_util.h"
|
|
|
|
#include "minidump/test/minidump_file_writer_test_util.h"
|
2014-10-22 18:35:18 -04:00
|
|
|
#include "minidump/test/minidump_writable_test_util.h"
|
2014-11-04 12:41:01 -05:00
|
|
|
#include "snapshot/test/test_cpu_context.h"
|
|
|
|
#include "snapshot/test/test_exception_snapshot.h"
|
mac: Tests that crash intentionally shouldn’t go to ReportCrash
Crashpad has many tests that crash intentionally. Some of these are
gtest death tests, and others arrange for intentional crashes to test
Crashpad’s own crash-catching logic. On macOS, all of the gtest death
tests and some of the other intentional crashes were being logged by
ReportCrash, the system’s crash reporter. Since these reports
corresponded to intentional crashes, they were never useful, and served
only to clutter ~/Library/Logs/DiagnosticReports.
Since Crashpad is adept at handling exceptions on its own, this
introduces the “exception swallowing server”,
crashpad_exception_swallower, which is a Mach exception server that
implements a no-op exception handler routine for all exceptions
received. The exception swallowing server is established as the task
handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest
death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all
child processes invoked by the Multiprocess test infrastructure. The
exception swallowing server is not in effect at other times, so
unexpected crashes in test code can still be handled by ReportCrash or
another crash reporter.
With this change in place, no new reports are generated in the
user-level ~/Library/Logs/DiagnosticReports or the system’s
/Library/Logs/DiagnosticReports during a run of Crashpad’s full test
suite on macOS.
Bug: crashpad:33
Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f
Reviewed-on: https://chromium-review.googlesource.com/777859
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-11-20 13:32:26 -05:00
|
|
|
#include "test/gtest_death.h"
|
2015-02-18 14:15:38 -05:00
|
|
|
#include "util/file/string_file.h"
|
2014-10-09 15:13:13 -04:00
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// This returns the MINIDUMP_EXCEPTION_STREAM stream in |exception_stream|.
|
|
|
|
void GetExceptionStream(const std::string& file_contents,
|
|
|
|
const MINIDUMP_EXCEPTION_STREAM** exception_stream) {
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
|
|
|
|
constexpr size_t kExceptionStreamOffset =
|
2014-10-09 15:13:13 -04:00
|
|
|
kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY);
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kContextOffset =
|
2014-10-09 15:13:13 -04:00
|
|
|
kExceptionStreamOffset + sizeof(MINIDUMP_EXCEPTION_STREAM);
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kFileSize = kContextOffset + sizeof(MinidumpContextX86);
|
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(kFileSize, file_contents.size());
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2014-10-21 14:15:07 -04:00
|
|
|
const MINIDUMP_DIRECTORY* directory;
|
2014-10-09 15:13:13 -04:00
|
|
|
const MINIDUMP_HEADER* header =
|
2014-10-21 14:15:07 -04:00
|
|
|
MinidumpHeaderAtStart(file_contents, &directory);
|
2014-10-09 15:13:13 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0));
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(directory[0].StreamType, kMinidumpStreamTypeException);
|
|
|
|
EXPECT_EQ(directory[0].Location.Rva, kExceptionStreamOffset);
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
*exception_stream =
|
|
|
|
MinidumpWritableAtLocationDescriptor<MINIDUMP_EXCEPTION_STREAM>(
|
|
|
|
file_contents, directory[0].Location);
|
|
|
|
ASSERT_TRUE(exception_stream);
|
2014-10-09 15:13:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The MINIDUMP_EXCEPTION_STREAMs |expected| and |observed| are compared against
|
2020-05-06 20:39:19 -04:00
|
|
|
// each other using Google Test assertions. The context will be recovered from
|
2014-10-09 15:13:13 -04:00
|
|
|
// |file_contents| and stored in |context|.
|
|
|
|
void ExpectExceptionStream(const MINIDUMP_EXCEPTION_STREAM* expected,
|
|
|
|
const MINIDUMP_EXCEPTION_STREAM* observed,
|
|
|
|
const std::string& file_contents,
|
|
|
|
const MinidumpContextX86** context) {
|
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(observed->ThreadId, expected->ThreadId);
|
|
|
|
EXPECT_EQ(observed->__alignment, 0u);
|
2020-12-09 22:21:38 +00:00
|
|
|
|
|
|
|
// Copy the ExceptionRecords so that their uint64_t members can be accessed
|
|
|
|
// with the proper alignment.
|
|
|
|
const MINIDUMP_EXCEPTION observed_exception = observed->ExceptionRecord;
|
|
|
|
const MINIDUMP_EXCEPTION expected_exception = expected->ExceptionRecord;
|
|
|
|
|
|
|
|
EXPECT_EQ(observed_exception.ExceptionCode, expected_exception.ExceptionCode);
|
|
|
|
EXPECT_EQ(observed_exception.ExceptionFlags,
|
|
|
|
expected_exception.ExceptionFlags);
|
|
|
|
EXPECT_EQ(observed_exception.ExceptionRecord,
|
|
|
|
expected_exception.ExceptionRecord);
|
|
|
|
EXPECT_EQ(observed_exception.ExceptionAddress,
|
|
|
|
expected_exception.ExceptionAddress);
|
|
|
|
EXPECT_EQ(observed_exception.NumberParameters,
|
|
|
|
expected_exception.NumberParameters);
|
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(observed->ExceptionRecord.__unusedAlignment, 0u);
|
2014-10-09 15:13:13 -04:00
|
|
|
for (size_t index = 0;
|
2022-02-28 20:57:19 -08:00
|
|
|
index < std::size(observed_exception.ExceptionInformation);
|
2014-10-09 15:13:13 -04:00
|
|
|
++index) {
|
2020-12-09 22:21:38 +00:00
|
|
|
EXPECT_EQ(observed_exception.ExceptionInformation[index],
|
|
|
|
expected_exception.ExceptionInformation[index]);
|
2014-10-09 15:13:13 -04:00
|
|
|
}
|
2014-10-22 18:35:18 -04:00
|
|
|
*context = MinidumpWritableAtLocationDescriptor<MinidumpContextX86>(
|
|
|
|
file_contents, observed->ThreadContext);
|
|
|
|
ASSERT_TRUE(context);
|
2014-10-09 15:13:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpExceptionWriter, Minimal) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto exception_writer = std::make_unique<MinidumpExceptionWriter>();
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kSeed = 100;
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto context_x86_writer = std::make_unique<MinidumpContextX86Writer>();
|
2014-10-27 15:01:39 -04:00
|
|
|
InitializeMinidumpContextX86(context_x86_writer->context(), kSeed);
|
2015-12-09 17:36:32 -05:00
|
|
|
exception_writer->SetContext(std::move(context_x86_writer));
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(exception_writer)));
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2015-02-05 08:45:34 -08:00
|
|
|
const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr;
|
2014-10-09 15:13:13 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
2015-02-18 14:15:38 -05:00
|
|
|
GetExceptionStream(string_file.string(), &observed_exception_stream));
|
2014-10-09 15:13:13 -04:00
|
|
|
|
|
|
|
MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {};
|
|
|
|
expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86);
|
|
|
|
|
2015-02-05 08:45:34 -08:00
|
|
|
const MinidumpContextX86* observed_context = nullptr;
|
2014-10-09 15:13:13 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream,
|
|
|
|
observed_exception_stream,
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-09 15:13:13 -04:00
|
|
|
&observed_context));
|
|
|
|
|
2014-11-03 17:43:39 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpContextX86(kSeed, observed_context, false));
|
2014-10-09 15:13:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpExceptionWriter, Standard) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto exception_writer = std::make_unique<MinidumpExceptionWriter>();
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kSeed = 200;
|
|
|
|
constexpr uint32_t kThreadID = 1;
|
|
|
|
constexpr uint32_t kExceptionCode = 2;
|
|
|
|
constexpr uint32_t kExceptionFlags = 3;
|
|
|
|
constexpr uint32_t kExceptionRecord = 4;
|
|
|
|
constexpr uint32_t kExceptionAddress = 5;
|
|
|
|
constexpr uint64_t kExceptionInformation0 = 6;
|
|
|
|
constexpr uint64_t kExceptionInformation1 = 7;
|
|
|
|
constexpr uint64_t kExceptionInformation2 = 7;
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto context_x86_writer = std::make_unique<MinidumpContextX86Writer>();
|
2014-10-27 15:01:39 -04:00
|
|
|
InitializeMinidumpContextX86(context_x86_writer->context(), kSeed);
|
2015-12-09 17:36:32 -05:00
|
|
|
exception_writer->SetContext(std::move(context_x86_writer));
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
exception_writer->SetThreadID(kThreadID);
|
|
|
|
exception_writer->SetExceptionCode(kExceptionCode);
|
|
|
|
exception_writer->SetExceptionFlags(kExceptionFlags);
|
|
|
|
exception_writer->SetExceptionRecord(kExceptionRecord);
|
|
|
|
exception_writer->SetExceptionAddress(kExceptionAddress);
|
2014-10-09 15:13:13 -04:00
|
|
|
|
|
|
|
// Set a lot of exception information at first, and then replace it with less.
|
|
|
|
// This tests that the exception that is written does not contain the
|
|
|
|
// “garbage” from the initial SetExceptionInformation() call.
|
|
|
|
std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS,
|
|
|
|
0x5a5a5a5a5a5a5a5a);
|
2014-10-27 15:01:39 -04:00
|
|
|
exception_writer->SetExceptionInformation(exception_information);
|
2014-10-09 15:13:13 -04:00
|
|
|
|
|
|
|
exception_information.clear();
|
|
|
|
exception_information.push_back(kExceptionInformation0);
|
|
|
|
exception_information.push_back(kExceptionInformation1);
|
|
|
|
exception_information.push_back(kExceptionInformation2);
|
2014-10-27 15:01:39 -04:00
|
|
|
exception_writer->SetExceptionInformation(exception_information);
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(exception_writer)));
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2015-02-05 08:45:34 -08:00
|
|
|
const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr;
|
2014-10-09 15:13:13 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
2015-02-18 14:15:38 -05:00
|
|
|
GetExceptionStream(string_file.string(), &observed_exception_stream));
|
2014-10-09 15:13:13 -04:00
|
|
|
|
|
|
|
MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {};
|
|
|
|
expected_exception_stream.ThreadId = kThreadID;
|
|
|
|
expected_exception_stream.ExceptionRecord.ExceptionCode = kExceptionCode;
|
|
|
|
expected_exception_stream.ExceptionRecord.ExceptionFlags = kExceptionFlags;
|
|
|
|
expected_exception_stream.ExceptionRecord.ExceptionRecord = kExceptionRecord;
|
|
|
|
expected_exception_stream.ExceptionRecord.ExceptionAddress =
|
|
|
|
kExceptionAddress;
|
|
|
|
expected_exception_stream.ExceptionRecord.NumberParameters =
|
2015-03-06 16:05:34 -08:00
|
|
|
static_cast<uint32_t>(exception_information.size());
|
2014-10-09 15:13:13 -04:00
|
|
|
for (size_t index = 0; index < exception_information.size(); ++index) {
|
|
|
|
expected_exception_stream.ExceptionRecord.ExceptionInformation[index] =
|
|
|
|
exception_information[index];
|
|
|
|
}
|
|
|
|
expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86);
|
|
|
|
|
2015-02-05 08:45:34 -08:00
|
|
|
const MinidumpContextX86* observed_context = nullptr;
|
2014-10-09 15:13:13 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream,
|
|
|
|
observed_exception_stream,
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-09 15:13:13 -04:00
|
|
|
&observed_context));
|
|
|
|
|
2014-11-03 17:43:39 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpContextX86(kSeed, observed_context, false));
|
2014-10-09 15:13:13 -04:00
|
|
|
}
|
|
|
|
|
2014-11-04 12:41:01 -05:00
|
|
|
TEST(MinidumpExceptionWriter, InitializeFromSnapshot) {
|
|
|
|
std::vector<uint64_t> exception_codes;
|
|
|
|
exception_codes.push_back(0x1000000000000000);
|
|
|
|
exception_codes.push_back(0x5555555555555555);
|
|
|
|
|
|
|
|
MINIDUMP_EXCEPTION_STREAM expect_exception = {};
|
|
|
|
|
|
|
|
expect_exception.ThreadId = 123;
|
|
|
|
expect_exception.ExceptionRecord.ExceptionCode = 100;
|
|
|
|
expect_exception.ExceptionRecord.ExceptionFlags = 1;
|
|
|
|
expect_exception.ExceptionRecord.ExceptionAddress = 0xfedcba9876543210;
|
2015-03-06 16:05:34 -08:00
|
|
|
expect_exception.ExceptionRecord.NumberParameters =
|
|
|
|
static_cast<uint32_t>(exception_codes.size());
|
2014-11-04 12:41:01 -05:00
|
|
|
for (size_t index = 0; index < exception_codes.size(); ++index) {
|
|
|
|
expect_exception.ExceptionRecord.ExceptionInformation[index] =
|
|
|
|
exception_codes[index];
|
|
|
|
}
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint64_t kThreadID = 0xaaaaaaaaaaaaaaaa;
|
|
|
|
constexpr uint32_t kSeed = 65;
|
2014-11-04 12:41:01 -05:00
|
|
|
|
|
|
|
TestExceptionSnapshot exception_snapshot;
|
|
|
|
exception_snapshot.SetThreadID(kThreadID);
|
|
|
|
exception_snapshot.SetException(
|
|
|
|
expect_exception.ExceptionRecord.ExceptionCode);
|
|
|
|
exception_snapshot.SetExceptionInfo(
|
|
|
|
expect_exception.ExceptionRecord.ExceptionFlags);
|
|
|
|
exception_snapshot.SetExceptionAddress(
|
|
|
|
expect_exception.ExceptionRecord.ExceptionAddress);
|
|
|
|
exception_snapshot.SetCodes(exception_codes);
|
|
|
|
|
|
|
|
InitializeCPUContextX86(exception_snapshot.MutableContext(), kSeed);
|
|
|
|
|
|
|
|
MinidumpThreadIDMap thread_id_map;
|
|
|
|
thread_id_map[kThreadID] = expect_exception.ThreadId;
|
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto exception_writer = std::make_unique<MinidumpExceptionWriter>();
|
2024-01-19 13:41:26 -05:00
|
|
|
exception_writer->InitializeFromSnapshot(
|
|
|
|
&exception_snapshot,
|
|
|
|
thread_id_map,
|
|
|
|
/*allow_missing_thread_id_from_map=*/false);
|
2014-11-04 12:41:01 -05:00
|
|
|
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(exception_writer)));
|
2014-11-04 12:41:01 -05:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-11-04 12:41:01 -05:00
|
|
|
|
2015-02-05 08:45:34 -08:00
|
|
|
const MINIDUMP_EXCEPTION_STREAM* exception = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetExceptionStream(string_file.string(), &exception));
|
2014-11-04 12:41:01 -05:00
|
|
|
|
2015-02-05 08:45:34 -08:00
|
|
|
const MinidumpContextX86* observed_context = nullptr;
|
2014-11-04 12:41:01 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expect_exception,
|
|
|
|
exception,
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-11-04 12:41:01 -05:00
|
|
|
&observed_context));
|
|
|
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpContextX86(kSeed, observed_context, true));
|
|
|
|
}
|
|
|
|
|
2014-10-09 15:13:13 -04:00
|
|
|
TEST(MinidumpExceptionWriterDeathTest, NoContext) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto exception_writer = std::make_unique<MinidumpExceptionWriter>();
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(exception_writer)));
|
2014-10-09 15:13:13 -04:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
2015-03-09 18:02:14 -04:00
|
|
|
ASSERT_DEATH_CHECK(minidump_file_writer.WriteEverything(&string_file),
|
|
|
|
"context_");
|
2014-10-09 15:13:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpExceptionWriterDeathTest, TooMuchInformation) {
|
|
|
|
MinidumpExceptionWriter exception_writer;
|
|
|
|
std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS + 1,
|
|
|
|
0x5a5a5a5a5a5a5a5a);
|
2015-03-09 18:02:14 -04:00
|
|
|
ASSERT_DEATH_CHECK(
|
|
|
|
exception_writer.SetExceptionInformation(exception_information),
|
|
|
|
"kMaxParameters");
|
2014-10-09 15:13:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|