OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "minidump/minidump_module_writer.h" | 15 #include "minidump/minidump_module_writer.h" |
16 | 16 |
17 #include <dbghelp.h> | 17 #include <dbghelp.h> |
18 #include <stdint.h> | 18 #include <stdint.h> |
19 #include <string.h> | 19 #include <string.h> |
20 | 20 |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
23 #include "minidump/minidump_extensions.h" | 23 #include "minidump/minidump_extensions.h" |
24 #include "minidump/minidump_file_writer.h" | 24 #include "minidump/minidump_file_writer.h" |
25 #include "minidump/test/minidump_file_writer_test_util.h" | 25 #include "minidump/test/minidump_file_writer_test_util.h" |
| 26 #include "minidump/test/minidump_string_writer_test_util.h" |
26 #include "util/file/string_file_writer.h" | 27 #include "util/file/string_file_writer.h" |
27 #include "util/misc/uuid.h" | 28 #include "util/misc/uuid.h" |
28 | 29 |
29 namespace crashpad { | 30 namespace crashpad { |
30 namespace test { | 31 namespace test { |
31 namespace { | 32 namespace { |
32 | 33 |
33 void GetModuleListStream(const std::string& file_contents, | 34 void GetModuleListStream(const std::string& file_contents, |
34 const MINIDUMP_MODULE_LIST** module_list) { | 35 const MINIDUMP_MODULE_LIST** module_list) { |
35 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 36 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
36 const size_t kModuleListStreamOffset = | 37 const size_t kModuleListStreamOffset = |
37 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); | 38 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); |
38 const size_t kModulesOffset = | 39 const size_t kModulesOffset = |
39 kModuleListStreamOffset + sizeof(MINIDUMP_MODULE_LIST); | 40 kModuleListStreamOffset + sizeof(MINIDUMP_MODULE_LIST); |
40 | 41 |
41 ASSERT_GE(file_contents.size(), kModulesOffset); | 42 ASSERT_GE(file_contents.size(), kModulesOffset); |
42 | 43 |
| 44 const MINIDUMP_DIRECTORY* directory; |
43 const MINIDUMP_HEADER* header = | 45 const MINIDUMP_HEADER* header = |
44 reinterpret_cast<const MINIDUMP_HEADER*>(&file_contents[0]); | 46 MinidumpHeaderAtStart(file_contents, &directory); |
| 47 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); |
| 48 ASSERT_TRUE(directory); |
45 | 49 |
46 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); | 50 ASSERT_EQ(kMinidumpStreamTypeModuleList, directory[0].StreamType); |
47 | 51 ASSERT_GE(directory[0].Location.DataSize, sizeof(MINIDUMP_MODULE_LIST)); |
48 const MINIDUMP_DIRECTORY* directory = | 52 ASSERT_EQ(kModuleListStreamOffset, directory[0].Location.Rva); |
49 reinterpret_cast<const MINIDUMP_DIRECTORY*>( | |
50 &file_contents[kDirectoryOffset]); | |
51 | |
52 ASSERT_EQ(kMinidumpStreamTypeModuleList, directory->StreamType); | |
53 ASSERT_GE(directory->Location.DataSize, sizeof(MINIDUMP_MODULE_LIST)); | |
54 ASSERT_EQ(kModuleListStreamOffset, directory->Location.Rva); | |
55 | 53 |
56 *module_list = reinterpret_cast<const MINIDUMP_MODULE_LIST*>( | 54 *module_list = reinterpret_cast<const MINIDUMP_MODULE_LIST*>( |
57 &file_contents[kModuleListStreamOffset]); | 55 &file_contents[kModuleListStreamOffset]); |
58 | 56 |
59 ASSERT_EQ(sizeof(MINIDUMP_MODULE_LIST) + | 57 ASSERT_EQ(sizeof(MINIDUMP_MODULE_LIST) + |
60 (*module_list)->NumberOfModules * sizeof(MINIDUMP_MODULE), | 58 (*module_list)->NumberOfModules * sizeof(MINIDUMP_MODULE), |
61 directory->Location.DataSize); | 59 directory[0].Location.DataSize); |
62 } | 60 } |
63 | 61 |
64 TEST(MinidumpModuleWriter, EmptyModuleList) { | 62 TEST(MinidumpModuleWriter, EmptyModuleList) { |
65 MinidumpFileWriter minidump_file_writer; | 63 MinidumpFileWriter minidump_file_writer; |
66 MinidumpModuleListWriter module_list_writer; | 64 MinidumpModuleListWriter module_list_writer; |
67 | 65 |
68 minidump_file_writer.AddStream(&module_list_writer); | 66 minidump_file_writer.AddStream(&module_list_writer); |
69 | 67 |
70 StringFileWriter file_writer; | 68 StringFileWriter file_writer; |
71 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 69 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 EXPECT_EQ(expected->VersionInfo.dwFileSubtype, | 247 EXPECT_EQ(expected->VersionInfo.dwFileSubtype, |
250 observed->VersionInfo.dwFileSubtype); | 248 observed->VersionInfo.dwFileSubtype); |
251 EXPECT_EQ(expected->VersionInfo.dwFileDateMS, | 249 EXPECT_EQ(expected->VersionInfo.dwFileDateMS, |
252 observed->VersionInfo.dwFileDateMS); | 250 observed->VersionInfo.dwFileDateMS); |
253 EXPECT_EQ(expected->VersionInfo.dwFileDateLS, | 251 EXPECT_EQ(expected->VersionInfo.dwFileDateLS, |
254 observed->VersionInfo.dwFileDateLS); | 252 observed->VersionInfo.dwFileDateLS); |
255 EXPECT_EQ(0u, observed->Reserved0); | 253 EXPECT_EQ(0u, observed->Reserved0); |
256 EXPECT_EQ(0u, observed->Reserved1); | 254 EXPECT_EQ(0u, observed->Reserved1); |
257 | 255 |
258 EXPECT_NE(0u, observed->ModuleNameRva); | 256 EXPECT_NE(0u, observed->ModuleNameRva); |
259 ASSERT_LE(observed->ModuleNameRva, | 257 string16 observed_module_name_utf16 = |
260 file_contents.size() - sizeof(MINIDUMP_STRING)); | 258 MinidumpStringAtRVAAsString(file_contents, observed->ModuleNameRva); |
261 const MINIDUMP_STRING* module_name = reinterpret_cast<const MINIDUMP_STRING*>( | |
262 &file_contents[observed->ModuleNameRva]); | |
263 ASSERT_LE(observed->ModuleNameRva + sizeof(MINIDUMP_STRING) + | |
264 (module_name->Length + 1), | |
265 file_contents.size()); | |
266 ASSERT_EQ(0u, module_name->Length % 2); | |
267 string16 observed_module_name_utf16( | |
268 reinterpret_cast<const char16*>( | |
269 &file_contents[observed->ModuleNameRva + sizeof(MINIDUMP_STRING)]), | |
270 module_name->Length / 2); | |
271 string16 expected_module_name_utf16 = base::UTF8ToUTF16(expected_module_name); | 259 string16 expected_module_name_utf16 = base::UTF8ToUTF16(expected_module_name); |
272 EXPECT_EQ(expected_module_name_utf16, observed_module_name_utf16); | 260 EXPECT_EQ(expected_module_name_utf16, observed_module_name_utf16); |
273 | 261 |
274 ASSERT_NO_FATAL_FAILURE(ExpectCodeViewRecord(&observed->CvRecord, | 262 ASSERT_NO_FATAL_FAILURE(ExpectCodeViewRecord(&observed->CvRecord, |
275 file_contents, | 263 file_contents, |
276 expected_pdb_name, | 264 expected_pdb_name, |
277 expected_pdb_uuid, | 265 expected_pdb_uuid, |
278 expected_pdb_timestamp, | 266 expected_pdb_timestamp, |
279 expected_pdb_age)); | 267 expected_pdb_age)); |
280 | 268 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 module_list_writer.AddModule(&module_writer); | 617 module_list_writer.AddModule(&module_writer); |
630 minidump_file_writer.AddStream(&module_list_writer); | 618 minidump_file_writer.AddStream(&module_list_writer); |
631 | 619 |
632 StringFileWriter file_writer; | 620 StringFileWriter file_writer; |
633 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "name_"); | 621 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "name_"); |
634 } | 622 } |
635 | 623 |
636 } // namespace | 624 } // namespace |
637 } // namespace test | 625 } // namespace test |
638 } // namespace crashpad | 626 } // namespace crashpad |
OLD | NEW |