| 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_system_info_writer.h" | 15 #include "minidump/minidump_system_info_writer.h" |
| 16 | 16 |
| 17 #include <dbghelp.h> | 17 #include <dbghelp.h> |
| 18 #include <string.h> | 18 #include <string.h> |
| 19 | 19 |
| 20 #include <string> | 20 #include <string> |
| 21 | 21 |
| 22 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
| 23 #include "minidump/minidump_file_writer.h" | 23 #include "minidump/minidump_file_writer.h" |
| 24 #include "minidump/test/minidump_file_writer_test_util.h" | 24 #include "minidump/test/minidump_file_writer_test_util.h" |
| 25 #include "minidump/test/minidump_string_writer_test_util.h" |
| 25 #include "util/file/string_file_writer.h" | 26 #include "util/file/string_file_writer.h" |
| 26 | 27 |
| 27 namespace crashpad { | 28 namespace crashpad { |
| 28 namespace test { | 29 namespace test { |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 void GetSystemInfoStream(const std::string& file_contents, | 32 void GetSystemInfoStream(const std::string& file_contents, |
| 32 size_t csd_version_length, | 33 size_t csd_version_length, |
| 33 const MINIDUMP_SYSTEM_INFO** system_info, | 34 const MINIDUMP_SYSTEM_INFO** system_info, |
| 34 const MINIDUMP_STRING** csd_version) { | 35 const MINIDUMP_STRING** csd_version) { |
| 35 // The expected number of bytes for the CSD version’s MINIDUMP_STRING::Buffer. | 36 // The expected number of bytes for the CSD version’s MINIDUMP_STRING::Buffer. |
| 36 const size_t kCSDVersionBytes = | 37 const size_t kCSDVersionBytes = |
| 37 csd_version_length * sizeof(MINIDUMP_STRING::Buffer[0]); | 38 csd_version_length * sizeof(MINIDUMP_STRING::Buffer[0]); |
| 38 const size_t kCSDVersionBytesWithNUL = | 39 const size_t kCSDVersionBytesWithNUL = |
| 39 kCSDVersionBytes + sizeof(MINIDUMP_STRING::Buffer[0]); | 40 kCSDVersionBytes + sizeof(MINIDUMP_STRING::Buffer[0]); |
| 40 | 41 |
| 41 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 42 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
| 42 const size_t kSystemInfoStreamOffset = | 43 const size_t kSystemInfoStreamOffset = |
| 43 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); | 44 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); |
| 44 const size_t kCSDVersionOffset = | 45 const size_t kCSDVersionOffset = |
| 45 kSystemInfoStreamOffset + sizeof(MINIDUMP_SYSTEM_INFO); | 46 kSystemInfoStreamOffset + sizeof(MINIDUMP_SYSTEM_INFO); |
| 46 const size_t kFileSize = | 47 const size_t kFileSize = |
| 47 kCSDVersionOffset + sizeof(MINIDUMP_STRING) + kCSDVersionBytesWithNUL; | 48 kCSDVersionOffset + sizeof(MINIDUMP_STRING) + kCSDVersionBytesWithNUL; |
| 48 | 49 |
| 49 ASSERT_EQ(kFileSize, file_contents.size()); | 50 ASSERT_EQ(kFileSize, file_contents.size()); |
| 50 | 51 |
| 52 const MINIDUMP_DIRECTORY* directory; |
| 51 const MINIDUMP_HEADER* header = | 53 const MINIDUMP_HEADER* header = |
| 52 reinterpret_cast<const MINIDUMP_HEADER*>(&file_contents[0]); | 54 MinidumpHeaderAtStart(file_contents, &directory); |
| 55 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); |
| 56 ASSERT_TRUE(directory); |
| 53 | 57 |
| 54 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); | 58 ASSERT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType); |
| 55 | 59 ASSERT_EQ(sizeof(MINIDUMP_SYSTEM_INFO), directory[0].Location.DataSize); |
| 56 const MINIDUMP_DIRECTORY* directory = | 60 ASSERT_EQ(kSystemInfoStreamOffset, directory[0].Location.Rva); |
| 57 reinterpret_cast<const MINIDUMP_DIRECTORY*>( | |
| 58 &file_contents[kDirectoryOffset]); | |
| 59 | |
| 60 ASSERT_EQ(kMinidumpStreamTypeSystemInfo, directory->StreamType); | |
| 61 ASSERT_EQ(sizeof(MINIDUMP_SYSTEM_INFO), directory->Location.DataSize); | |
| 62 ASSERT_EQ(kSystemInfoStreamOffset, directory->Location.Rva); | |
| 63 | 61 |
| 64 *system_info = reinterpret_cast<const MINIDUMP_SYSTEM_INFO*>( | 62 *system_info = reinterpret_cast<const MINIDUMP_SYSTEM_INFO*>( |
| 65 &file_contents[kSystemInfoStreamOffset]); | 63 &file_contents[kSystemInfoStreamOffset]); |
| 66 | 64 |
| 67 ASSERT_EQ(kCSDVersionOffset, (*system_info)->CSDVersionRva); | 65 ASSERT_EQ(kCSDVersionOffset, (*system_info)->CSDVersionRva); |
| 68 | 66 |
| 69 *csd_version = reinterpret_cast<const MINIDUMP_STRING*>( | 67 *csd_version = |
| 70 &file_contents[kCSDVersionOffset]); | 68 MinidumpStringAtRVA(file_contents, (*system_info)->CSDVersionRva); |
| 71 | |
| 72 ASSERT_EQ(kCSDVersionBytes, (*csd_version)->Length); | 69 ASSERT_EQ(kCSDVersionBytes, (*csd_version)->Length); |
| 73 } | 70 } |
| 74 | 71 |
| 75 TEST(MinidumpSystemInfoWriter, Empty) { | 72 TEST(MinidumpSystemInfoWriter, Empty) { |
| 76 MinidumpFileWriter minidump_file_writer; | 73 MinidumpFileWriter minidump_file_writer; |
| 77 MinidumpSystemInfoWriter system_info_writer; | 74 MinidumpSystemInfoWriter system_info_writer; |
| 78 | 75 |
| 79 system_info_writer.SetCSDVersion(std::string()); | 76 system_info_writer.SetCSDVersion(std::string()); |
| 80 | 77 |
| 81 minidump_file_writer.AddStream(&system_info_writer); | 78 minidump_file_writer.AddStream(&system_info_writer); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 minidump_file_writer.AddStream(&system_info_writer); | 273 minidump_file_writer.AddStream(&system_info_writer); |
| 277 | 274 |
| 278 StringFileWriter file_writer; | 275 StringFileWriter file_writer; |
| 279 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), | 276 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), |
| 280 "csd_version_"); | 277 "csd_version_"); |
| 281 } | 278 } |
| 282 | 279 |
| 283 } // namespace | 280 } // namespace |
| 284 } // namespace test | 281 } // namespace test |
| 285 } // namespace crashpad | 282 } // namespace crashpad |
| OLD | NEW |