Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: components/browser_watcher/postmortem_report_collector_unittest.cc

Issue 2722223002: Separate collection logic from the extraction of the report (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_collector_impl.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
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 impl::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
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(impl::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
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(impl::ANALYZER_CREATION_FAILED,
311 collector.Collect(file_path, &report)); 302 collector.Collect(file_path, &report));
312 } 303 }
313 304
314 TEST(PostmortemReportCollectorTest, CollectRandomFile) { 305 TEST(PostmortemReportCollectorTest, CollectRandomFile) {
315 // Create a file with content we don't expect to be valid for a debug file. 306 // Create a file with content we don't expect to be valid for a debug file.
316 base::ScopedTempDir temp_dir; 307 base::ScopedTempDir temp_dir;
317 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 308 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
318 base::FilePath file_path = 309 base::FilePath file_path =
319 temp_dir.GetPath().AppendASCII("invalid_content.pma"); 310 temp_dir.GetPath().AppendASCII("invalid_content.pma");
320 { 311 {
321 base::ScopedFILE file(base::OpenFile(file_path, "w")); 312 base::ScopedFILE file(base::OpenFile(file_path, "w"));
322 ASSERT_NE(file.get(), nullptr); 313 ASSERT_NE(file.get(), nullptr);
323 // Assuming this size is greater than the minimum size of a debug file. 314 // Assuming this size is greater than the minimum size of a debug file.
324 std::vector<uint8_t> data(1024); 315 std::vector<uint8_t> data(1024);
325 for (size_t i = 0; i < data.size(); ++i) 316 for (size_t i = 0; i < data.size(); ++i)
326 data[i] = i % UINT8_MAX; 317 data[i] = i % UINT8_MAX;
327 ASSERT_EQ(data.size(), 318 ASSERT_EQ(data.size(),
328 fwrite(&data.at(0), sizeof(uint8_t), data.size(), file.get())); 319 fwrite(&data.at(0), sizeof(uint8_t), data.size(), file.get()));
329 } 320 }
330 ASSERT_TRUE(PathExists(file_path)); 321 ASSERT_TRUE(PathExists(file_path));
331 322
332 // Validate collection: random content appears as though there is not 323 // Validate collection: random content appears as though there is not
333 // stability data. 324 // stability data.
334 PostmortemReportCollector collector(kProductName, kVersionNumber, 325 PostmortemReportCollector collector(kProductName, kVersionNumber,
335 kChannelName); 326 kChannelName);
336 std::unique_ptr<StabilityReport> report; 327 StabilityReport report;
337 ASSERT_EQ(PostmortemReportCollector::DEBUG_FILE_NO_DATA, 328 ASSERT_EQ(impl::DEBUG_FILE_NO_DATA, collector.Collect(file_path, &report));
338 collector.Collect(file_path, &report));
339 } 329 }
340 330
341 namespace { 331 namespace {
342 332
343 // Parameters for the activity tracking. 333 // Parameters for the activity tracking.
344 const size_t kFileSize = 2 * 1024; 334 const size_t kFileSize = 2 * 1024;
345 const int kStackDepth = 5; 335 const int kStackDepth = 5;
346 const uint64_t kAllocatorId = 0; 336 const uint64_t kAllocatorId = 0;
347 const char kAllocatorName[] = "PostmortemReportCollectorCollectionTest"; 337 const char kAllocatorName[] = "PostmortemReportCollectorCollectionTest";
348 const uint64_t kTaskSequenceNum = 42; 338 const uint64_t kTaskSequenceNum = 42;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 ActivityTrackerMemoryAllocator user_data_allocator( 443 ActivityTrackerMemoryAllocator user_data_allocator(
454 allocator_.get(), GlobalActivityTracker::kTypeIdUserDataRecord, 444 allocator_.get(), GlobalActivityTracker::kTypeIdUserDataRecord,
455 GlobalActivityTracker::kTypeIdUserDataRecordFree, 1024U, 10U, false); 445 GlobalActivityTracker::kTypeIdUserDataRecordFree, 1024U, 10U, false);
456 std::unique_ptr<ActivityUserData> user_data = 446 std::unique_ptr<ActivityUserData> user_data =
457 tracker_->GetUserData(activity_id, &user_data_allocator); 447 tracker_->GetUserData(activity_id, &user_data_allocator);
458 user_data->SetInt("some_int", 42); 448 user_data->SetInt("some_int", 42);
459 449
460 // Validate collection returns the expected report. 450 // Validate collection returns the expected report.
461 PostmortemReportCollector collector(kProductName, kVersionNumber, 451 PostmortemReportCollector collector(kProductName, kVersionNumber,
462 kChannelName); 452 kChannelName);
463 std::unique_ptr<StabilityReport> report; 453 StabilityReport report;
464 ASSERT_EQ(PostmortemReportCollector::SUCCESS, 454 ASSERT_EQ(impl::SUCCESS, collector.Collect(debug_file_path(), &report));
465 collector.Collect(debug_file_path(), &report));
466 ASSERT_NE(nullptr, report);
467 455
468 // Validate the report. 456 // Validate the report.
469 ASSERT_EQ(1, report->process_states_size()); 457 ASSERT_EQ(1, report.process_states_size());
470 const ProcessState& process_state = report->process_states(0); 458 const ProcessState& process_state = report.process_states(0);
471 EXPECT_EQ(base::GetCurrentProcId(), process_state.process_id()); 459 EXPECT_EQ(base::GetCurrentProcId(), process_state.process_id());
472 ASSERT_EQ(1, process_state.threads_size()); 460 ASSERT_EQ(1, process_state.threads_size());
473 461
474 const ThreadState& thread_state = process_state.threads(0); 462 const ThreadState& thread_state = process_state.threads(0);
475 EXPECT_EQ(base::PlatformThread::GetName(), thread_state.thread_name()); 463 EXPECT_EQ(base::PlatformThread::GetName(), thread_state.thread_name());
476 #if defined(OS_WIN) 464 #if defined(OS_WIN)
477 EXPECT_EQ(base::PlatformThread::CurrentId(), thread_state.thread_id()); 465 EXPECT_EQ(base::PlatformThread::CurrentId(), thread_state.thread_id());
478 #elif defined(OS_POSIX) 466 #elif defined(OS_POSIX)
479 EXPECT_EQ(base::PlatformThread::CurrentHandle().platform_handle(), 467 EXPECT_EQ(base::PlatformThread::CurrentHandle().platform_handle(),
480 thread_state.thread_id()); 468 thread_state.thread_id());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 LogCollection) { 540 LogCollection) {
553 // Record some log messages. 541 // Record some log messages.
554 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, 542 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL,
555 "", 3); 543 "", 3);
556 GlobalActivityTracker::Get()->RecordLogMessage("hello world"); 544 GlobalActivityTracker::Get()->RecordLogMessage("hello world");
557 GlobalActivityTracker::Get()->RecordLogMessage("foo bar"); 545 GlobalActivityTracker::Get()->RecordLogMessage("foo bar");
558 546
559 // Collect the stability report. 547 // Collect the stability report.
560 PostmortemReportCollector collector(kProductName, kVersionNumber, 548 PostmortemReportCollector collector(kProductName, kVersionNumber,
561 kChannelName); 549 kChannelName);
562 std::unique_ptr<StabilityReport> report; 550 StabilityReport report;
563 ASSERT_EQ(PostmortemReportCollector::SUCCESS, 551 ASSERT_EQ(impl::SUCCESS, collector.Collect(debug_file_path(), &report));
564 collector.Collect(debug_file_path(), &report));
565 ASSERT_NE(nullptr, report);
566 552
567 // Validate the report's log content. 553 // Validate the report's log content.
568 ASSERT_EQ(2, report->log_messages_size()); 554 ASSERT_EQ(2, report.log_messages_size());
569 ASSERT_EQ("hello world", report->log_messages(0)); 555 ASSERT_EQ("hello world", report.log_messages(0));
570 ASSERT_EQ("foo bar", report->log_messages(1)); 556 ASSERT_EQ("foo bar", report.log_messages(1));
571 } 557 }
572 558
573 TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest, 559 TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
574 GlobalUserDataCollection) { 560 GlobalUserDataCollection) {
575 const char string1[] = "foo"; 561 const char string1[] = "foo";
576 const char string2[] = "bar"; 562 const char string2[] = "bar";
577 563
578 // Record some global user data. 564 // Record some global user data.
579 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, 565 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL,
580 "", 3); 566 "", 3);
581 ActivityUserData& global_data = GlobalActivityTracker::Get()->global_data(); 567 ActivityUserData& global_data = GlobalActivityTracker::Get()->global_data();
582 global_data.Set("raw", "foo", 3); 568 global_data.Set("raw", "foo", 3);
583 global_data.SetString("string", "bar"); 569 global_data.SetString("string", "bar");
584 global_data.SetChar("char", '9'); 570 global_data.SetChar("char", '9');
585 global_data.SetInt("int", -9999); 571 global_data.SetInt("int", -9999);
586 global_data.SetUint("uint", 9999); 572 global_data.SetUint("uint", 9999);
587 global_data.SetBool("bool", true); 573 global_data.SetBool("bool", true);
588 global_data.SetReference("ref", string1, strlen(string1)); 574 global_data.SetReference("ref", string1, strlen(string1));
589 global_data.SetStringReference("sref", string2); 575 global_data.SetStringReference("sref", string2);
590 576
591 // Collect the stability report. 577 // Collect the stability report.
592 PostmortemReportCollector collector(kProductName, kVersionNumber, 578 PostmortemReportCollector collector(kProductName, kVersionNumber,
593 kChannelName); 579 kChannelName);
594 std::unique_ptr<StabilityReport> report; 580 StabilityReport report;
595 ASSERT_EQ(PostmortemReportCollector::SUCCESS, 581 ASSERT_EQ(impl::SUCCESS, collector.Collect(debug_file_path(), &report));
596 collector.Collect(debug_file_path(), &report));
597 ASSERT_NE(nullptr, report);
598 582
599 // Validate the report's user data. 583 // Validate the report's user data.
600 const auto& collected_data = report->global_data(); 584 const auto& collected_data = report.global_data();
601 ASSERT_EQ(12U, collected_data.size()); 585 ASSERT_EQ(12U, collected_data.size());
602 586
603 ASSERT_TRUE(base::ContainsKey(collected_data, "raw")); 587 ASSERT_TRUE(base::ContainsKey(collected_data, "raw"));
604 EXPECT_EQ(TypedValue::kBytesValue, collected_data.at("raw").value_case()); 588 EXPECT_EQ(TypedValue::kBytesValue, collected_data.at("raw").value_case());
605 EXPECT_EQ("foo", collected_data.at("raw").bytes_value()); 589 EXPECT_EQ("foo", collected_data.at("raw").bytes_value());
606 590
607 ASSERT_TRUE(base::ContainsKey(collected_data, "string")); 591 ASSERT_TRUE(base::ContainsKey(collected_data, "string"));
608 EXPECT_EQ(TypedValue::kStringValue, collected_data.at("string").value_case()); 592 EXPECT_EQ(TypedValue::kStringValue, collected_data.at("string").value_case());
609 EXPECT_EQ("bar", collected_data.at("string").string_value()); 593 EXPECT_EQ("bar", collected_data.at("string").string_value());
610 594
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, 639 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL,
656 "", 3); 640 "", 3);
657 ActivityUserData& global_data = GlobalActivityTracker::Get()->global_data(); 641 ActivityUserData& global_data = GlobalActivityTracker::Get()->global_data();
658 global_data.SetString("string", "bar"); 642 global_data.SetString("string", "bar");
659 global_data.SetString("FieldTrial.string", "bar"); 643 global_data.SetString("FieldTrial.string", "bar");
660 global_data.SetString("FieldTrial.foo", "bar"); 644 global_data.SetString("FieldTrial.foo", "bar");
661 645
662 // Collect the stability report. 646 // Collect the stability report.
663 PostmortemReportCollector collector(kProductName, kVersionNumber, 647 PostmortemReportCollector collector(kProductName, kVersionNumber,
664 kChannelName); 648 kChannelName);
665 std::unique_ptr<StabilityReport> report; 649 StabilityReport report;
666 ASSERT_EQ(PostmortemReportCollector::SUCCESS, 650 ASSERT_EQ(impl::SUCCESS, collector.Collect(debug_file_path(), &report));
667 collector.Collect(debug_file_path(), &report));
668 ASSERT_NE(nullptr, report);
669 651
670 // Validate the report's experiment and global data. 652 // Validate the report's experiment and global data.
671 ASSERT_EQ(2, report->field_trials_size()); 653 ASSERT_EQ(2, report.field_trials_size());
672 EXPECT_NE(0U, report->field_trials(0).name_id()); 654 EXPECT_NE(0U, report.field_trials(0).name_id());
673 EXPECT_NE(0U, report->field_trials(0).group_id()); 655 EXPECT_NE(0U, report.field_trials(0).group_id());
674 EXPECT_NE(0U, report->field_trials(1).name_id()); 656 EXPECT_NE(0U, report.field_trials(1).name_id());
675 EXPECT_EQ(report->field_trials(0).group_id(), 657 EXPECT_EQ(report.field_trials(0).group_id(),
676 report->field_trials(1).group_id()); 658 report.field_trials(1).group_id());
677 659
678 // Expect 5 key/value pairs (including product details). 660 // Expect 5 key/value pairs (including product details).
679 const auto& collected_data = report->global_data(); 661 const auto& collected_data = report.global_data();
680 EXPECT_EQ(5U, collected_data.size()); 662 EXPECT_EQ(5U, collected_data.size());
681 EXPECT_TRUE(base::ContainsKey(collected_data, "string")); 663 EXPECT_TRUE(base::ContainsKey(collected_data, "string"));
682 } 664 }
683 665
684 TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest, 666 TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
685 ModuleCollection) { 667 ModuleCollection) {
686 // Record some module information. 668 // Record some module information.
687 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, 669 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL,
688 "", 3); 670 "", 3);
689 671
690 base::debug::GlobalActivityTracker::ModuleInfo module_info = {}; 672 base::debug::GlobalActivityTracker::ModuleInfo module_info = {};
691 module_info.is_loaded = true; 673 module_info.is_loaded = true;
692 module_info.address = 0x123456; 674 module_info.address = 0x123456;
693 module_info.load_time = 1111LL; 675 module_info.load_time = 1111LL;
694 module_info.size = 0x2d000; 676 module_info.size = 0x2d000;
695 module_info.timestamp = 0xCAFECAFE; 677 module_info.timestamp = 0xCAFECAFE;
696 module_info.age = 1; 678 module_info.age = 1;
697 crashpad::UUID debug_uuid; 679 crashpad::UUID debug_uuid;
698 debug_uuid.InitializeFromString("11223344-5566-7788-abcd-0123456789ab"); 680 debug_uuid.InitializeFromString("11223344-5566-7788-abcd-0123456789ab");
699 memcpy(module_info.identifier, &debug_uuid, sizeof(module_info.identifier)); 681 memcpy(module_info.identifier, &debug_uuid, sizeof(module_info.identifier));
700 module_info.file = "foo"; 682 module_info.file = "foo";
701 module_info.debug_file = "bar"; 683 module_info.debug_file = "bar";
702 684
703 GlobalActivityTracker::Get()->RecordModuleInfo(module_info); 685 GlobalActivityTracker::Get()->RecordModuleInfo(module_info);
704 686
705 // Collect the stability report. 687 // Collect the stability report.
706 PostmortemReportCollector collector(kProductName, kVersionNumber, 688 PostmortemReportCollector collector(kProductName, kVersionNumber,
707 kChannelName); 689 kChannelName);
708 std::unique_ptr<StabilityReport> report; 690 StabilityReport report;
709 ASSERT_EQ(PostmortemReportCollector::SUCCESS, 691 ASSERT_EQ(impl::SUCCESS, collector.Collect(debug_file_path(), &report));
710 collector.Collect(debug_file_path(), &report));
711 ASSERT_NE(nullptr, report);
712 692
713 // Validate the report's modules content. 693 // Validate the report's modules content.
714 ASSERT_EQ(1, report->process_states_size()); 694 ASSERT_EQ(1, report.process_states_size());
715 const ProcessState& process_state = report->process_states(0); 695 const ProcessState& process_state = report.process_states(0);
716 ASSERT_EQ(1, process_state.modules_size()); 696 ASSERT_EQ(1, process_state.modules_size());
717 697
718 const CodeModule collected_module = process_state.modules(0); 698 const CodeModule collected_module = process_state.modules(0);
719 EXPECT_EQ(module_info.address, 699 EXPECT_EQ(module_info.address,
720 static_cast<uintptr_t>(collected_module.base_address())); 700 static_cast<uintptr_t>(collected_module.base_address()));
721 EXPECT_EQ(module_info.size, static_cast<size_t>(collected_module.size())); 701 EXPECT_EQ(module_info.size, static_cast<size_t>(collected_module.size()));
722 EXPECT_EQ(module_info.file, collected_module.code_file()); 702 EXPECT_EQ(module_info.file, collected_module.code_file());
723 EXPECT_EQ("CAFECAFE2d000", collected_module.code_identifier()); 703 EXPECT_EQ("CAFECAFE2d000", collected_module.code_identifier());
724 EXPECT_EQ(module_info.debug_file, collected_module.debug_file()); 704 EXPECT_EQ(module_info.debug_file, collected_module.debug_file());
725 EXPECT_EQ("1122334455667788ABCD0123456789AB1", 705 EXPECT_EQ("1122334455667788ABCD0123456789AB1",
726 collected_module.debug_identifier()); 706 collected_module.debug_identifier());
727 EXPECT_EQ("", collected_module.version()); 707 EXPECT_EQ("", collected_module.version());
728 EXPECT_EQ(0LL, collected_module.shrink_down_delta()); 708 EXPECT_EQ(0LL, collected_module.shrink_down_delta());
729 EXPECT_EQ(!module_info.is_loaded, collected_module.is_unloaded()); 709 EXPECT_EQ(!module_info.is_loaded, collected_module.is_unloaded());
730 } 710 }
731 711
732 } // namespace browser_watcher 712 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698