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

Unified Diff: components/browser_watcher/postmortem_report_collector_unittest.cc

Issue 2467103002: Collect an initial set of stability activities (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: components/browser_watcher/postmortem_report_collector_unittest.cc
diff --git a/components/browser_watcher/postmortem_report_collector_unittest.cc b/components/browser_watcher/postmortem_report_collector_unittest.cc
index 6049189f3d1bea5f0e184db16dfe8147a553a0e6..02f753e68c992ae438487d8f7162428ac8578a9c 100644
--- a/components/browser_watcher/postmortem_report_collector_unittest.cc
+++ b/components/browser_watcher/postmortem_report_collector_unittest.cc
@@ -21,6 +21,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/persistent_memory_allocator.h"
+#include "base/process/process_handle.h"
#include "base/threading/platform_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -28,7 +29,6 @@
namespace browser_watcher {
-using base::debug::Activity;
using base::debug::ActivityData;
using base::debug::GlobalActivityTracker;
using base::debug::ThreadActivityTracker;
@@ -326,9 +326,16 @@ namespace {
// Parameters for the activity tracking.
const size_t kFileSize = 2 * 1024;
-const int kStackDepth = 4;
+const int kStackDepth = 5;
const uint64_t kAllocatorId = 0;
const char kAllocatorName[] = "PostmortemReportCollectorCollectionTest";
+const int kTaskSequenceNum = 42;
+const uintptr_t kTaskOrigin = 1000U;
+const uintptr_t kLockAddress = 1001U;
+const uintptr_t kEventAddress = 1002U;
+const int kThreadId = 43;
+const int kProcessId = 44;
+const int kAnotherThreadId = 45;
} // namespace
@@ -354,12 +361,22 @@ class PostmortemReportCollectorCollectionTest : public testing::Test {
ASSERT_NE(nullptr, tracker);
ASSERT_TRUE(tracker->IsValid());
- const void* dummy_task_origin = reinterpret_cast<void*>(0xCAFE);
- const int dummy_task_sequence_num = 42;
- tracker->PushActivity(dummy_task_origin, Activity::ACT_TASK_RUN,
- ActivityData::ForTask(dummy_task_sequence_num));
-
- // TODO(manzagop): flesh out the data (more trackers and content).
+ tracker->PushActivity(reinterpret_cast<void*>(kTaskOrigin),
bcwhite 2016/11/02 16:52:37 This is far away from where it's tested. How abou
manzagop (departed) 2016/11/02 20:15:23 Done.
bcwhite 2016/11/03 17:56:25 Acknowledged.
+ base::debug::Activity::ACT_TASK_RUN,
+ ActivityData::ForTask(kTaskSequenceNum));
+ tracker->PushActivity(
+ nullptr, base::debug::Activity::ACT_LOCK_ACQUIRE,
+ ActivityData::ForLock(reinterpret_cast<void*>(kLockAddress)));
+ tracker->PushActivity(
+ nullptr, base::debug::Activity::ACT_EVENT_WAIT,
+ ActivityData::ForEvent(reinterpret_cast<void*>(kEventAddress)));
+ tracker->PushActivity(nullptr, base::debug::Activity::ACT_THREAD_JOIN,
+ ActivityData::ForThread(kThreadId));
+ tracker->PushActivity(nullptr, base::debug::Activity::ACT_PROCESS_WAIT,
+ ActivityData::ForProcess(kProcessId));
+ // Note: this exceeds the stack's capacity.
+ tracker->PushActivity(nullptr, base::debug::Activity::ACT_THREAD_JOIN,
+ ActivityData::ForThread(kAnotherThreadId));
}
std::unique_ptr<PersistentMemoryAllocator> CreateAllocator() {
@@ -417,13 +434,49 @@ TEST_F(PostmortemReportCollectorCollectionTest, CollectSuccess) {
collector.Collect(debug_file_path(), &report));
ASSERT_NE(nullptr, report);
- // Build the expected report.
- StabilityReport expected_report;
- ProcessState* process_state = expected_report.add_process_states();
- ThreadState* thread_state = process_state->add_threads();
- thread_state->set_thread_name(base::PlatformThread::GetName());
-
- ASSERT_EQ(expected_report.SerializeAsString(), report->SerializeAsString());
+ // Validate the report.
+ ASSERT_EQ(1, report->process_states_size());
+ const ProcessState& process_state = report->process_states(0);
+ EXPECT_EQ(base::GetCurrentProcId(), process_state.process_id());
+ ASSERT_EQ(1, process_state.threads_size());
+
+ const ThreadState& thread_state = process_state.threads(0);
+ EXPECT_EQ(base::PlatformThread::GetName(), thread_state.thread_name());
+#if defined(OS_WIN)
+ EXPECT_EQ(base::PlatformThread::CurrentId(), thread_state.thread_id());
+#elif defined(OS_POSIX)
+ EXPECT_EQ(base::PlatformThread::CurrentHandle().platform_handle(),
+ thread_state.thread_id());
+#endif
+
+ EXPECT_EQ(6, thread_state.activity_cnt());
+ ASSERT_EQ(5, thread_state.activities_size());
+ {
+ const Activity& activity = thread_state.activities(0);
+ EXPECT_EQ(Activity::ACT_TASK_RUN, activity.type());
+ EXPECT_EQ(kTaskOrigin, activity.origin_address());
+ EXPECT_EQ(kTaskSequenceNum, activity.task_sequence_id());
+ }
+ {
+ const Activity& activity = thread_state.activities(1);
+ EXPECT_EQ(Activity::ACT_LOCK_ACQUIRE, activity.type());
+ EXPECT_EQ(kLockAddress, activity.lock_address());
+ }
+ {
+ const Activity& activity = thread_state.activities(2);
+ EXPECT_EQ(Activity::ACT_EVENT_WAIT, activity.type());
+ EXPECT_EQ(kEventAddress, activity.event_address());
+ }
+ {
+ const Activity& activity = thread_state.activities(3);
+ EXPECT_EQ(Activity::ACT_THREAD_JOIN, activity.type());
+ EXPECT_EQ(kThreadId, activity.thread_id());
+ }
+ {
+ const Activity& activity = thread_state.activities(4);
+ EXPECT_EQ(Activity::ACT_PROCESS_WAIT, activity.type());
+ EXPECT_EQ(kProcessId, activity.process_id());
+ }
}
} // namespace browser_watcher

Powered by Google App Engine
This is Rietveld 408576698