2014-10-09 15:31:29 -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 "minidump/minidump_thread_writer.h"
|
|
|
|
|
2015-10-01 14:04:49 -07:00
|
|
|
#include <string>
|
2015-12-09 17:36:32 -05:00
|
|
|
#include <utility>
|
2015-10-01 14:04:49 -07:00
|
|
|
|
2015-02-05 11:30:29 -08:00
|
|
|
#include "base/compiler_specific.h"
|
2015-02-05 15:04:49 -08:00
|
|
|
#include "base/format_macros.h"
|
2019-01-04 16:57:57 -05:00
|
|
|
#include "base/stl_util.h"
|
2014-11-04 12:36:29 -05:00
|
|
|
#include "base/strings/stringprintf.h"
|
2014-10-09 15:31:29 -04:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "minidump/minidump_context_writer.h"
|
|
|
|
#include "minidump/minidump_file_writer.h"
|
2016-01-06 12:22:50 -05:00
|
|
|
#include "minidump/minidump_memory_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"
|
2016-01-06 12:22:50 -05:00
|
|
|
#include "minidump/test/minidump_memory_writer_test_util.h"
|
2014-10-22 18:35:18 -04:00
|
|
|
#include "minidump/test/minidump_writable_test_util.h"
|
2014-11-04 12:36:29 -05:00
|
|
|
#include "snapshot/test/test_cpu_context.h"
|
|
|
|
#include "snapshot/test/test_memory_snapshot.h"
|
|
|
|
#include "snapshot/test/test_thread_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:31:29 -04:00
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// This returns the MINIDUMP_THREAD_LIST stream in |thread_list|. If
|
2014-10-14 11:10:45 -04:00
|
|
|
// |memory_list| is not nullptr, a MINIDUMP_MEMORY_LIST stream is also expected
|
|
|
|
// in |file_contents|, and that stream will be returned in |memory_list|.
|
2014-10-09 15:31:29 -04:00
|
|
|
void GetThreadListStream(const std::string& file_contents,
|
|
|
|
const MINIDUMP_THREAD_LIST** thread_list,
|
|
|
|
const MINIDUMP_MEMORY_LIST** memory_list) {
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
|
2014-10-09 15:31:29 -04:00
|
|
|
const uint32_t kExpectedStreams = memory_list ? 2 : 1;
|
|
|
|
const size_t kThreadListStreamOffset =
|
|
|
|
kDirectoryOffset + kExpectedStreams * sizeof(MINIDUMP_DIRECTORY);
|
|
|
|
const size_t kThreadsOffset =
|
|
|
|
kThreadListStreamOffset + sizeof(MINIDUMP_THREAD_LIST);
|
|
|
|
|
|
|
|
ASSERT_GE(file_contents.size(), kThreadsOffset);
|
|
|
|
|
2014-10-21 14:15:07 -04:00
|
|
|
const MINIDUMP_DIRECTORY* directory;
|
2014-10-09 15:31:29 -04:00
|
|
|
const MINIDUMP_HEADER* header =
|
2014-10-21 14:15:07 -04:00
|
|
|
MinidumpHeaderAtStart(file_contents, &directory);
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, kExpectedStreams, 0));
|
2014-10-21 14:15:07 -04:00
|
|
|
ASSERT_TRUE(directory);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(directory[0].StreamType, kMinidumpStreamTypeThreadList);
|
|
|
|
EXPECT_EQ(directory[0].Location.Rva, kThreadListStreamOffset);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
*thread_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>(
|
|
|
|
file_contents, directory[0].Location);
|
|
|
|
ASSERT_TRUE(thread_list);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
|
|
|
if (memory_list) {
|
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[1].StreamType, kMinidumpStreamTypeMemoryList);
|
2014-10-22 18:35:18 -04:00
|
|
|
|
|
|
|
*memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
|
|
|
|
file_contents, directory[1].Location);
|
|
|
|
ASSERT_TRUE(*memory_list);
|
2014-10-09 15:31:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpThreadWriter, EmptyThreadList) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_list_writer = std::make_unique<MinidumpThreadListWriter>();
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(thread_list_writer)));
|
2014-10-09 15:31:29 -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:31:29 -04:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(string_file.string().size(),
|
|
|
|
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
|
|
|
|
sizeof(MINIDUMP_THREAD_LIST));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MINIDUMP_THREAD_LIST* thread_list = nullptr;
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
2015-02-18 14:15:38 -05:00
|
|
|
GetThreadListStream(string_file.string(), &thread_list, nullptr));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(thread_list->NumberOfThreads, 0u);
|
2014-10-09 15:31:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The MINIDUMP_THREADs |expected| and |observed| are compared against each
|
2020-05-06 20:39:19 -04:00
|
|
|
// other using Google Test assertions. If |stack| is not nullptr, |observed| is
|
2014-10-14 11:10:45 -04:00
|
|
|
// expected to contain a populated MINIDUMP_MEMORY_DESCRIPTOR in its Stack
|
|
|
|
// field, otherwise, its Stack field is expected to be zeroed out. The memory
|
2014-10-09 15:31:29 -04:00
|
|
|
// descriptor will be placed in |stack|. |observed| must contain a populated
|
|
|
|
// ThreadContext field. The context will be recovered from |file_contents| and
|
|
|
|
// stored in |context_base|.
|
|
|
|
void ExpectThread(const MINIDUMP_THREAD* expected,
|
|
|
|
const MINIDUMP_THREAD* observed,
|
|
|
|
const std::string& file_contents,
|
|
|
|
const MINIDUMP_MEMORY_DESCRIPTOR** stack,
|
|
|
|
const void** context_base) {
|
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->SuspendCount, expected->SuspendCount);
|
|
|
|
EXPECT_EQ(observed->PriorityClass, expected->PriorityClass);
|
|
|
|
EXPECT_EQ(observed->Priority, expected->Priority);
|
|
|
|
EXPECT_EQ(observed->Teb, expected->Teb);
|
|
|
|
|
|
|
|
EXPECT_EQ(observed->Stack.StartOfMemoryRange,
|
|
|
|
expected->Stack.StartOfMemoryRange);
|
|
|
|
EXPECT_EQ(observed->Stack.Memory.DataSize, expected->Stack.Memory.DataSize);
|
2014-10-09 15:31:29 -04:00
|
|
|
if (stack) {
|
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(observed->Stack.Memory.DataSize, 0u);
|
|
|
|
ASSERT_NE(observed->Stack.Memory.Rva, 0u);
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_GE(file_contents.size(),
|
|
|
|
observed->Stack.Memory.Rva + observed->Stack.Memory.DataSize);
|
|
|
|
*stack = &observed->Stack;
|
|
|
|
} 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(observed->Stack.StartOfMemoryRange, 0u);
|
|
|
|
EXPECT_EQ(observed->Stack.Memory.DataSize, 0u);
|
|
|
|
EXPECT_EQ(observed->Stack.Memory.Rva, 0u);
|
2014-10-09 15:31:29 -04:00
|
|
|
}
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(observed->ThreadContext.DataSize, expected->ThreadContext.DataSize);
|
|
|
|
ASSERT_NE(observed->ThreadContext.DataSize, 0u);
|
|
|
|
ASSERT_NE(observed->ThreadContext.Rva, 0u);
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_GE(file_contents.size(),
|
|
|
|
observed->ThreadContext.Rva + expected->ThreadContext.DataSize);
|
|
|
|
*context_base = &file_contents[observed->ThreadContext.Rva];
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpThreadWriter, OneThread_x86_NoStack) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_list_writer = std::make_unique<MinidumpThreadListWriter>();
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kThreadID = 0x11111111;
|
|
|
|
constexpr uint32_t kSuspendCount = 1;
|
|
|
|
constexpr uint32_t kPriorityClass = 0x20;
|
|
|
|
constexpr uint32_t kPriority = 10;
|
|
|
|
constexpr uint64_t kTEB = 0x55555555;
|
|
|
|
constexpr uint32_t kSeed = 123;
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_writer = std::make_unique<MinidumpThreadWriter>();
|
2014-10-27 15:01:39 -04:00
|
|
|
thread_writer->SetThreadID(kThreadID);
|
|
|
|
thread_writer->SetSuspendCount(kSuspendCount);
|
|
|
|
thread_writer->SetPriorityClass(kPriorityClass);
|
|
|
|
thread_writer->SetPriority(kPriority);
|
|
|
|
thread_writer->SetTEB(kTEB);
|
2014-10-09 15:31:29 -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
|
|
|
thread_writer->SetContext(std::move(context_x86_writer));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_list_writer->AddThread(std::move(thread_writer));
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(thread_list_writer)));
|
2014-10-09 15:31:29 -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:31:29 -04:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(string_file.string().size(),
|
|
|
|
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
|
2014-10-09 15:31:29 -04:00
|
|
|
sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) +
|
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
|
|
|
1 * sizeof(MinidumpContextX86));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MINIDUMP_THREAD_LIST* thread_list = nullptr;
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
2015-02-18 14:15:38 -05:00
|
|
|
GetThreadListStream(string_file.string(), &thread_list, nullptr));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(thread_list->NumberOfThreads, 1u);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
|
|
|
MINIDUMP_THREAD expected = {};
|
|
|
|
expected.ThreadId = kThreadID;
|
|
|
|
expected.SuspendCount = kSuspendCount;
|
|
|
|
expected.PriorityClass = kPriorityClass;
|
|
|
|
expected.Priority = kPriority;
|
|
|
|
expected.Teb = kTEB;
|
|
|
|
expected.ThreadContext.DataSize = sizeof(MinidumpContextX86);
|
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MinidumpContextX86* observed_context = nullptr;
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectThread(&expected,
|
|
|
|
&thread_list->Threads[0],
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-14 11:10:45 -04:00
|
|
|
nullptr,
|
2014-10-09 15:31:29 -04:00
|
|
|
reinterpret_cast<const void**>(&observed_context)));
|
|
|
|
|
2014-11-03 17:43:39 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpContextX86(kSeed, observed_context, false));
|
2014-10-09 15:31:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpThreadWriter, OneThread_AMD64_Stack) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_list_writer = std::make_unique<MinidumpThreadListWriter>();
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kThreadID = 0x22222222;
|
|
|
|
constexpr uint32_t kSuspendCount = 2;
|
|
|
|
constexpr uint32_t kPriorityClass = 0x30;
|
|
|
|
constexpr uint32_t kPriority = 20;
|
|
|
|
constexpr uint64_t kTEB = 0x5555555555555555;
|
|
|
|
constexpr uint64_t kMemoryBase = 0x765432100000;
|
|
|
|
constexpr size_t kMemorySize = 32;
|
|
|
|
constexpr uint8_t kMemoryValue = 99;
|
|
|
|
constexpr uint32_t kSeed = 456;
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_writer = std::make_unique<MinidumpThreadWriter>();
|
2014-10-27 15:01:39 -04:00
|
|
|
thread_writer->SetThreadID(kThreadID);
|
|
|
|
thread_writer->SetSuspendCount(kSuspendCount);
|
|
|
|
thread_writer->SetPriorityClass(kPriorityClass);
|
|
|
|
thread_writer->SetPriority(kPriority);
|
|
|
|
thread_writer->SetTEB(kTEB);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto memory_writer = std::make_unique<TestMinidumpMemoryWriter>(
|
|
|
|
kMemoryBase, kMemorySize, kMemoryValue);
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_writer->SetStack(std::move(memory_writer));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-31 22:25:34 -04:00
|
|
|
auto context_amd64_writer = std::make_unique<MinidumpContextAMD64Writer>();
|
2014-10-27 15:01:39 -04:00
|
|
|
InitializeMinidumpContextAMD64(context_amd64_writer->context(), kSeed);
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_writer->SetContext(std::move(context_amd64_writer));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_list_writer->AddThread(std::move(thread_writer));
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(thread_list_writer)));
|
2014-10-09 15:31:29 -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:31:29 -04:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(string_file.string().size(),
|
|
|
|
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
|
2014-10-09 15:31:29 -04:00
|
|
|
sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) +
|
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
|
|
|
1 * sizeof(MinidumpContextAMD64) + kMemorySize);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MINIDUMP_THREAD_LIST* thread_list = nullptr;
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
2015-02-18 14:15:38 -05:00
|
|
|
GetThreadListStream(string_file.string(), &thread_list, nullptr));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(thread_list->NumberOfThreads, 1u);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
|
|
|
MINIDUMP_THREAD expected = {};
|
|
|
|
expected.ThreadId = kThreadID;
|
|
|
|
expected.SuspendCount = kSuspendCount;
|
|
|
|
expected.PriorityClass = kPriorityClass;
|
|
|
|
expected.Priority = kPriority;
|
|
|
|
expected.Teb = kTEB;
|
|
|
|
expected.Stack.StartOfMemoryRange = kMemoryBase;
|
|
|
|
expected.Stack.Memory.DataSize = kMemorySize;
|
|
|
|
expected.ThreadContext.DataSize = sizeof(MinidumpContextAMD64);
|
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr;
|
|
|
|
const MinidumpContextAMD64* observed_context = nullptr;
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectThread(&expected,
|
|
|
|
&thread_list->Threads[0],
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-09 15:31:29 -04:00
|
|
|
&observed_stack,
|
|
|
|
reinterpret_cast<const void**>(&observed_context)));
|
|
|
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack,
|
|
|
|
observed_stack,
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-09 15:31:29 -04:00
|
|
|
kMemoryValue,
|
|
|
|
true));
|
2014-11-03 17:43:39 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpContextAMD64(kSeed, observed_context, false));
|
2014-10-09 15:31:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpThreadWriter, ThreeThreads_x86_MemoryList) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_list_writer = std::make_unique<MinidumpThreadListWriter>();
|
|
|
|
auto memory_list_writer = std::make_unique<MinidumpMemoryListWriter>();
|
2014-10-27 15:01:39 -04:00
|
|
|
thread_list_writer->SetMemoryListWriter(memory_list_writer.get());
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kThreadID0 = 1111111;
|
|
|
|
constexpr uint32_t kSuspendCount0 = 111111;
|
|
|
|
constexpr uint32_t kPriorityClass0 = 11111;
|
|
|
|
constexpr uint32_t kPriority0 = 1111;
|
|
|
|
constexpr uint64_t kTEB0 = 111;
|
|
|
|
constexpr uint64_t kMemoryBase0 = 0x1110;
|
|
|
|
constexpr size_t kMemorySize0 = 16;
|
|
|
|
constexpr uint8_t kMemoryValue0 = 11;
|
|
|
|
constexpr uint32_t kSeed0 = 1;
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_writer_0 = std::make_unique<MinidumpThreadWriter>();
|
2014-10-27 15:01:39 -04:00
|
|
|
thread_writer_0->SetThreadID(kThreadID0);
|
|
|
|
thread_writer_0->SetSuspendCount(kSuspendCount0);
|
|
|
|
thread_writer_0->SetPriorityClass(kPriorityClass0);
|
|
|
|
thread_writer_0->SetPriority(kPriority0);
|
|
|
|
thread_writer_0->SetTEB(kTEB0);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto memory_writer_0 = std::make_unique<TestMinidumpMemoryWriter>(
|
|
|
|
kMemoryBase0, kMemorySize0, kMemoryValue0);
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_writer_0->SetStack(std::move(memory_writer_0));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto context_x86_writer_0 = std::make_unique<MinidumpContextX86Writer>();
|
2014-10-27 15:01:39 -04:00
|
|
|
InitializeMinidumpContextX86(context_x86_writer_0->context(), kSeed0);
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_writer_0->SetContext(std::move(context_x86_writer_0));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_list_writer->AddThread(std::move(thread_writer_0));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kThreadID1 = 2222222;
|
|
|
|
constexpr uint32_t kSuspendCount1 = 222222;
|
|
|
|
constexpr uint32_t kPriorityClass1 = 22222;
|
|
|
|
constexpr uint32_t kPriority1 = 2222;
|
|
|
|
constexpr uint64_t kTEB1 = 222;
|
|
|
|
constexpr uint64_t kMemoryBase1 = 0x2220;
|
|
|
|
constexpr size_t kMemorySize1 = 32;
|
|
|
|
constexpr uint8_t kMemoryValue1 = 22;
|
|
|
|
constexpr uint32_t kSeed1 = 2;
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_writer_1 = std::make_unique<MinidumpThreadWriter>();
|
2014-10-27 15:01:39 -04:00
|
|
|
thread_writer_1->SetThreadID(kThreadID1);
|
|
|
|
thread_writer_1->SetSuspendCount(kSuspendCount1);
|
|
|
|
thread_writer_1->SetPriorityClass(kPriorityClass1);
|
|
|
|
thread_writer_1->SetPriority(kPriority1);
|
|
|
|
thread_writer_1->SetTEB(kTEB1);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto memory_writer_1 = std::make_unique<TestMinidumpMemoryWriter>(
|
|
|
|
kMemoryBase1, kMemorySize1, kMemoryValue1);
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_writer_1->SetStack(std::move(memory_writer_1));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto context_x86_writer_1 = std::make_unique<MinidumpContextX86Writer>();
|
2014-10-27 15:01:39 -04:00
|
|
|
InitializeMinidumpContextX86(context_x86_writer_1->context(), kSeed1);
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_writer_1->SetContext(std::move(context_x86_writer_1));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_list_writer->AddThread(std::move(thread_writer_1));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kThreadID2 = 3333333;
|
|
|
|
constexpr uint32_t kSuspendCount2 = 333333;
|
|
|
|
constexpr uint32_t kPriorityClass2 = 33333;
|
|
|
|
constexpr uint32_t kPriority2 = 3333;
|
|
|
|
constexpr uint64_t kTEB2 = 333;
|
|
|
|
constexpr uint64_t kMemoryBase2 = 0x3330;
|
|
|
|
constexpr size_t kMemorySize2 = 48;
|
|
|
|
constexpr uint8_t kMemoryValue2 = 33;
|
|
|
|
constexpr uint32_t kSeed2 = 3;
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_writer_2 = std::make_unique<MinidumpThreadWriter>();
|
2014-10-27 15:01:39 -04:00
|
|
|
thread_writer_2->SetThreadID(kThreadID2);
|
|
|
|
thread_writer_2->SetSuspendCount(kSuspendCount2);
|
|
|
|
thread_writer_2->SetPriorityClass(kPriorityClass2);
|
|
|
|
thread_writer_2->SetPriority(kPriority2);
|
|
|
|
thread_writer_2->SetTEB(kTEB2);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto memory_writer_2 = std::make_unique<TestMinidumpMemoryWriter>(
|
|
|
|
kMemoryBase2, kMemorySize2, kMemoryValue2);
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_writer_2->SetStack(std::move(memory_writer_2));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto context_x86_writer_2 = std::make_unique<MinidumpContextX86Writer>();
|
2014-10-27 15:01:39 -04:00
|
|
|
InitializeMinidumpContextX86(context_x86_writer_2->context(), kSeed2);
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_writer_2->SetContext(std::move(context_x86_writer_2));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_list_writer->AddThread(std::move(thread_writer_2));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(thread_list_writer)));
|
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(memory_list_writer)));
|
2014-10-09 15:31:29 -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:31:29 -04:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(
|
|
|
|
string_file.string().size(),
|
|
|
|
sizeof(MINIDUMP_HEADER) + 2 * sizeof(MINIDUMP_DIRECTORY) +
|
|
|
|
sizeof(MINIDUMP_THREAD_LIST) + 3 * sizeof(MINIDUMP_THREAD) +
|
|
|
|
sizeof(MINIDUMP_MEMORY_LIST) +
|
|
|
|
3 * sizeof(MINIDUMP_MEMORY_DESCRIPTOR) +
|
|
|
|
3 * sizeof(MinidumpContextX86) + kMemorySize0 + kMemorySize1 +
|
|
|
|
kMemorySize2 + 12); // 12 for alignment
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MINIDUMP_THREAD_LIST* thread_list = nullptr;
|
|
|
|
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
2015-02-18 14:15:38 -05:00
|
|
|
GetThreadListStream(string_file.string(), &thread_list, &memory_list));
|
2014-10-09 15:31:29 -04:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(thread_list->NumberOfThreads, 3u);
|
|
|
|
EXPECT_EQ(memory_list->NumberOfMemoryRanges, 3u);
|
2014-10-09 15:31:29 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("thread 0");
|
|
|
|
|
|
|
|
MINIDUMP_THREAD expected = {};
|
|
|
|
expected.ThreadId = kThreadID0;
|
|
|
|
expected.SuspendCount = kSuspendCount0;
|
|
|
|
expected.PriorityClass = kPriorityClass0;
|
|
|
|
expected.Priority = kPriority0;
|
|
|
|
expected.Teb = kTEB0;
|
|
|
|
expected.Stack.StartOfMemoryRange = kMemoryBase0;
|
|
|
|
expected.Stack.Memory.DataSize = kMemorySize0;
|
|
|
|
expected.ThreadContext.DataSize = sizeof(MinidumpContextX86);
|
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr;
|
|
|
|
const MinidumpContextX86* observed_context = nullptr;
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectThread(&expected,
|
|
|
|
&thread_list->Threads[0],
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-09 15:31:29 -04:00
|
|
|
&observed_stack,
|
|
|
|
reinterpret_cast<const void**>(&observed_context)));
|
|
|
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack,
|
|
|
|
observed_stack,
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-09 15:31:29 -04:00
|
|
|
kMemoryValue0,
|
|
|
|
false));
|
2014-11-03 17:43:39 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpContextX86(kSeed0, observed_context, false));
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor(
|
|
|
|
observed_stack, &memory_list->MemoryRanges[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("thread 1");
|
|
|
|
|
|
|
|
MINIDUMP_THREAD expected = {};
|
|
|
|
expected.ThreadId = kThreadID1;
|
|
|
|
expected.SuspendCount = kSuspendCount1;
|
|
|
|
expected.PriorityClass = kPriorityClass1;
|
|
|
|
expected.Priority = kPriority1;
|
|
|
|
expected.Teb = kTEB1;
|
|
|
|
expected.Stack.StartOfMemoryRange = kMemoryBase1;
|
|
|
|
expected.Stack.Memory.DataSize = kMemorySize1;
|
|
|
|
expected.ThreadContext.DataSize = sizeof(MinidumpContextX86);
|
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr;
|
|
|
|
const MinidumpContextX86* observed_context = nullptr;
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectThread(&expected,
|
|
|
|
&thread_list->Threads[1],
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-09 15:31:29 -04:00
|
|
|
&observed_stack,
|
|
|
|
reinterpret_cast<const void**>(&observed_context)));
|
|
|
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack,
|
|
|
|
observed_stack,
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-09 15:31:29 -04:00
|
|
|
kMemoryValue1,
|
|
|
|
false));
|
2014-11-03 17:43:39 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpContextX86(kSeed1, observed_context, false));
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor(
|
|
|
|
observed_stack, &memory_list->MemoryRanges[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("thread 2");
|
|
|
|
|
|
|
|
MINIDUMP_THREAD expected = {};
|
|
|
|
expected.ThreadId = kThreadID2;
|
|
|
|
expected.SuspendCount = kSuspendCount2;
|
|
|
|
expected.PriorityClass = kPriorityClass2;
|
|
|
|
expected.Priority = kPriority2;
|
|
|
|
expected.Teb = kTEB2;
|
|
|
|
expected.Stack.StartOfMemoryRange = kMemoryBase2;
|
|
|
|
expected.Stack.Memory.DataSize = kMemorySize2;
|
|
|
|
expected.ThreadContext.DataSize = sizeof(MinidumpContextX86);
|
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr;
|
|
|
|
const MinidumpContextX86* observed_context = nullptr;
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectThread(&expected,
|
|
|
|
&thread_list->Threads[2],
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-09 15:31:29 -04:00
|
|
|
&observed_stack,
|
|
|
|
reinterpret_cast<const void**>(&observed_context)));
|
|
|
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack,
|
|
|
|
observed_stack,
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-10-09 15:31:29 -04:00
|
|
|
kMemoryValue2,
|
|
|
|
true));
|
2014-11-03 17:43:39 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpContextX86(kSeed2, observed_context, false));
|
2014-10-09 15:31:29 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor(
|
|
|
|
observed_stack, &memory_list->MemoryRanges[2]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-04 12:36:29 -05:00
|
|
|
struct InitializeFromSnapshotX86Traits {
|
2014-11-05 14:09:01 -05:00
|
|
|
using MinidumpContextType = MinidumpContextX86;
|
2014-11-04 12:36:29 -05:00
|
|
|
static void InitializeCPUContext(CPUContext* context, uint32_t seed) {
|
|
|
|
return InitializeCPUContextX86(context, seed);
|
|
|
|
}
|
|
|
|
static void ExpectMinidumpContext(
|
|
|
|
uint32_t expect_seed, const MinidumpContextX86* observed, bool snapshot) {
|
|
|
|
return ExpectMinidumpContextX86(expect_seed, observed, snapshot);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InitializeFromSnapshotAMD64Traits {
|
2014-11-05 14:09:01 -05:00
|
|
|
using MinidumpContextType = MinidumpContextAMD64;
|
2014-11-04 12:36:29 -05:00
|
|
|
static void InitializeCPUContext(CPUContext* context, uint32_t seed) {
|
|
|
|
return InitializeCPUContextX86_64(context, seed);
|
|
|
|
}
|
|
|
|
static void ExpectMinidumpContext(uint32_t expect_seed,
|
|
|
|
const MinidumpContextAMD64* observed,
|
|
|
|
bool snapshot) {
|
|
|
|
return ExpectMinidumpContextAMD64(expect_seed, observed, snapshot);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InitializeFromSnapshotNoContextTraits {
|
2014-11-05 14:09:01 -05:00
|
|
|
using MinidumpContextType = MinidumpContextX86;
|
2014-11-04 12:36:29 -05:00
|
|
|
static void InitializeCPUContext(CPUContext* context, uint32_t seed) {
|
|
|
|
context->architecture = kCPUArchitectureUnknown;
|
|
|
|
}
|
|
|
|
static void ExpectMinidumpContext(uint32_t expect_seed,
|
|
|
|
const MinidumpContextX86* observed,
|
|
|
|
bool snapshot) {
|
|
|
|
FAIL();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Traits>
|
|
|
|
void RunInitializeFromSnapshotTest(bool thread_id_collision) {
|
2014-11-05 14:09:01 -05:00
|
|
|
using MinidumpContextType = typename Traits::MinidumpContextType;
|
2014-11-04 12:36:29 -05:00
|
|
|
MINIDUMP_THREAD expect_threads[3] = {};
|
2019-01-04 16:57:57 -05:00
|
|
|
uint64_t thread_ids[base::size(expect_threads)] = {};
|
|
|
|
uint8_t memory_values[base::size(expect_threads)] = {};
|
|
|
|
uint32_t context_seeds[base::size(expect_threads)] = {};
|
|
|
|
MINIDUMP_MEMORY_DESCRIPTOR tebs[base::size(expect_threads)] = {};
|
2015-10-01 14:04:49 -07:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kTebSize = 1024;
|
2014-11-04 12:36:29 -05:00
|
|
|
|
|
|
|
expect_threads[0].ThreadId = 1;
|
|
|
|
expect_threads[0].SuspendCount = 2;
|
|
|
|
expect_threads[0].Priority = 3;
|
|
|
|
expect_threads[0].Teb = 0x0123456789abcdef;
|
|
|
|
expect_threads[0].Stack.StartOfMemoryRange = 0x1000;
|
|
|
|
expect_threads[0].Stack.Memory.DataSize = 0x100;
|
|
|
|
expect_threads[0].ThreadContext.DataSize = sizeof(MinidumpContextType);
|
|
|
|
memory_values[0] = 'A';
|
|
|
|
context_seeds[0] = 0x80000000;
|
2015-10-01 14:04:49 -07:00
|
|
|
tebs[0].StartOfMemoryRange = expect_threads[0].Teb;
|
|
|
|
tebs[0].Memory.DataSize = kTebSize;
|
2014-11-04 12:36:29 -05:00
|
|
|
|
|
|
|
// The thread at index 1 has no stack.
|
|
|
|
expect_threads[1].ThreadId = 11;
|
|
|
|
expect_threads[1].SuspendCount = 12;
|
|
|
|
expect_threads[1].Priority = 13;
|
2018-02-01 15:54:56 -08:00
|
|
|
expect_threads[1].Teb = 0x1111111111111111;
|
2014-11-04 12:36:29 -05:00
|
|
|
expect_threads[1].ThreadContext.DataSize = sizeof(MinidumpContextType);
|
|
|
|
context_seeds[1] = 0x40000001;
|
2015-10-01 14:04:49 -07:00
|
|
|
tebs[1].StartOfMemoryRange = expect_threads[1].Teb;
|
|
|
|
tebs[1].Memory.DataSize = kTebSize;
|
2014-11-04 12:36:29 -05:00
|
|
|
|
|
|
|
expect_threads[2].ThreadId = 21;
|
|
|
|
expect_threads[2].SuspendCount = 22;
|
|
|
|
expect_threads[2].Priority = 23;
|
2018-02-01 15:54:56 -08:00
|
|
|
expect_threads[2].Teb = 0xfedcba9876543210;
|
2014-11-04 12:36:29 -05:00
|
|
|
expect_threads[2].Stack.StartOfMemoryRange = 0x3000;
|
|
|
|
expect_threads[2].Stack.Memory.DataSize = 0x300;
|
|
|
|
expect_threads[2].ThreadContext.DataSize = sizeof(MinidumpContextType);
|
|
|
|
memory_values[2] = 'd';
|
|
|
|
context_seeds[2] = 0x20000002;
|
2015-10-01 14:04:49 -07:00
|
|
|
tebs[2].StartOfMemoryRange = expect_threads[2].Teb;
|
|
|
|
tebs[2].Memory.DataSize = kTebSize;
|
2014-11-04 12:36:29 -05:00
|
|
|
|
|
|
|
if (thread_id_collision) {
|
|
|
|
thread_ids[0] = 0x0123456700000001;
|
|
|
|
thread_ids[1] = 0x89abcdef00000001;
|
|
|
|
thread_ids[2] = 4;
|
|
|
|
expect_threads[0].ThreadId = 0;
|
|
|
|
expect_threads[1].ThreadId = 1;
|
|
|
|
expect_threads[2].ThreadId = 2;
|
|
|
|
} else {
|
|
|
|
thread_ids[0] = 1;
|
|
|
|
thread_ids[1] = 11;
|
|
|
|
thread_ids[2] = 22;
|
2015-02-05 09:52:24 -08:00
|
|
|
expect_threads[0].ThreadId = static_cast<uint32_t>(thread_ids[0]);
|
|
|
|
expect_threads[1].ThreadId = static_cast<uint32_t>(thread_ids[1]);
|
|
|
|
expect_threads[2].ThreadId = static_cast<uint32_t>(thread_ids[2]);
|
2014-11-04 12:36:29 -05:00
|
|
|
}
|
|
|
|
|
2017-10-19 00:26:38 -04:00
|
|
|
std::vector<std::unique_ptr<TestThreadSnapshot>> thread_snapshots_owner;
|
2014-11-04 12:36:29 -05:00
|
|
|
std::vector<const ThreadSnapshot*> thread_snapshots;
|
2019-01-04 16:57:57 -05:00
|
|
|
for (size_t index = 0; index < base::size(expect_threads); ++index) {
|
2017-10-19 00:26:38 -04:00
|
|
|
thread_snapshots_owner.push_back(std::make_unique<TestThreadSnapshot>());
|
|
|
|
TestThreadSnapshot* thread_snapshot = thread_snapshots_owner.back().get();
|
2014-11-04 12:36:29 -05:00
|
|
|
|
|
|
|
thread_snapshot->SetThreadID(thread_ids[index]);
|
|
|
|
thread_snapshot->SetSuspendCount(expect_threads[index].SuspendCount);
|
|
|
|
thread_snapshot->SetPriority(expect_threads[index].Priority);
|
|
|
|
thread_snapshot->SetThreadSpecificDataAddress(expect_threads[index].Teb);
|
|
|
|
|
|
|
|
if (expect_threads[index].Stack.Memory.DataSize) {
|
2017-10-12 12:42:28 -04:00
|
|
|
auto memory_snapshot = std::make_unique<TestMemorySnapshot>();
|
2014-11-04 12:36:29 -05:00
|
|
|
memory_snapshot->SetAddress(
|
|
|
|
expect_threads[index].Stack.StartOfMemoryRange);
|
|
|
|
memory_snapshot->SetSize(expect_threads[index].Stack.Memory.DataSize);
|
|
|
|
memory_snapshot->SetValue(memory_values[index]);
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_snapshot->SetStack(std::move(memory_snapshot));
|
2014-11-04 12:36:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Traits::InitializeCPUContext(thread_snapshot->MutableContext(),
|
|
|
|
context_seeds[index]);
|
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto teb_snapshot = std::make_unique<TestMemorySnapshot>();
|
2015-10-01 14:04:49 -07:00
|
|
|
teb_snapshot->SetAddress(expect_threads[index].Teb);
|
|
|
|
teb_snapshot->SetSize(kTebSize);
|
|
|
|
teb_snapshot->SetValue(static_cast<char>('t' + index));
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_snapshot->AddExtraMemory(std::move(teb_snapshot));
|
2015-10-01 14:04:49 -07:00
|
|
|
|
2014-11-04 12:36:29 -05:00
|
|
|
thread_snapshots.push_back(thread_snapshot);
|
|
|
|
}
|
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_list_writer = std::make_unique<MinidumpThreadListWriter>();
|
|
|
|
auto memory_list_writer = std::make_unique<MinidumpMemoryListWriter>();
|
2014-11-04 12:36:29 -05:00
|
|
|
thread_list_writer->SetMemoryListWriter(memory_list_writer.get());
|
|
|
|
MinidumpThreadIDMap thread_id_map;
|
|
|
|
thread_list_writer->InitializeFromSnapshot(thread_snapshots, &thread_id_map);
|
|
|
|
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(thread_list_writer)));
|
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(memory_list_writer)));
|
2014-11-04 12:36:29 -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:36:29 -05:00
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MINIDUMP_THREAD_LIST* thread_list = nullptr;
|
|
|
|
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
|
2014-11-04 12:36:29 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
2015-02-18 14:15:38 -05:00
|
|
|
GetThreadListStream(string_file.string(), &thread_list, &memory_list));
|
2014-11-04 12:36:29 -05: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
|
|
|
ASSERT_EQ(thread_list->NumberOfThreads, 3u);
|
|
|
|
ASSERT_EQ(memory_list->NumberOfMemoryRanges, 5u);
|
2014-11-04 12:36:29 -05:00
|
|
|
|
|
|
|
size_t memory_index = 0;
|
|
|
|
for (size_t index = 0; index < thread_list->NumberOfThreads; ++index) {
|
2015-02-05 15:04:49 -08:00
|
|
|
SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index));
|
2014-11-04 12:36:29 -05:00
|
|
|
|
2015-02-05 09:52:24 -08:00
|
|
|
const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr;
|
2014-11-04 12:36:29 -05:00
|
|
|
const MINIDUMP_MEMORY_DESCRIPTOR** observed_stack_p =
|
|
|
|
expect_threads[index].Stack.Memory.DataSize ? &observed_stack : nullptr;
|
2015-02-05 09:52:24 -08:00
|
|
|
const MinidumpContextType* observed_context = nullptr;
|
2014-11-04 12:36:29 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectThread(&expect_threads[index],
|
|
|
|
&thread_list->Threads[index],
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-11-04 12:36:29 -05:00
|
|
|
observed_stack_p,
|
|
|
|
reinterpret_cast<const void**>(&observed_context)));
|
|
|
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(Traits::ExpectMinidumpContext(
|
|
|
|
context_seeds[index], observed_context, true));
|
|
|
|
|
|
|
|
if (observed_stack_p) {
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptorAndContents(
|
|
|
|
&expect_threads[index].Stack,
|
|
|
|
observed_stack,
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.string(),
|
2014-11-04 12:36:29 -05:00
|
|
|
memory_values[index],
|
2015-10-01 14:04:49 -07:00
|
|
|
false));
|
2014-11-04 12:36:29 -05:00
|
|
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor(
|
|
|
|
observed_stack, &memory_list->MemoryRanges[memory_index]));
|
|
|
|
|
|
|
|
++memory_index;
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 14:04:49 -07:00
|
|
|
|
|
|
|
for (size_t index = 0; index < thread_list->NumberOfThreads; ++index) {
|
|
|
|
const MINIDUMP_MEMORY_DESCRIPTOR* memory =
|
|
|
|
&memory_list->MemoryRanges[memory_index];
|
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
ExpectMinidumpMemoryDescriptor(&tebs[index], memory));
|
|
|
|
std::string expected_data(kTebSize, static_cast<char>('t' + index));
|
|
|
|
std::string observed_data(&string_file.string()[memory->Memory.Rva],
|
|
|
|
memory->Memory.DataSize);
|
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_data, expected_data);
|
2015-10-01 14:04:49 -07:00
|
|
|
++memory_index;
|
|
|
|
}
|
2014-11-04 12:36:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpThreadWriter, InitializeFromSnapshot_x86) {
|
|
|
|
RunInitializeFromSnapshotTest<InitializeFromSnapshotX86Traits>(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpThreadWriter, InitializeFromSnapshot_AMD64) {
|
|
|
|
RunInitializeFromSnapshotTest<InitializeFromSnapshotAMD64Traits>(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpThreadWriter, InitializeFromSnapshot_ThreadIDCollision) {
|
|
|
|
RunInitializeFromSnapshotTest<InitializeFromSnapshotX86Traits>(true);
|
|
|
|
}
|
|
|
|
|
2014-10-09 15:31:29 -04:00
|
|
|
TEST(MinidumpThreadWriterDeathTest, NoContext) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_list_writer = std::make_unique<MinidumpThreadListWriter>();
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto thread_writer = std::make_unique<MinidumpThreadWriter>();
|
2014-10-09 15:31:29 -04:00
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
thread_list_writer->AddThread(std::move(thread_writer));
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(thread_list_writer)));
|
2014-10-09 15:31:29 -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:31:29 -04:00
|
|
|
}
|
|
|
|
|
2014-11-04 12:36:29 -05:00
|
|
|
TEST(MinidumpThreadWriterDeathTest, InitializeFromSnapshot_NoContext) {
|
2015-03-09 18:02:14 -04:00
|
|
|
ASSERT_DEATH_CHECK(
|
2014-11-04 12:36:29 -05:00
|
|
|
RunInitializeFromSnapshotTest<InitializeFromSnapshotNoContextTraits>(
|
|
|
|
false), "context_");
|
|
|
|
}
|
|
|
|
|
2014-10-09 15:31:29 -04:00
|
|
|
} // namespace
|
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|