2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2015 The Crashpad Authors
|
2015-10-13 13:15:44 -07: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_memory_info_writer.h"
|
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
#include <memory>
|
2015-10-13 13:15:44 -07:00
|
|
|
#include <string>
|
2015-12-09 17:36:32 -05:00
|
|
|
#include <utility>
|
2015-10-13 13:15:44 -07:00
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "minidump/minidump_file_writer.h"
|
|
|
|
#include "minidump/test/minidump_file_writer_test_util.h"
|
|
|
|
#include "minidump/test/minidump_writable_test_util.h"
|
|
|
|
#include "snapshot/test/test_memory_map_region_snapshot.h"
|
|
|
|
#include "util/file/string_file.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// The memory info list is expected to be the only stream.
|
|
|
|
void GetMemoryInfoListStream(
|
|
|
|
const std::string& file_contents,
|
|
|
|
const MINIDUMP_MEMORY_INFO_LIST** memory_info_list) {
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
|
|
|
|
constexpr size_t kMemoryInfoListStreamOffset =
|
2015-10-13 13:15:44 -07: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;
|
2015-10-13 13:15:44 -07: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,
|
|
|
|
kMinidumpStreamTypeMemoryInfoList);
|
|
|
|
EXPECT_EQ(directory[kDirectoryIndex].Location.Rva,
|
|
|
|
kMemoryInfoListStreamOffset);
|
2015-10-13 13:15:44 -07:00
|
|
|
|
|
|
|
*memory_info_list =
|
|
|
|
MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_INFO_LIST>(
|
|
|
|
file_contents, directory[kDirectoryIndex].Location);
|
2015-10-21 10:43:42 -07:00
|
|
|
ASSERT_TRUE(*memory_info_list);
|
2015-10-13 13:15:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMemoryInfoWriter, Empty) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
|
|
|
auto memory_info_list_writer =
|
2017-10-12 12:42:28 -04:00
|
|
|
std::make_unique<MinidumpMemoryInfoListWriter>();
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(
|
|
|
|
minidump_file_writer.AddStream(std::move(memory_info_list_writer)));
|
2015-10-13 13:15:44 -07: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) +
|
|
|
|
sizeof(MINIDUMP_MEMORY_INFO_LIST));
|
2015-10-13 13:15:44 -07:00
|
|
|
|
|
|
|
const MINIDUMP_MEMORY_INFO_LIST* memory_info_list = nullptr;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
GetMemoryInfoListStream(string_file.string(), &memory_info_list));
|
|
|
|
|
2020-12-09 22:21:38 +00:00
|
|
|
uint64_t number_of_entries;
|
|
|
|
memcpy(&number_of_entries,
|
|
|
|
&memory_info_list->NumberOfEntries,
|
|
|
|
sizeof(number_of_entries));
|
|
|
|
EXPECT_EQ(number_of_entries, 0u);
|
2015-10-13 13:15:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMemoryInfoWriter, OneRegion) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
|
|
|
auto memory_info_list_writer =
|
2017-10-12 12:42:28 -04:00
|
|
|
std::make_unique<MinidumpMemoryInfoListWriter>();
|
2015-10-13 13:15:44 -07:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto memory_map_region = std::make_unique<TestMemoryMapRegionSnapshot>();
|
2015-10-13 13:15:44 -07:00
|
|
|
|
2018-01-10 14:16:31 -08:00
|
|
|
MINIDUMP_MEMORY_INFO mmi;
|
2015-10-13 13:15:44 -07:00
|
|
|
mmi.BaseAddress = 0x12340000;
|
|
|
|
mmi.AllocationBase = 0x12000000;
|
|
|
|
mmi.AllocationProtect = PAGE_READWRITE;
|
2018-01-10 14:16:31 -08:00
|
|
|
mmi.__alignment1 = 0;
|
2015-10-13 13:15:44 -07:00
|
|
|
mmi.RegionSize = 0x6000;
|
|
|
|
mmi.State = MEM_COMMIT;
|
|
|
|
mmi.Protect = PAGE_NOACCESS;
|
|
|
|
mmi.Type = MEM_PRIVATE;
|
2018-01-10 14:16:31 -08:00
|
|
|
mmi.__alignment2 = 0;
|
2015-10-13 13:15:44 -07:00
|
|
|
memory_map_region->SetMindumpMemoryInfo(mmi);
|
|
|
|
|
|
|
|
std::vector<const MemoryMapRegionSnapshot*> memory_map;
|
|
|
|
memory_map.push_back(memory_map_region.get());
|
|
|
|
memory_info_list_writer->InitializeFromSnapshot(memory_map);
|
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(
|
|
|
|
minidump_file_writer.AddStream(std::move(memory_info_list_writer)));
|
2015-10-13 13:15:44 -07: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) +
|
2015-10-13 13:15:44 -07:00
|
|
|
sizeof(MINIDUMP_MEMORY_INFO_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
|
|
|
sizeof(MINIDUMP_MEMORY_INFO));
|
2015-10-13 13:15:44 -07:00
|
|
|
|
|
|
|
const MINIDUMP_MEMORY_INFO_LIST* memory_info_list = nullptr;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
GetMemoryInfoListStream(string_file.string(), &memory_info_list));
|
|
|
|
|
2020-12-09 22:21:38 +00:00
|
|
|
uint64_t number_of_entries;
|
|
|
|
memcpy(&number_of_entries,
|
|
|
|
&memory_info_list->NumberOfEntries,
|
|
|
|
sizeof(number_of_entries));
|
|
|
|
EXPECT_EQ(number_of_entries, 1u);
|
|
|
|
|
|
|
|
MINIDUMP_MEMORY_INFO memory_info;
|
|
|
|
memcpy(&memory_info, &memory_info_list[1], sizeof(memory_info));
|
|
|
|
EXPECT_EQ(memory_info.BaseAddress, mmi.BaseAddress);
|
|
|
|
EXPECT_EQ(memory_info.AllocationBase, mmi.AllocationBase);
|
|
|
|
EXPECT_EQ(memory_info.AllocationProtect, mmi.AllocationProtect);
|
|
|
|
EXPECT_EQ(memory_info.RegionSize, mmi.RegionSize);
|
|
|
|
EXPECT_EQ(memory_info.State, mmi.State);
|
|
|
|
EXPECT_EQ(memory_info.Protect, mmi.Protect);
|
|
|
|
EXPECT_EQ(memory_info.Type, mmi.Type);
|
2015-10-13 13:15:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|