| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/browser_watcher/postmortem_minidump_writer.h" | 5 #include "components/browser_watcher/postmortem_minidump_writer.h" |
| 6 | 6 |
| 7 #include <windows.h> // NOLINT | 7 #include <windows.h> // NOLINT |
| 8 #include <dbghelp.h> | 8 #include <dbghelp.h> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/files/scoped_file.h" | 12 #include "base/files/scoped_file.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/win/scoped_handle.h" | 14 #include "base/win/scoped_handle.h" |
| 15 #include "components/browser_watcher/stability_report.pb.h" | 15 #include "components/browser_watcher/stability_report.pb.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/crashpad/crashpad/snapshot/minidump/process_snapshot_minid
ump.h" | 17 #include "third_party/crashpad/crashpad/snapshot/minidump/process_snapshot_minid
ump.h" |
| 18 #include "third_party/crashpad/crashpad/util/file/file_reader.h" | 18 #include "third_party/crashpad/crashpad/util/file/file_reader.h" |
| 19 #include "third_party/crashpad/crashpad/util/misc/uuid.h" | 19 #include "third_party/crashpad/crashpad/util/misc/uuid.h" |
| 20 | 20 |
| 21 namespace browser_watcher { | 21 namespace browser_watcher { |
| 22 | 22 |
| 23 using crashpad::UUID; | 23 using crashpad::UUID; |
| 24 | 24 |
| 25 const char kProductName[] = "some-product"; | 25 const char kProductName[] = "some-product"; |
| 26 const char kExpectedProductName[] = "some-product_Postmortem"; | 26 const char kExpectedProductName[] = "some-product_Postmortem"; |
| 27 const char kVersion[] = "51.0.2704.106"; | 27 const char kVersion[] = "51.0.2704.106"; |
| 28 const char kChannel[] = "some-channel"; |
| 29 const char kPlatform[] = "some-platform"; |
| 28 | 30 |
| 29 class WritePostmortemDumpTest : public testing::Test { | 31 class WritePostmortemDumpTest : public testing::Test { |
| 30 public: | 32 public: |
| 31 void SetUp() override { | 33 void SetUp() override { |
| 32 testing::Test::SetUp(); | 34 testing::Test::SetUp(); |
| 33 | 35 |
| 34 expected_client_id_ = UUID(UUID::InitializeWithNewTag{}); | 36 expected_client_id_ = UUID(UUID::InitializeWithNewTag{}); |
| 35 expected_report_id_ = UUID(UUID::InitializeWithNewTag{}); | 37 expected_report_id_ = UUID(UUID::InitializeWithNewTag{}); |
| 36 | 38 |
| 37 // Create a stability report. | 39 // Create a stability report. |
| 38 // TODO(manzagop): flesh out the report once proto is more detailed. | 40 // TODO(manzagop): flesh out the report once proto is more detailed. |
| 39 ProcessState* process_state = expected_report_.add_process_states(); | 41 ProcessState* process_state = expected_report_.add_process_states(); |
| 40 CodeModule* module = process_state->add_modules(); | 42 CodeModule* module = process_state->add_modules(); |
| 41 module->set_base_address(1024); | 43 module->set_base_address(1024); |
| 42 module->set_code_file("some_code_file.dll"); | 44 module->set_code_file("some_code_file.dll"); |
| 43 | 45 |
| 44 // Write the minidump. | 46 // Write the minidump. |
| 45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 47 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 46 minidump_path_ = temp_dir_.GetPath().AppendASCII("minidump.dmp"); | 48 minidump_path_ = temp_dir_.GetPath().AppendASCII("minidump.dmp"); |
| 47 } | 49 } |
| 48 | 50 |
| 49 bool WriteDump() { | 51 bool WriteDump() { |
| 50 base::win::ScopedHandle file_handle(::CreateFile( | 52 base::win::ScopedHandle file_handle(::CreateFile( |
| 51 minidump_path_.value().c_str(), GENERIC_READ | GENERIC_WRITE, | 53 minidump_path_.value().c_str(), GENERIC_READ | GENERIC_WRITE, |
| 52 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_NEW, | 54 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_NEW, |
| 53 FILE_ATTRIBUTE_NORMAL, nullptr)); | 55 FILE_ATTRIBUTE_NORMAL, nullptr)); |
| 54 if (!file_handle.IsValid()) | 56 if (!file_handle.IsValid()) |
| 55 return false; | 57 return false; |
| 56 | 58 |
| 57 MinidumpInfo mindump_info; | 59 MinidumpInfo minidump_info; |
| 58 mindump_info.client_id = expected_client_id_; | 60 minidump_info.client_id = expected_client_id_; |
| 59 mindump_info.report_id = expected_report_id_; | 61 minidump_info.report_id = expected_report_id_; |
| 60 mindump_info.product_name = kProductName; | 62 minidump_info.product_name = kProductName; |
| 61 mindump_info.version_number = kVersion; | 63 minidump_info.version_number = kVersion; |
| 64 minidump_info.channel_name = kChannel; |
| 65 minidump_info.platform = kPlatform; |
| 62 | 66 |
| 63 return WritePostmortemDump(file_handle.Get(), expected_report_, | 67 return WritePostmortemDump(file_handle.Get(), expected_report_, |
| 64 mindump_info); | 68 minidump_info); |
| 65 } | 69 } |
| 66 | 70 |
| 67 const base::FilePath& minidump_path() { return minidump_path_; } | 71 const base::FilePath& minidump_path() { return minidump_path_; } |
| 68 const UUID& expected_client_id() { return expected_client_id_; } | 72 const UUID& expected_client_id() { return expected_client_id_; } |
| 69 const UUID& expected_report_id() { return expected_report_id_; } | 73 const UUID& expected_report_id() { return expected_report_id_; } |
| 70 const StabilityReport& expected_report() { return expected_report_; } | 74 const StabilityReport& expected_report() { return expected_report_; } |
| 71 | 75 |
| 72 private: | 76 private: |
| 73 base::ScopedTempDir temp_dir_; | 77 base::ScopedTempDir temp_dir_; |
| 74 base::FilePath minidump_path_; | 78 base::FilePath minidump_path_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 UUID client_id; | 133 UUID client_id; |
| 130 minidump_process_snapshot.ClientID(&client_id); | 134 minidump_process_snapshot.ClientID(&client_id); |
| 131 ASSERT_EQ(expected_client_id(), client_id); | 135 ASSERT_EQ(expected_client_id(), client_id); |
| 132 | 136 |
| 133 UUID report_id; | 137 UUID report_id; |
| 134 minidump_process_snapshot.ReportID(&report_id); | 138 minidump_process_snapshot.ReportID(&report_id); |
| 135 ASSERT_EQ(expected_report_id(), report_id); | 139 ASSERT_EQ(expected_report_id(), report_id); |
| 136 | 140 |
| 137 std::map<std::string, std::string> parameters = | 141 std::map<std::string, std::string> parameters = |
| 138 minidump_process_snapshot.AnnotationsSimpleMap(); | 142 minidump_process_snapshot.AnnotationsSimpleMap(); |
| 139 auto it = parameters.find("product"); | 143 auto it = parameters.find("prod"); |
| 140 ASSERT_NE(parameters.end(), it); | 144 ASSERT_NE(parameters.end(), it); |
| 141 ASSERT_EQ(kExpectedProductName, it->second); | 145 ASSERT_EQ(kExpectedProductName, it->second); |
| 142 | 146 |
| 143 it = parameters.find("version"); | 147 it = parameters.find("ver"); |
| 144 ASSERT_NE(parameters.end(), it); | 148 ASSERT_NE(parameters.end(), it); |
| 145 ASSERT_EQ(kVersion, it->second); | 149 ASSERT_EQ(kVersion, it->second); |
| 150 |
| 151 it = parameters.find("channel"); |
| 152 ASSERT_NE(parameters.end(), it); |
| 153 ASSERT_EQ(kChannel, it->second); |
| 154 |
| 155 it = parameters.find("plat"); |
| 156 ASSERT_NE(parameters.end(), it); |
| 157 ASSERT_EQ(kPlatform, it->second); |
| 146 } | 158 } |
| 147 | 159 |
| 148 } // namespace browser_watcher | 160 } // namespace browser_watcher |
| OLD | NEW |