OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #include "snapshot/minidump/process_snapshot_minidump.h" |
| 16 |
| 17 #include <string.h> |
| 18 #include <windows.h> |
| 19 #include <dbghelp.h> |
| 20 |
| 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "gtest/gtest.h" |
| 23 #include "util/file/string_file.h" |
| 24 |
| 25 namespace crashpad { |
| 26 namespace test { |
| 27 namespace { |
| 28 |
| 29 TEST(ProcessSnapshotMinidump, EmptyFile) { |
| 30 StringFile string_file; |
| 31 ProcessSnapshotMinidump process_snapshot; |
| 32 |
| 33 EXPECT_FALSE(process_snapshot.Initialize(&string_file)); |
| 34 } |
| 35 |
| 36 TEST(ProcessSnapshotMinidump, InvalidSignatureAndVersion) { |
| 37 StringFile string_file; |
| 38 |
| 39 MINIDUMP_HEADER header = {}; |
| 40 |
| 41 EXPECT_TRUE(string_file.Write(&header, sizeof(header))); |
| 42 |
| 43 ProcessSnapshotMinidump process_snapshot; |
| 44 EXPECT_FALSE(process_snapshot.Initialize(&string_file)); |
| 45 } |
| 46 |
| 47 TEST(ProcessSnapshotMinidump, Empty) { |
| 48 StringFile string_file; |
| 49 |
| 50 MINIDUMP_HEADER header = {}; |
| 51 header.Signature = MINIDUMP_SIGNATURE; |
| 52 header.Version = MINIDUMP_VERSION; |
| 53 |
| 54 EXPECT_TRUE(string_file.Write(&header, sizeof(header))); |
| 55 |
| 56 ProcessSnapshotMinidump process_snapshot; |
| 57 EXPECT_TRUE(process_snapshot.Initialize(&string_file)); |
| 58 } |
| 59 |
| 60 TEST(ProcessSnapshotMinidump, AnnotationsSimpleMap) { |
| 61 StringFile string_file; |
| 62 |
| 63 MINIDUMP_HEADER header = {}; |
| 64 EXPECT_TRUE(string_file.Write(&header, sizeof(header))); |
| 65 |
| 66 MinidumpSimpleStringDictionaryEntry entry0 = {}; |
| 67 entry0.key = static_cast<RVA>(string_file.SeekGet()); |
| 68 const char kKey0[] = "the first key"; |
| 69 uint32_t string_size = strlen(kKey0); |
| 70 EXPECT_TRUE(string_file.Write(&string_size, sizeof(string_size))); |
| 71 EXPECT_TRUE(string_file.Write(kKey0, sizeof(kKey0))); |
| 72 |
| 73 entry0.value = static_cast<RVA>(string_file.SeekGet()); |
| 74 const char kValue0[] = "THE FIRST VALUE EVER!"; |
| 75 string_size = strlen(kValue0); |
| 76 EXPECT_TRUE(string_file.Write(&string_size, sizeof(string_size))); |
| 77 EXPECT_TRUE(string_file.Write(kValue0, sizeof(kValue0))); |
| 78 |
| 79 MinidumpSimpleStringDictionaryEntry entry1 = {}; |
| 80 entry1.key = static_cast<RVA>(string_file.SeekGet()); |
| 81 const char kKey1[] = "2key"; |
| 82 string_size = strlen(kKey1); |
| 83 EXPECT_TRUE(string_file.Write(&string_size, sizeof(string_size))); |
| 84 EXPECT_TRUE(string_file.Write(kKey1, sizeof(kKey1))); |
| 85 |
| 86 entry1.value = static_cast<RVA>(string_file.SeekGet()); |
| 87 const char kValue1[] = "a lowly second value"; |
| 88 string_size = strlen(kValue1); |
| 89 EXPECT_TRUE(string_file.Write(&string_size, sizeof(string_size))); |
| 90 EXPECT_TRUE(string_file.Write(kValue1, sizeof(kValue1))); |
| 91 |
| 92 MinidumpCrashpadInfo crashpad_info = {}; |
| 93 crashpad_info.version = MinidumpCrashpadInfo::kVersion; |
| 94 |
| 95 crashpad_info.simple_annotations.Rva = |
| 96 static_cast<RVA>(string_file.SeekGet()); |
| 97 uint32_t simple_string_dictionary_entries = 2; |
| 98 EXPECT_TRUE(string_file.Write(&simple_string_dictionary_entries, |
| 99 sizeof(simple_string_dictionary_entries))); |
| 100 EXPECT_TRUE(string_file.Write(&entry0, sizeof(entry0))); |
| 101 EXPECT_TRUE(string_file.Write(&entry1, sizeof(entry1))); |
| 102 crashpad_info.simple_annotations.DataSize = |
| 103 simple_string_dictionary_entries * |
| 104 sizeof(MinidumpSimpleStringDictionaryEntry); |
| 105 |
| 106 MINIDUMP_DIRECTORY crashpad_info_directory = {}; |
| 107 crashpad_info_directory.StreamType = kMinidumpStreamTypeCrashpadInfo; |
| 108 crashpad_info_directory.Location.Rva = |
| 109 static_cast<RVA>(string_file.SeekGet()); |
| 110 EXPECT_TRUE(string_file.Write(&crashpad_info, sizeof(crashpad_info))); |
| 111 crashpad_info_directory.Location.DataSize = sizeof(crashpad_info); |
| 112 |
| 113 header.StreamDirectoryRva = static_cast<RVA>(string_file.SeekGet()); |
| 114 EXPECT_TRUE(string_file.Write(&crashpad_info_directory, |
| 115 sizeof(crashpad_info_directory))); |
| 116 |
| 117 header.Signature = MINIDUMP_SIGNATURE; |
| 118 header.Version = MINIDUMP_VERSION; |
| 119 header.NumberOfStreams = 1; |
| 120 EXPECT_TRUE(string_file.SeekSet(0)); |
| 121 EXPECT_TRUE(string_file.Write(&header, sizeof(header))); |
| 122 |
| 123 ProcessSnapshotMinidump process_snapshot; |
| 124 EXPECT_TRUE(process_snapshot.Initialize(&string_file)); |
| 125 |
| 126 const auto annotations_simple_map = process_snapshot.AnnotationsSimpleMap(); |
| 127 EXPECT_EQ(2u, annotations_simple_map.size()); |
| 128 |
| 129 auto it = annotations_simple_map.find(kKey0); |
| 130 ASSERT_NE(it, annotations_simple_map.end()); |
| 131 EXPECT_EQ(kValue0, it->second); |
| 132 |
| 133 it = annotations_simple_map.find(kKey1); |
| 134 ASSERT_NE(it, annotations_simple_map.end()); |
| 135 EXPECT_EQ(kValue1, it->second); |
| 136 } |
| 137 |
| 138 } // namespace |
| 139 } // namespace test |
| 140 } // namespace crashpad |
OLD | NEW |