| 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> |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 const uint64_t kTaskSequenceNum = 42; | 333 const uint64_t kTaskSequenceNum = 42; |
| 334 const uintptr_t kTaskOrigin = 1000U; | 334 const uintptr_t kTaskOrigin = 1000U; |
| 335 const uintptr_t kLockAddress = 1001U; | 335 const uintptr_t kLockAddress = 1001U; |
| 336 const uintptr_t kEventAddress = 1002U; | 336 const uintptr_t kEventAddress = 1002U; |
| 337 const int kThreadId = 43; | 337 const int kThreadId = 43; |
| 338 const int kProcessId = 44; | 338 const int kProcessId = 44; |
| 339 const int kAnotherThreadId = 45; | 339 const int kAnotherThreadId = 45; |
| 340 | 340 |
| 341 } // namespace | 341 } // namespace |
| 342 | 342 |
| 343 // Sets up a file backed thread tracker for direct access. A |
| 344 // GlobalActivityTracker is not created, meaning there is no risk of |
| 345 // the instrumentation interfering with the file's content. |
| 343 class PostmortemReportCollectorCollectionTest : public testing::Test { | 346 class PostmortemReportCollectorCollectionTest : public testing::Test { |
| 344 public: | 347 public: |
| 345 // Create a proper debug file. | 348 // Create a proper debug file. |
| 346 void SetUp() override { | 349 void SetUp() override { |
| 347 testing::Test::SetUp(); | 350 testing::Test::SetUp(); |
| 348 | 351 |
| 349 // Create a file backed allocator. | 352 // Create a file backed allocator. |
| 350 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 353 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 351 debug_file_path_ = temp_dir_.GetPath().AppendASCII("debug_file.pma"); | 354 debug_file_path_ = temp_dir_.GetPath().AppendASCII("debug_file.pma"); |
| 352 allocator_ = CreateAllocator(); | 355 allocator_ = CreateAllocator(); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 EXPECT_EQ(Activity::ACT_THREAD_JOIN, activity.type()); | 480 EXPECT_EQ(Activity::ACT_THREAD_JOIN, activity.type()); |
| 478 EXPECT_EQ(kThreadId, activity.thread_id()); | 481 EXPECT_EQ(kThreadId, activity.thread_id()); |
| 479 } | 482 } |
| 480 { | 483 { |
| 481 const Activity& activity = thread_state.activities(4); | 484 const Activity& activity = thread_state.activities(4); |
| 482 EXPECT_EQ(Activity::ACT_PROCESS_WAIT, activity.type()); | 485 EXPECT_EQ(Activity::ACT_PROCESS_WAIT, activity.type()); |
| 483 EXPECT_EQ(kProcessId, activity.process_id()); | 486 EXPECT_EQ(kProcessId, activity.process_id()); |
| 484 } | 487 } |
| 485 } | 488 } |
| 486 | 489 |
| 490 class PostmortemReportCollectorCollectionFromGlobalTrackerTest |
| 491 : public testing::Test { |
| 492 public: |
| 493 const int kMemorySize = 1 << 20; // 1MiB |
| 494 |
| 495 PostmortemReportCollectorCollectionFromGlobalTrackerTest() {} |
| 496 ~PostmortemReportCollectorCollectionFromGlobalTrackerTest() override { |
| 497 GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get(); |
| 498 if (global_tracker) { |
| 499 global_tracker->ReleaseTrackerForCurrentThreadForTesting(); |
| 500 delete global_tracker; |
| 501 } |
| 502 } |
| 503 |
| 504 void SetUp() override { |
| 505 testing::Test::SetUp(); |
| 506 |
| 507 // Set up a debug file path. |
| 508 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 509 debug_file_path_ = temp_dir_.GetPath().AppendASCII("debug.pma"); |
| 510 } |
| 511 |
| 512 const base::FilePath& debug_file_path() { return debug_file_path_; } |
| 513 |
| 514 protected: |
| 515 base::ScopedTempDir temp_dir_; |
| 516 base::FilePath debug_file_path_; |
| 517 }; |
| 518 |
| 519 TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 520 LogCollection) { |
| 521 // Record some log messages. |
| 522 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, |
| 523 "", 3); |
| 524 GlobalActivityTracker::Get()->RecordLogMessage("hello world"); |
| 525 GlobalActivityTracker::Get()->RecordLogMessage("foo bar"); |
| 526 |
| 527 // Collect the stability report. |
| 528 PostmortemReportCollector collector(kProductName, kVersionNumber, |
| 529 kChannelName); |
| 530 std::unique_ptr<StabilityReport> report; |
| 531 ASSERT_EQ(PostmortemReportCollector::SUCCESS, |
| 532 collector.Collect(debug_file_path(), &report)); |
| 533 ASSERT_NE(nullptr, report); |
| 534 |
| 535 // Validate the report's log content. |
| 536 ASSERT_EQ(2, report->log_messages_size()); |
| 537 ASSERT_EQ("hello world", report->log_messages(0)); |
| 538 ASSERT_EQ("foo bar", report->log_messages(1)); |
| 539 } |
| 540 |
| 487 } // namespace browser_watcher | 541 } // namespace browser_watcher |
| OLD | NEW |