| 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 PostmortemReportCollector collector(kProductName, kVersionNumber, | 335 PostmortemReportCollector collector(kProductName, kVersionNumber, |
| 336 kChannelName, nullptr); | 336 kChannelName, nullptr); |
| 337 StabilityReport report; | 337 StabilityReport report; |
| 338 ASSERT_EQ(DEBUG_FILE_NO_DATA, collector.CollectOneReport(file_path, &report)); | 338 ASSERT_EQ(DEBUG_FILE_NO_DATA, collector.CollectOneReport(file_path, &report)); |
| 339 } | 339 } |
| 340 | 340 |
| 341 namespace { | 341 namespace { |
| 342 | 342 |
| 343 // Parameters for the activity tracking. | 343 // Parameters for the activity tracking. |
| 344 const size_t kFileSize = 2 * 1024; | 344 const size_t kFileSize = 2 * 1024; |
| 345 const int kStackDepth = 5; | 345 const int kStackDepth = 6; |
| 346 const uint64_t kAllocatorId = 0; | 346 const uint64_t kAllocatorId = 0; |
| 347 const char kAllocatorName[] = "PostmortemReportCollectorCollectionTest"; | 347 const char kAllocatorName[] = "PostmortemReportCollectorCollectionTest"; |
| 348 const uint64_t kTaskSequenceNum = 42; | 348 const uint64_t kTaskSequenceNum = 42; |
| 349 const uintptr_t kTaskOrigin = 1000U; | 349 const uintptr_t kTaskOrigin = 1000U; |
| 350 const uintptr_t kLockAddress = 1001U; | 350 const uintptr_t kLockAddress = 1001U; |
| 351 const uintptr_t kEventAddress = 1002U; | 351 const uintptr_t kEventAddress = 1002U; |
| 352 const int kThreadId = 43; | 352 const int kThreadId = 43; |
| 353 const int kProcessId = 44; | 353 const int kProcessId = 44; |
| 354 const int kAnotherThreadId = 45; | 354 const int kAnotherThreadId = 45; |
| 355 const uint32_t kGenericId = 46U; |
| 356 const int32_t kGenericData = 47; |
| 355 | 357 |
| 356 } // namespace | 358 } // namespace |
| 357 | 359 |
| 358 // Sets up a file backed thread tracker for direct access. A | 360 // Sets up a file backed thread tracker for direct access. A |
| 359 // GlobalActivityTracker is not created, meaning there is no risk of | 361 // GlobalActivityTracker is not created, meaning there is no risk of |
| 360 // the instrumentation interfering with the file's content. | 362 // the instrumentation interfering with the file's content. |
| 361 class PostmortemReportCollectorCollectionTest : public testing::Test { | 363 class PostmortemReportCollectorCollectionTest : public testing::Test { |
| 362 public: | 364 public: |
| 363 // Create a proper debug file. | 365 // Create a proper debug file. |
| 364 void SetUp() override { | 366 void SetUp() override { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 tracker_->PushActivity( | 440 tracker_->PushActivity( |
| 439 nullptr, base::debug::Activity::ACT_LOCK_ACQUIRE, | 441 nullptr, base::debug::Activity::ACT_LOCK_ACQUIRE, |
| 440 ActivityData::ForLock(reinterpret_cast<void*>(kLockAddress))); | 442 ActivityData::ForLock(reinterpret_cast<void*>(kLockAddress))); |
| 441 ThreadActivityTracker::ActivityId activity_id = tracker_->PushActivity( | 443 ThreadActivityTracker::ActivityId activity_id = tracker_->PushActivity( |
| 442 nullptr, base::debug::Activity::ACT_EVENT_WAIT, | 444 nullptr, base::debug::Activity::ACT_EVENT_WAIT, |
| 443 ActivityData::ForEvent(reinterpret_cast<void*>(kEventAddress))); | 445 ActivityData::ForEvent(reinterpret_cast<void*>(kEventAddress))); |
| 444 tracker_->PushActivity(nullptr, base::debug::Activity::ACT_THREAD_JOIN, | 446 tracker_->PushActivity(nullptr, base::debug::Activity::ACT_THREAD_JOIN, |
| 445 ActivityData::ForThread(kThreadId)); | 447 ActivityData::ForThread(kThreadId)); |
| 446 tracker_->PushActivity(nullptr, base::debug::Activity::ACT_PROCESS_WAIT, | 448 tracker_->PushActivity(nullptr, base::debug::Activity::ACT_PROCESS_WAIT, |
| 447 ActivityData::ForProcess(kProcessId)); | 449 ActivityData::ForProcess(kProcessId)); |
| 450 tracker_->PushActivity(nullptr, base::debug::Activity::ACT_GENERIC, |
| 451 ActivityData::ForGeneric(kGenericId, kGenericData)); |
| 448 // Note: this exceeds the activity stack's capacity. | 452 // Note: this exceeds the activity stack's capacity. |
| 449 tracker_->PushActivity(nullptr, base::debug::Activity::ACT_THREAD_JOIN, | 453 tracker_->PushActivity(nullptr, base::debug::Activity::ACT_THREAD_JOIN, |
| 450 ActivityData::ForThread(kAnotherThreadId)); | 454 ActivityData::ForThread(kAnotherThreadId)); |
| 451 | 455 |
| 452 // Add some user data. | 456 // Add some user data. |
| 453 ActivityTrackerMemoryAllocator user_data_allocator( | 457 ActivityTrackerMemoryAllocator user_data_allocator( |
| 454 allocator_.get(), GlobalActivityTracker::kTypeIdUserDataRecord, | 458 allocator_.get(), GlobalActivityTracker::kTypeIdUserDataRecord, |
| 455 GlobalActivityTracker::kTypeIdUserDataRecordFree, 1024U, 10U, false); | 459 GlobalActivityTracker::kTypeIdUserDataRecordFree, 1024U, 10U, false); |
| 456 std::unique_ptr<ActivityUserData> user_data = | 460 std::unique_ptr<ActivityUserData> user_data = |
| 457 tracker_->GetUserData(activity_id, &user_data_allocator); | 461 tracker_->GetUserData(activity_id, &user_data_allocator); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 471 | 475 |
| 472 const ThreadState& thread_state = process_state.threads(0); | 476 const ThreadState& thread_state = process_state.threads(0); |
| 473 EXPECT_EQ(base::PlatformThread::GetName(), thread_state.thread_name()); | 477 EXPECT_EQ(base::PlatformThread::GetName(), thread_state.thread_name()); |
| 474 #if defined(OS_WIN) | 478 #if defined(OS_WIN) |
| 475 EXPECT_EQ(base::PlatformThread::CurrentId(), thread_state.thread_id()); | 479 EXPECT_EQ(base::PlatformThread::CurrentId(), thread_state.thread_id()); |
| 476 #elif defined(OS_POSIX) | 480 #elif defined(OS_POSIX) |
| 477 EXPECT_EQ(base::PlatformThread::CurrentHandle().platform_handle(), | 481 EXPECT_EQ(base::PlatformThread::CurrentHandle().platform_handle(), |
| 478 thread_state.thread_id()); | 482 thread_state.thread_id()); |
| 479 #endif | 483 #endif |
| 480 | 484 |
| 481 EXPECT_EQ(6, thread_state.activity_count()); | 485 EXPECT_EQ(7, thread_state.activity_count()); |
| 482 ASSERT_EQ(5, thread_state.activities_size()); | 486 ASSERT_EQ(6, thread_state.activities_size()); |
| 483 { | 487 { |
| 484 const Activity& activity = thread_state.activities(0); | 488 const Activity& activity = thread_state.activities(0); |
| 485 EXPECT_EQ(Activity::ACT_TASK_RUN, activity.type()); | 489 EXPECT_EQ(Activity::ACT_TASK_RUN, activity.type()); |
| 486 EXPECT_EQ(kTaskOrigin, activity.origin_address()); | 490 EXPECT_EQ(kTaskOrigin, activity.origin_address()); |
| 487 EXPECT_EQ(kTaskSequenceNum, activity.task_sequence_id()); | 491 EXPECT_EQ(kTaskSequenceNum, activity.task_sequence_id()); |
| 488 EXPECT_EQ(0U, activity.user_data().size()); | 492 EXPECT_EQ(0U, activity.user_data().size()); |
| 489 } | 493 } |
| 490 { | 494 { |
| 491 const Activity& activity = thread_state.activities(1); | 495 const Activity& activity = thread_state.activities(1); |
| 492 EXPECT_EQ(Activity::ACT_LOCK_ACQUIRE, activity.type()); | 496 EXPECT_EQ(Activity::ACT_LOCK_ACQUIRE, activity.type()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 508 EXPECT_EQ(Activity::ACT_THREAD_JOIN, activity.type()); | 512 EXPECT_EQ(Activity::ACT_THREAD_JOIN, activity.type()); |
| 509 EXPECT_EQ(kThreadId, activity.thread_id()); | 513 EXPECT_EQ(kThreadId, activity.thread_id()); |
| 510 EXPECT_EQ(0U, activity.user_data().size()); | 514 EXPECT_EQ(0U, activity.user_data().size()); |
| 511 } | 515 } |
| 512 { | 516 { |
| 513 const Activity& activity = thread_state.activities(4); | 517 const Activity& activity = thread_state.activities(4); |
| 514 EXPECT_EQ(Activity::ACT_PROCESS_WAIT, activity.type()); | 518 EXPECT_EQ(Activity::ACT_PROCESS_WAIT, activity.type()); |
| 515 EXPECT_EQ(kProcessId, activity.process_id()); | 519 EXPECT_EQ(kProcessId, activity.process_id()); |
| 516 EXPECT_EQ(0U, activity.user_data().size()); | 520 EXPECT_EQ(0U, activity.user_data().size()); |
| 517 } | 521 } |
| 522 { |
| 523 const Activity& activity = thread_state.activities(5); |
| 524 EXPECT_EQ(Activity::ACT_GENERIC, activity.type()); |
| 525 EXPECT_EQ(kGenericId, activity.generic_id()); |
| 526 EXPECT_EQ(kGenericData, activity.generic_data()); |
| 527 EXPECT_EQ(0U, activity.user_data().size()); |
| 528 } |
| 518 } | 529 } |
| 519 | 530 |
| 520 class PostmortemReportCollectorCollectionFromGlobalTrackerTest | 531 class PostmortemReportCollectorCollectionFromGlobalTrackerTest |
| 521 : public testing::Test { | 532 : public testing::Test { |
| 522 public: | 533 public: |
| 523 const int kMemorySize = 1 << 20; // 1MiB | 534 const int kMemorySize = 1 << 20; // 1MiB |
| 524 | 535 |
| 525 PostmortemReportCollectorCollectionFromGlobalTrackerTest() {} | 536 PostmortemReportCollectorCollectionFromGlobalTrackerTest() {} |
| 526 ~PostmortemReportCollectorCollectionFromGlobalTrackerTest() override { | 537 ~PostmortemReportCollectorCollectionFromGlobalTrackerTest() override { |
| 527 GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get(); | 538 GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 PostmortemReportCollector collector(kProductName, kVersionNumber, | 747 PostmortemReportCollector collector(kProductName, kVersionNumber, |
| 737 kChannelName, &analyzer); | 748 kChannelName, &analyzer); |
| 738 StabilityReport report; | 749 StabilityReport report; |
| 739 ASSERT_EQ(SUCCESS, collector.CollectOneReport(debug_file_path(), &report)); | 750 ASSERT_EQ(SUCCESS, collector.CollectOneReport(debug_file_path(), &report)); |
| 740 | 751 |
| 741 // Validate the report. | 752 // Validate the report. |
| 742 ASSERT_EQ(SystemState::CLEAN, report.system_state().session_state()); | 753 ASSERT_EQ(SystemState::CLEAN, report.system_state().session_state()); |
| 743 } | 754 } |
| 744 | 755 |
| 745 } // namespace browser_watcher | 756 } // namespace browser_watcher |
| OLD | NEW |