| 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_report_collector.h" | 5 #include "components/browser_watcher/postmortem_report_collector.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/debug/activity_analyzer.h" | 15 #include "base/debug/activity_analyzer.h" |
| 16 #include "base/debug/activity_tracker.h" | 16 #include "base/debug/activity_tracker.h" |
| 17 #include "base/files/file.h" | 17 #include "base/files/file.h" |
| 18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| 19 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
| 20 #include "base/files/memory_mapped_file.h" | 20 #include "base/files/memory_mapped_file.h" |
| 21 #include "base/files/scoped_file.h" | 21 #include "base/files/scoped_file.h" |
| 22 #include "base/files/scoped_temp_dir.h" | 22 #include "base/files/scoped_temp_dir.h" |
| 23 #include "base/memory/ptr_util.h" | 23 #include "base/memory/ptr_util.h" |
| 24 #include "base/metrics/persistent_memory_allocator.h" | 24 #include "base/metrics/persistent_memory_allocator.h" |
| 25 #include "base/process/process_handle.h" | 25 #include "base/process/process_handle.h" |
| 26 #include "base/stl_util.h" | 26 #include "base/stl_util.h" |
| 27 #include "base/threading/platform_thread.h" | 27 #include "base/threading/platform_thread.h" |
| 28 #include "components/browser_watcher/postmortem_report_extractor.h" |
| 28 #include "components/browser_watcher/stability_data_names.h" | 29 #include "components/browser_watcher/stability_data_names.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "third_party/crashpad/crashpad/client/crash_report_database.h" | 32 #include "third_party/crashpad/crashpad/client/crash_report_database.h" |
| 32 | 33 |
| 33 namespace browser_watcher { | 34 namespace browser_watcher { |
| 34 | 35 |
| 35 using base::debug::ActivityData; | 36 using base::debug::ActivityData; |
| 36 using base::debug::ActivityTrackerMemoryAllocator; | 37 using base::debug::ActivityTrackerMemoryAllocator; |
| 37 using base::debug::ActivityUserData; | 38 using base::debug::ActivityUserData; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 MOCK_METHOD1(RequestUpload, | 107 MOCK_METHOD1(RequestUpload, |
| 107 CrashReportDatabase::OperationStatus(const UUID& uuid)); | 108 CrashReportDatabase::OperationStatus(const UUID& uuid)); |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 // Used for testing CollectAndSubmitForUpload. | 111 // Used for testing CollectAndSubmitForUpload. |
| 111 class MockPostmortemReportCollector : public PostmortemReportCollector { | 112 class MockPostmortemReportCollector : public PostmortemReportCollector { |
| 112 public: | 113 public: |
| 113 MockPostmortemReportCollector() | 114 MockPostmortemReportCollector() |
| 114 : PostmortemReportCollector(kProductName, kVersionNumber, kChannelName) {} | 115 : PostmortemReportCollector(kProductName, kVersionNumber, kChannelName) {} |
| 115 | 116 |
| 116 // A function that returns a unique_ptr cannot be mocked, so mock a function | |
| 117 // that returns a raw pointer instead. | |
| 118 CollectionStatus Collect(const base::FilePath& debug_state_file, | |
| 119 std::unique_ptr<StabilityReport>* report) override { | |
| 120 DCHECK_NE(nullptr, report); | |
| 121 report->reset(CollectRaw(debug_state_file)); | |
| 122 return SUCCESS; | |
| 123 } | |
| 124 | |
| 125 MOCK_METHOD3(GetDebugStateFilePaths, | 117 MOCK_METHOD3(GetDebugStateFilePaths, |
| 126 std::vector<base::FilePath>( | 118 std::vector<base::FilePath>( |
| 127 const base::FilePath& debug_info_dir, | 119 const base::FilePath& debug_info_dir, |
| 128 const base::FilePath::StringType& debug_file_pattern, | 120 const base::FilePath::StringType& debug_file_pattern, |
| 129 const std::set<base::FilePath>&)); | 121 const std::set<base::FilePath>&)); |
| 130 MOCK_METHOD1(CollectRaw, StabilityReport*(const base::FilePath&)); | 122 MOCK_METHOD2(Collect, |
| 123 CollectionStatus(const base::FilePath&, |
| 124 StabilityReport* report)); |
| 131 MOCK_METHOD4(WriteReportToMinidump, | 125 MOCK_METHOD4(WriteReportToMinidump, |
| 132 bool(StabilityReport* report, | 126 bool(StabilityReport* report, |
| 133 const crashpad::UUID& client_id, | 127 const crashpad::UUID& client_id, |
| 134 const crashpad::UUID& report_id, | 128 const crashpad::UUID& report_id, |
| 135 base::PlatformFile minidump_file)); | 129 base::PlatformFile minidump_file)); |
| 136 }; | 130 }; |
| 137 | 131 |
| 138 // Checks if two proto messages are the same based on their serializations. Note | 132 // Checks if two proto messages are the same based on their serializations. Note |
| 139 // this only works if serialization is deterministic, which is not guaranteed. | 133 // this only works if serialization is deterministic, which is not guaranteed. |
| 140 // In practice, serialization is deterministic (even for protocol buffers with | 134 // In practice, serialization is deterministic (even for protocol buffers with |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 debug_file_pattern_ = FILE_PATH_LITERAL("foo-*.pma"); | 167 debug_file_pattern_ = FILE_PATH_LITERAL("foo-*.pma"); |
| 174 std::vector<base::FilePath> debug_files{debug_file_}; | 168 std::vector<base::FilePath> debug_files{debug_file_}; |
| 175 EXPECT_CALL(collector_, | 169 EXPECT_CALL(collector_, |
| 176 GetDebugStateFilePaths(debug_file_.DirName(), | 170 GetDebugStateFilePaths(debug_file_.DirName(), |
| 177 debug_file_pattern_, no_excluded_files_)) | 171 debug_file_pattern_, no_excluded_files_)) |
| 178 .Times(1) | 172 .Times(1) |
| 179 .WillOnce(Return(debug_files)); | 173 .WillOnce(Return(debug_files)); |
| 180 | 174 |
| 181 EXPECT_CALL(database_, GetSettings()).Times(1).WillOnce(Return(nullptr)); | 175 EXPECT_CALL(database_, GetSettings()).Times(1).WillOnce(Return(nullptr)); |
| 182 | 176 |
| 183 // Expect collection to a proto of a single debug file. | 177 // Expect a single collection call. |
| 184 // Note: caller takes ownership. | 178 EXPECT_CALL(collector_, Collect(debug_file_, _)) |
| 185 StabilityReport* stability_report = new StabilityReport(); | |
| 186 EXPECT_CALL(collector_, CollectRaw(debug_file_)) | |
| 187 .Times(1) | 179 .Times(1) |
| 188 .WillOnce(Return(stability_report)); | 180 .WillOnce(Return(SUCCESS)); |
| 189 | 181 |
| 190 // Expect the call to write the proto to a minidump. This involves | 182 // Expect the call to write the proto to a minidump. This involves |
| 191 // requesting a report from the crashpad database, writing the report, then | 183 // requesting a report from the crashpad database, writing the report, then |
| 192 // finalizing it with the database. | 184 // finalizing it with the database. |
| 193 base::FilePath minidump_path = temp_dir_.GetPath().AppendASCII("foo-1.dmp"); | 185 base::FilePath minidump_path = temp_dir_.GetPath().AppendASCII("foo-1.dmp"); |
| 194 base::File minidump_file( | 186 base::File minidump_file( |
| 195 minidump_path, base::File::FLAG_CREATE | base::File::File::FLAG_WRITE); | 187 minidump_path, base::File::FLAG_CREATE | base::File::File::FLAG_WRITE); |
| 196 crashpad::UUID new_report_uuid; | 188 crashpad::UUID new_report_uuid; |
| 197 new_report_uuid.InitializeWithNew(); | 189 new_report_uuid.InitializeWithNew(); |
| 198 crashpad_report_ = {minidump_file.GetPlatformFile(), new_report_uuid, | 190 crashpad_report_ = {minidump_file.GetPlatformFile(), new_report_uuid, |
| 199 minidump_path}; | 191 minidump_path}; |
| 200 EXPECT_CALL(database_, PrepareNewCrashReport(_)) | 192 EXPECT_CALL(database_, PrepareNewCrashReport(_)) |
| 201 .Times(1) | 193 .Times(1) |
| 202 .WillOnce(DoAll(SetArgPointee<0>(&crashpad_report_), | 194 .WillOnce(DoAll(SetArgPointee<0>(&crashpad_report_), |
| 203 Return(CrashReportDatabase::kNoError))); | 195 Return(CrashReportDatabase::kNoError))); |
| 204 | 196 |
| 205 EXPECT_CALL(collector_, | 197 EXPECT_CALL(collector_, |
| 206 WriteReportToMinidump(stability_report, _, _, | 198 WriteReportToMinidump(_, _, _, minidump_file.GetPlatformFile())) |
| 207 minidump_file.GetPlatformFile())) | |
| 208 .Times(1) | 199 .Times(1) |
| 209 .WillOnce(Return(true)); | 200 .WillOnce(Return(true)); |
| 210 } | 201 } |
| 211 | 202 |
| 212 protected: | 203 protected: |
| 213 base::ScopedTempDir temp_dir_; | 204 base::ScopedTempDir temp_dir_; |
| 214 base::FilePath debug_file_; | 205 base::FilePath debug_file_; |
| 215 MockCrashReportDatabase database_; | 206 MockCrashReportDatabase database_; |
| 216 MockPostmortemReportCollector collector_; | 207 MockPostmortemReportCollector collector_; |
| 217 base::FilePath::StringType debug_file_pattern_; | 208 base::FilePath::StringType debug_file_pattern_; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 base::FilePath file_path = temp_dir.GetPath().AppendASCII("empty.pma"); | 290 base::FilePath file_path = temp_dir.GetPath().AppendASCII("empty.pma"); |
| 300 { | 291 { |
| 301 base::ScopedFILE file(base::OpenFile(file_path, "w")); | 292 base::ScopedFILE file(base::OpenFile(file_path, "w")); |
| 302 ASSERT_NE(file.get(), nullptr); | 293 ASSERT_NE(file.get(), nullptr); |
| 303 } | 294 } |
| 304 ASSERT_TRUE(PathExists(file_path)); | 295 ASSERT_TRUE(PathExists(file_path)); |
| 305 | 296 |
| 306 // Validate collection: an empty file cannot suppport an analyzer. | 297 // Validate collection: an empty file cannot suppport an analyzer. |
| 307 PostmortemReportCollector collector(kProductName, kVersionNumber, | 298 PostmortemReportCollector collector(kProductName, kVersionNumber, |
| 308 kChannelName); | 299 kChannelName); |
| 309 std::unique_ptr<StabilityReport> report; | 300 StabilityReport report; |
| 310 ASSERT_EQ(PostmortemReportCollector::ANALYZER_CREATION_FAILED, | 301 ASSERT_EQ(ANALYZER_CREATION_FAILED, collector.Collect(file_path, &report)); |
| 311 collector.Collect(file_path, &report)); | |
| 312 } | 302 } |
| 313 | 303 |
| 314 TEST(PostmortemReportCollectorTest, CollectRandomFile) { | 304 TEST(PostmortemReportCollectorTest, CollectRandomFile) { |
| 315 // Create a file with content we don't expect to be valid for a debug file. | 305 // Create a file with content we don't expect to be valid for a debug file. |
| 316 base::ScopedTempDir temp_dir; | 306 base::ScopedTempDir temp_dir; |
| 317 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 307 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 318 base::FilePath file_path = | 308 base::FilePath file_path = |
| 319 temp_dir.GetPath().AppendASCII("invalid_content.pma"); | 309 temp_dir.GetPath().AppendASCII("invalid_content.pma"); |
| 320 { | 310 { |
| 321 base::ScopedFILE file(base::OpenFile(file_path, "w")); | 311 base::ScopedFILE file(base::OpenFile(file_path, "w")); |
| 322 ASSERT_NE(file.get(), nullptr); | 312 ASSERT_NE(file.get(), nullptr); |
| 323 // Assuming this size is greater than the minimum size of a debug file. | 313 // Assuming this size is greater than the minimum size of a debug file. |
| 324 std::vector<uint8_t> data(1024); | 314 std::vector<uint8_t> data(1024); |
| 325 for (size_t i = 0; i < data.size(); ++i) | 315 for (size_t i = 0; i < data.size(); ++i) |
| 326 data[i] = i % UINT8_MAX; | 316 data[i] = i % UINT8_MAX; |
| 327 ASSERT_EQ(data.size(), | 317 ASSERT_EQ(data.size(), |
| 328 fwrite(&data.at(0), sizeof(uint8_t), data.size(), file.get())); | 318 fwrite(&data.at(0), sizeof(uint8_t), data.size(), file.get())); |
| 329 } | 319 } |
| 330 ASSERT_TRUE(PathExists(file_path)); | 320 ASSERT_TRUE(PathExists(file_path)); |
| 331 | 321 |
| 332 // Validate collection: random content appears as though there is not | 322 // Validate collection: random content appears as though there is not |
| 333 // stability data. | 323 // stability data. |
| 334 PostmortemReportCollector collector(kProductName, kVersionNumber, | 324 PostmortemReportCollector collector(kProductName, kVersionNumber, |
| 335 kChannelName); | 325 kChannelName); |
| 336 std::unique_ptr<StabilityReport> report; | 326 StabilityReport report; |
| 337 ASSERT_EQ(PostmortemReportCollector::DEBUG_FILE_NO_DATA, | 327 ASSERT_EQ(DEBUG_FILE_NO_DATA, collector.Collect(file_path, &report)); |
| 338 collector.Collect(file_path, &report)); | |
| 339 } | 328 } |
| 340 | 329 |
| 341 namespace { | 330 namespace { |
| 342 | 331 |
| 343 // Parameters for the activity tracking. | 332 // Parameters for the activity tracking. |
| 344 const size_t kFileSize = 2 * 1024; | 333 const size_t kFileSize = 2 * 1024; |
| 345 const int kStackDepth = 5; | 334 const int kStackDepth = 5; |
| 346 const uint64_t kAllocatorId = 0; | 335 const uint64_t kAllocatorId = 0; |
| 347 const char kAllocatorName[] = "PostmortemReportCollectorCollectionTest"; | 336 const char kAllocatorName[] = "PostmortemReportCollectorCollectionTest"; |
| 348 const uint64_t kTaskSequenceNum = 42; | 337 const uint64_t kTaskSequenceNum = 42; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 ActivityTrackerMemoryAllocator user_data_allocator( | 442 ActivityTrackerMemoryAllocator user_data_allocator( |
| 454 allocator_.get(), GlobalActivityTracker::kTypeIdUserDataRecord, | 443 allocator_.get(), GlobalActivityTracker::kTypeIdUserDataRecord, |
| 455 GlobalActivityTracker::kTypeIdUserDataRecordFree, 1024U, 10U, false); | 444 GlobalActivityTracker::kTypeIdUserDataRecordFree, 1024U, 10U, false); |
| 456 std::unique_ptr<ActivityUserData> user_data = | 445 std::unique_ptr<ActivityUserData> user_data = |
| 457 tracker_->GetUserData(activity_id, &user_data_allocator); | 446 tracker_->GetUserData(activity_id, &user_data_allocator); |
| 458 user_data->SetInt("some_int", 42); | 447 user_data->SetInt("some_int", 42); |
| 459 | 448 |
| 460 // Validate collection returns the expected report. | 449 // Validate collection returns the expected report. |
| 461 PostmortemReportCollector collector(kProductName, kVersionNumber, | 450 PostmortemReportCollector collector(kProductName, kVersionNumber, |
| 462 kChannelName); | 451 kChannelName); |
| 463 std::unique_ptr<StabilityReport> report; | 452 StabilityReport report; |
| 464 ASSERT_EQ(PostmortemReportCollector::SUCCESS, | 453 ASSERT_EQ(SUCCESS, collector.Collect(debug_file_path(), &report)); |
| 465 collector.Collect(debug_file_path(), &report)); | |
| 466 ASSERT_NE(nullptr, report); | |
| 467 | 454 |
| 468 // Validate the report. | 455 // Validate the report. |
| 469 ASSERT_EQ(1, report->process_states_size()); | 456 ASSERT_EQ(1, report.process_states_size()); |
| 470 const ProcessState& process_state = report->process_states(0); | 457 const ProcessState& process_state = report.process_states(0); |
| 471 EXPECT_EQ(base::GetCurrentProcId(), process_state.process_id()); | 458 EXPECT_EQ(base::GetCurrentProcId(), process_state.process_id()); |
| 472 ASSERT_EQ(1, process_state.threads_size()); | 459 ASSERT_EQ(1, process_state.threads_size()); |
| 473 | 460 |
| 474 const ThreadState& thread_state = process_state.threads(0); | 461 const ThreadState& thread_state = process_state.threads(0); |
| 475 EXPECT_EQ(base::PlatformThread::GetName(), thread_state.thread_name()); | 462 EXPECT_EQ(base::PlatformThread::GetName(), thread_state.thread_name()); |
| 476 #if defined(OS_WIN) | 463 #if defined(OS_WIN) |
| 477 EXPECT_EQ(base::PlatformThread::CurrentId(), thread_state.thread_id()); | 464 EXPECT_EQ(base::PlatformThread::CurrentId(), thread_state.thread_id()); |
| 478 #elif defined(OS_POSIX) | 465 #elif defined(OS_POSIX) |
| 479 EXPECT_EQ(base::PlatformThread::CurrentHandle().platform_handle(), | 466 EXPECT_EQ(base::PlatformThread::CurrentHandle().platform_handle(), |
| 480 thread_state.thread_id()); | 467 thread_state.thread_id()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 LogCollection) { | 539 LogCollection) { |
| 553 // Record some log messages. | 540 // Record some log messages. |
| 554 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, | 541 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, |
| 555 "", 3); | 542 "", 3); |
| 556 GlobalActivityTracker::Get()->RecordLogMessage("hello world"); | 543 GlobalActivityTracker::Get()->RecordLogMessage("hello world"); |
| 557 GlobalActivityTracker::Get()->RecordLogMessage("foo bar"); | 544 GlobalActivityTracker::Get()->RecordLogMessage("foo bar"); |
| 558 | 545 |
| 559 // Collect the stability report. | 546 // Collect the stability report. |
| 560 PostmortemReportCollector collector(kProductName, kVersionNumber, | 547 PostmortemReportCollector collector(kProductName, kVersionNumber, |
| 561 kChannelName); | 548 kChannelName); |
| 562 std::unique_ptr<StabilityReport> report; | 549 StabilityReport report; |
| 563 ASSERT_EQ(PostmortemReportCollector::SUCCESS, | 550 ASSERT_EQ(SUCCESS, collector.Collect(debug_file_path(), &report)); |
| 564 collector.Collect(debug_file_path(), &report)); | |
| 565 ASSERT_NE(nullptr, report); | |
| 566 | 551 |
| 567 // Validate the report's log content. | 552 // Validate the report's log content. |
| 568 ASSERT_EQ(2, report->log_messages_size()); | 553 ASSERT_EQ(2, report.log_messages_size()); |
| 569 ASSERT_EQ("hello world", report->log_messages(0)); | 554 ASSERT_EQ("hello world", report.log_messages(0)); |
| 570 ASSERT_EQ("foo bar", report->log_messages(1)); | 555 ASSERT_EQ("foo bar", report.log_messages(1)); |
| 571 } | 556 } |
| 572 | 557 |
| 573 TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 558 TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 574 GlobalUserDataCollection) { | 559 GlobalUserDataCollection) { |
| 575 const char string1[] = "foo"; | 560 const char string1[] = "foo"; |
| 576 const char string2[] = "bar"; | 561 const char string2[] = "bar"; |
| 577 | 562 |
| 578 // Record some global user data. | 563 // Record some global user data. |
| 579 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, | 564 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, |
| 580 "", 3); | 565 "", 3); |
| 581 ActivityUserData& global_data = GlobalActivityTracker::Get()->global_data(); | 566 ActivityUserData& global_data = GlobalActivityTracker::Get()->global_data(); |
| 582 global_data.Set("raw", "foo", 3); | 567 global_data.Set("raw", "foo", 3); |
| 583 global_data.SetString("string", "bar"); | 568 global_data.SetString("string", "bar"); |
| 584 global_data.SetChar("char", '9'); | 569 global_data.SetChar("char", '9'); |
| 585 global_data.SetInt("int", -9999); | 570 global_data.SetInt("int", -9999); |
| 586 global_data.SetUint("uint", 9999); | 571 global_data.SetUint("uint", 9999); |
| 587 global_data.SetBool("bool", true); | 572 global_data.SetBool("bool", true); |
| 588 global_data.SetReference("ref", string1, strlen(string1)); | 573 global_data.SetReference("ref", string1, strlen(string1)); |
| 589 global_data.SetStringReference("sref", string2); | 574 global_data.SetStringReference("sref", string2); |
| 590 | 575 |
| 591 // Collect the stability report. | 576 // Collect the stability report. |
| 592 PostmortemReportCollector collector(kProductName, kVersionNumber, | 577 PostmortemReportCollector collector(kProductName, kVersionNumber, |
| 593 kChannelName); | 578 kChannelName); |
| 594 std::unique_ptr<StabilityReport> report; | 579 StabilityReport report; |
| 595 ASSERT_EQ(PostmortemReportCollector::SUCCESS, | 580 ASSERT_EQ(SUCCESS, collector.Collect(debug_file_path(), &report)); |
| 596 collector.Collect(debug_file_path(), &report)); | |
| 597 ASSERT_NE(nullptr, report); | |
| 598 | 581 |
| 599 // Validate the report's user data. | 582 // Validate the report's user data. |
| 600 const auto& collected_data = report->global_data(); | 583 const auto& collected_data = report.global_data(); |
| 601 ASSERT_EQ(12U, collected_data.size()); | 584 ASSERT_EQ(12U, collected_data.size()); |
| 602 | 585 |
| 603 ASSERT_TRUE(base::ContainsKey(collected_data, "raw")); | 586 ASSERT_TRUE(base::ContainsKey(collected_data, "raw")); |
| 604 EXPECT_EQ(TypedValue::kBytesValue, collected_data.at("raw").value_case()); | 587 EXPECT_EQ(TypedValue::kBytesValue, collected_data.at("raw").value_case()); |
| 605 EXPECT_EQ("foo", collected_data.at("raw").bytes_value()); | 588 EXPECT_EQ("foo", collected_data.at("raw").bytes_value()); |
| 606 | 589 |
| 607 ASSERT_TRUE(base::ContainsKey(collected_data, "string")); | 590 ASSERT_TRUE(base::ContainsKey(collected_data, "string")); |
| 608 EXPECT_EQ(TypedValue::kStringValue, collected_data.at("string").value_case()); | 591 EXPECT_EQ(TypedValue::kStringValue, collected_data.at("string").value_case()); |
| 609 EXPECT_EQ("bar", collected_data.at("string").string_value()); | 592 EXPECT_EQ("bar", collected_data.at("string").string_value()); |
| 610 | 593 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, | 638 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, |
| 656 "", 3); | 639 "", 3); |
| 657 ActivityUserData& global_data = GlobalActivityTracker::Get()->global_data(); | 640 ActivityUserData& global_data = GlobalActivityTracker::Get()->global_data(); |
| 658 global_data.SetString("string", "bar"); | 641 global_data.SetString("string", "bar"); |
| 659 global_data.SetString("FieldTrial.string", "bar"); | 642 global_data.SetString("FieldTrial.string", "bar"); |
| 660 global_data.SetString("FieldTrial.foo", "bar"); | 643 global_data.SetString("FieldTrial.foo", "bar"); |
| 661 | 644 |
| 662 // Collect the stability report. | 645 // Collect the stability report. |
| 663 PostmortemReportCollector collector(kProductName, kVersionNumber, | 646 PostmortemReportCollector collector(kProductName, kVersionNumber, |
| 664 kChannelName); | 647 kChannelName); |
| 665 std::unique_ptr<StabilityReport> report; | 648 StabilityReport report; |
| 666 ASSERT_EQ(PostmortemReportCollector::SUCCESS, | 649 ASSERT_EQ(SUCCESS, collector.Collect(debug_file_path(), &report)); |
| 667 collector.Collect(debug_file_path(), &report)); | |
| 668 ASSERT_NE(nullptr, report); | |
| 669 | 650 |
| 670 // Validate the report's experiment and global data. | 651 // Validate the report's experiment and global data. |
| 671 ASSERT_EQ(2, report->field_trials_size()); | 652 ASSERT_EQ(2, report.field_trials_size()); |
| 672 EXPECT_NE(0U, report->field_trials(0).name_id()); | 653 EXPECT_NE(0U, report.field_trials(0).name_id()); |
| 673 EXPECT_NE(0U, report->field_trials(0).group_id()); | 654 EXPECT_NE(0U, report.field_trials(0).group_id()); |
| 674 EXPECT_NE(0U, report->field_trials(1).name_id()); | 655 EXPECT_NE(0U, report.field_trials(1).name_id()); |
| 675 EXPECT_EQ(report->field_trials(0).group_id(), | 656 EXPECT_EQ(report.field_trials(0).group_id(), |
| 676 report->field_trials(1).group_id()); | 657 report.field_trials(1).group_id()); |
| 677 | 658 |
| 678 // Expect 5 key/value pairs (including product details). | 659 // Expect 5 key/value pairs (including product details). |
| 679 const auto& collected_data = report->global_data(); | 660 const auto& collected_data = report.global_data(); |
| 680 EXPECT_EQ(5U, collected_data.size()); | 661 EXPECT_EQ(5U, collected_data.size()); |
| 681 EXPECT_TRUE(base::ContainsKey(collected_data, "string")); | 662 EXPECT_TRUE(base::ContainsKey(collected_data, "string")); |
| 682 } | 663 } |
| 683 | 664 |
| 684 TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 665 TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 685 ModuleCollection) { | 666 ModuleCollection) { |
| 686 // Record some module information. | 667 // Record some module information. |
| 687 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, | 668 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, |
| 688 "", 3); | 669 "", 3); |
| 689 | 670 |
| 690 base::debug::GlobalActivityTracker::ModuleInfo module_info = {}; | 671 base::debug::GlobalActivityTracker::ModuleInfo module_info = {}; |
| 691 module_info.is_loaded = true; | 672 module_info.is_loaded = true; |
| 692 module_info.address = 0x123456; | 673 module_info.address = 0x123456; |
| 693 module_info.load_time = 1111LL; | 674 module_info.load_time = 1111LL; |
| 694 module_info.size = 0x2d000; | 675 module_info.size = 0x2d000; |
| 695 module_info.timestamp = 0xCAFECAFE; | 676 module_info.timestamp = 0xCAFECAFE; |
| 696 module_info.age = 1; | 677 module_info.age = 1; |
| 697 crashpad::UUID debug_uuid; | 678 crashpad::UUID debug_uuid; |
| 698 debug_uuid.InitializeFromString("11223344-5566-7788-abcd-0123456789ab"); | 679 debug_uuid.InitializeFromString("11223344-5566-7788-abcd-0123456789ab"); |
| 699 memcpy(module_info.identifier, &debug_uuid, sizeof(module_info.identifier)); | 680 memcpy(module_info.identifier, &debug_uuid, sizeof(module_info.identifier)); |
| 700 module_info.file = "foo"; | 681 module_info.file = "foo"; |
| 701 module_info.debug_file = "bar"; | 682 module_info.debug_file = "bar"; |
| 702 | 683 |
| 703 GlobalActivityTracker::Get()->RecordModuleInfo(module_info); | 684 GlobalActivityTracker::Get()->RecordModuleInfo(module_info); |
| 704 | 685 |
| 705 // Collect the stability report. | 686 // Collect the stability report. |
| 706 PostmortemReportCollector collector(kProductName, kVersionNumber, | 687 PostmortemReportCollector collector(kProductName, kVersionNumber, |
| 707 kChannelName); | 688 kChannelName); |
| 708 std::unique_ptr<StabilityReport> report; | 689 StabilityReport report; |
| 709 ASSERT_EQ(PostmortemReportCollector::SUCCESS, | 690 ASSERT_EQ(SUCCESS, collector.Collect(debug_file_path(), &report)); |
| 710 collector.Collect(debug_file_path(), &report)); | |
| 711 ASSERT_NE(nullptr, report); | |
| 712 | 691 |
| 713 // Validate the report's modules content. | 692 // Validate the report's modules content. |
| 714 ASSERT_EQ(1, report->process_states_size()); | 693 ASSERT_EQ(1, report.process_states_size()); |
| 715 const ProcessState& process_state = report->process_states(0); | 694 const ProcessState& process_state = report.process_states(0); |
| 716 ASSERT_EQ(1, process_state.modules_size()); | 695 ASSERT_EQ(1, process_state.modules_size()); |
| 717 | 696 |
| 718 const CodeModule collected_module = process_state.modules(0); | 697 const CodeModule collected_module = process_state.modules(0); |
| 719 EXPECT_EQ(module_info.address, | 698 EXPECT_EQ(module_info.address, |
| 720 static_cast<uintptr_t>(collected_module.base_address())); | 699 static_cast<uintptr_t>(collected_module.base_address())); |
| 721 EXPECT_EQ(module_info.size, static_cast<size_t>(collected_module.size())); | 700 EXPECT_EQ(module_info.size, static_cast<size_t>(collected_module.size())); |
| 722 EXPECT_EQ(module_info.file, collected_module.code_file()); | 701 EXPECT_EQ(module_info.file, collected_module.code_file()); |
| 723 EXPECT_EQ("CAFECAFE2d000", collected_module.code_identifier()); | 702 EXPECT_EQ("CAFECAFE2d000", collected_module.code_identifier()); |
| 724 EXPECT_EQ(module_info.debug_file, collected_module.debug_file()); | 703 EXPECT_EQ(module_info.debug_file, collected_module.debug_file()); |
| 725 EXPECT_EQ("1122334455667788ABCD0123456789AB1", | 704 EXPECT_EQ("1122334455667788ABCD0123456789AB1", |
| 726 collected_module.debug_identifier()); | 705 collected_module.debug_identifier()); |
| 727 EXPECT_EQ("", collected_module.version()); | 706 EXPECT_EQ("", collected_module.version()); |
| 728 EXPECT_EQ(0LL, collected_module.shrink_down_delta()); | 707 EXPECT_EQ(0LL, collected_module.shrink_down_delta()); |
| 729 EXPECT_EQ(!module_info.is_loaded, collected_module.is_unloaded()); | 708 EXPECT_EQ(!module_info.is_loaded, collected_module.is_unloaded()); |
| 730 } | 709 } |
| 731 | 710 |
| 732 } // namespace browser_watcher | 711 } // namespace browser_watcher |
| OLD | NEW |