2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2016 The Crashpad Authors
|
2016-02-29 13:28:05 -08: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_user_stream_writer.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "minidump/minidump_file_writer.h"
|
|
|
|
#include "minidump/test/minidump_file_writer_test_util.h"
|
2017-04-11 14:48:10 -04:00
|
|
|
#include "minidump/test/minidump_user_extension_stream_util.h"
|
2016-02-29 13:28:05 -08:00
|
|
|
#include "minidump/test/minidump_writable_test_util.h"
|
|
|
|
#include "snapshot/test/test_memory_snapshot.h"
|
|
|
|
#include "util/file/string_file.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// The user stream is expected to be the only stream.
|
|
|
|
void GetUserStream(const std::string& file_contents,
|
|
|
|
MINIDUMP_LOCATION_DESCRIPTOR* user_stream_location,
|
2017-03-23 08:52:46 -04:00
|
|
|
uint32_t stream_type,
|
|
|
|
size_t stream_size) {
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
|
|
|
|
constexpr size_t kUserStreamOffset =
|
2016-02-29 13:28:05 -08:00
|
|
|
kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY);
|
|
|
|
|
|
|
|
const MINIDUMP_DIRECTORY* directory;
|
|
|
|
const MINIDUMP_HEADER* header =
|
|
|
|
MinidumpHeaderAtStart(file_contents, &directory);
|
|
|
|
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0));
|
|
|
|
ASSERT_TRUE(directory);
|
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kDirectoryIndex = 0;
|
2016-02-29 13:28:05 -08: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[kDirectoryIndex].StreamType, stream_type);
|
|
|
|
EXPECT_EQ(directory[kDirectoryIndex].Location.Rva, kUserStreamOffset);
|
|
|
|
EXPECT_EQ(directory[kDirectoryIndex].Location.DataSize, stream_size);
|
2016-02-29 13:28:05 -08:00
|
|
|
*user_stream_location = directory[kDirectoryIndex].Location;
|
|
|
|
}
|
|
|
|
|
2017-03-23 08:52:46 -04:00
|
|
|
constexpr MinidumpStreamType kTestStreamId =
|
|
|
|
static_cast<MinidumpStreamType>(0x123456);
|
|
|
|
|
|
|
|
TEST(MinidumpUserStreamWriter, InitializeFromSnapshotNoData) {
|
2016-02-29 13:28:05 -08:00
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto user_stream_writer = std::make_unique<MinidumpUserStreamWriter>();
|
|
|
|
auto stream = std::make_unique<UserMinidumpStream>(kTestStreamId, nullptr);
|
2016-02-29 13:28:05 -08:00
|
|
|
user_stream_writer->InitializeFromSnapshot(stream.get());
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(user_stream_writer)));
|
2016-02-29 13:28:05 -08:00
|
|
|
|
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
|
|
|
|
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));
|
2016-02-29 13:28:05 -08:00
|
|
|
|
|
|
|
MINIDUMP_LOCATION_DESCRIPTOR user_stream_location;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(GetUserStream(
|
2017-03-23 08:52:46 -04:00
|
|
|
string_file.string(), &user_stream_location, kTestStreamId, 0u));
|
|
|
|
}
|
|
|
|
|
2017-04-11 14:48:10 -04:00
|
|
|
TEST(MinidumpUserStreamWriter, InitializeFromUserExtensionStreamNoData) {
|
2017-03-23 08:52:46 -04:00
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto data_source = std::make_unique<test::BufferExtensionStreamDataSource>(
|
|
|
|
kTestStreamId, nullptr, 0);
|
|
|
|
auto user_stream_writer = std::make_unique<MinidumpUserStreamWriter>();
|
2017-04-11 14:48:10 -04:00
|
|
|
user_stream_writer->InitializeFromUserExtensionStream(std::move(data_source));
|
2017-03-23 08:52:46 -04:00
|
|
|
minidump_file_writer.AddStream(std::move(user_stream_writer));
|
|
|
|
|
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
|
|
|
|
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));
|
2017-03-23 08:52:46 -04:00
|
|
|
|
|
|
|
MINIDUMP_LOCATION_DESCRIPTOR user_stream_location;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(GetUserStream(
|
|
|
|
string_file.string(), &user_stream_location, kTestStreamId, 0u));
|
2016-02-29 13:28:05 -08:00
|
|
|
}
|
|
|
|
|
2017-03-23 08:52:46 -04:00
|
|
|
TEST(MinidumpUserStreamWriter, InitializeFromSnapshotOneStream) {
|
2016-02-29 13:28:05 -08:00
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto user_stream_writer = std::make_unique<MinidumpUserStreamWriter>();
|
2016-02-29 13:28:05 -08:00
|
|
|
|
|
|
|
TestMemorySnapshot* test_data = new TestMemorySnapshot();
|
|
|
|
test_data->SetAddress(97865);
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kStreamSize = 128;
|
2016-02-29 13:28:05 -08:00
|
|
|
test_data->SetSize(kStreamSize);
|
|
|
|
test_data->SetValue('c');
|
2017-10-12 12:42:28 -04:00
|
|
|
auto stream = std::make_unique<UserMinidumpStream>(kTestStreamId, test_data);
|
2016-02-29 13:28:05 -08:00
|
|
|
user_stream_writer->InitializeFromSnapshot(stream.get());
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(user_stream_writer)));
|
2016-02-29 13:28:05 -08:00
|
|
|
|
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
|
|
|
|
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) + kStreamSize);
|
2016-02-29 13:28:05 -08:00
|
|
|
|
2017-03-23 08:52:46 -04:00
|
|
|
MINIDUMP_LOCATION_DESCRIPTOR user_stream_location = {};
|
|
|
|
ASSERT_NO_FATAL_FAILURE(GetUserStream(
|
|
|
|
string_file.string(), &user_stream_location, kTestStreamId, kStreamSize));
|
|
|
|
const std::string stream_data = string_file.string().substr(
|
|
|
|
user_stream_location.Rva, user_stream_location.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(stream_data, std::string(kStreamSize, 'c'));
|
2017-03-23 08:52:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpUserStreamWriter, InitializeFromBufferOneStream) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kStreamSize = 128;
|
2017-03-23 08:52:46 -04:00
|
|
|
std::vector<uint8_t> data(kStreamSize, 'c');
|
2017-10-12 12:42:28 -04:00
|
|
|
auto data_source = std::make_unique<test::BufferExtensionStreamDataSource>(
|
|
|
|
kTestStreamId, &data[0], data.size());
|
|
|
|
auto user_stream_writer = std::make_unique<MinidumpUserStreamWriter>();
|
2017-04-11 14:48:10 -04:00
|
|
|
user_stream_writer->InitializeFromUserExtensionStream(std::move(data_source));
|
2017-03-23 08:52:46 -04:00
|
|
|
minidump_file_writer.AddStream(std::move(user_stream_writer));
|
|
|
|
|
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
|
|
|
|
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) + kStreamSize);
|
2017-03-23 08:52:46 -04:00
|
|
|
|
|
|
|
MINIDUMP_LOCATION_DESCRIPTOR user_stream_location = {};
|
2016-02-29 13:28:05 -08:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetUserStream(
|
2017-03-23 08:52:46 -04:00
|
|
|
string_file.string(), &user_stream_location, kTestStreamId, kStreamSize));
|
2016-02-29 13:28:05 -08:00
|
|
|
const std::string stream_data = string_file.string().substr(
|
|
|
|
user_stream_location.Rva, user_stream_location.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(stream_data, std::string(kStreamSize, 'c'));
|
2016-02-29 13:28:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|