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

Side by Side Diff: base/trace_event/memory_dump_manager_unittest.cc

Issue 1546033002: Switch to standard integer types in base/trace_event/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « base/trace_event/memory_dump_manager.h ('k') | base/trace_event/process_memory_dump.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/trace_event/memory_dump_manager.h" 5 #include "base/trace_event/memory_dump_manager.h"
6 6
7 #include <stdint.h>
8
7 #include <vector> 9 #include <vector>
8 10
9 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
10 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 14 #include "base/run_loop.h"
13 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
14 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
15 #include "base/test/test_io_thread.h" 17 #include "base/test/test_io_thread.h"
16 #include "base/test/trace_event_analyzer.h" 18 #include "base/test/trace_event_analyzer.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 MemoryDumpManagerDelegateForTesting() { 78 MemoryDumpManagerDelegateForTesting() {
77 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) 79 ON_CALL(*this, RequestGlobalMemoryDump(_, _))
78 .WillByDefault(Invoke( 80 .WillByDefault(Invoke(
79 this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump)); 81 this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump));
80 } 82 }
81 83
82 MOCK_METHOD2(RequestGlobalMemoryDump, 84 MOCK_METHOD2(RequestGlobalMemoryDump,
83 void(const MemoryDumpRequestArgs& args, 85 void(const MemoryDumpRequestArgs& args,
84 const MemoryDumpCallback& callback)); 86 const MemoryDumpCallback& callback));
85 87
86 uint64 GetTracingProcessId() const override { 88 uint64_t GetTracingProcessId() const override {
87 NOTREACHED(); 89 NOTREACHED();
88 return MemoryDumpManager::kInvalidTracingProcessId; 90 return MemoryDumpManager::kInvalidTracingProcessId;
89 } 91 }
90 }; 92 };
91 93
92 class MockMemoryDumpProvider : public MemoryDumpProvider { 94 class MockMemoryDumpProvider : public MemoryDumpProvider {
93 public: 95 public:
94 MOCK_METHOD2(OnMemoryDump, 96 MOCK_METHOD2(OnMemoryDump,
95 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd)); 97 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd));
96 }; 98 };
(...skipping 16 matching lines...) Expand all
113 mdm_.reset(); 115 mdm_.reset();
114 delegate_.reset(); 116 delegate_.reset();
115 message_loop_.reset(); 117 message_loop_.reset();
116 TraceLog::DeleteForTesting(); 118 TraceLog::DeleteForTesting();
117 } 119 }
118 120
119 // Turns a Closure into a MemoryDumpCallback, keeping track of the callback 121 // Turns a Closure into a MemoryDumpCallback, keeping track of the callback
120 // result and taking care of posting the closure on the correct task runner. 122 // result and taking care of posting the closure on the correct task runner.
121 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, 123 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner,
122 Closure closure, 124 Closure closure,
123 uint64 dump_guid, 125 uint64_t dump_guid,
124 bool success) { 126 bool success) {
125 last_callback_success_ = success; 127 last_callback_success_ = success;
126 task_runner->PostTask(FROM_HERE, closure); 128 task_runner->PostTask(FROM_HERE, closure);
127 } 129 }
128 130
129 protected: 131 protected:
130 void InitializeMemoryDumpManager(bool is_coordinator) { 132 void InitializeMemoryDumpManager(bool is_coordinator) {
131 mdm_->set_dumper_registrations_ignored_for_testing(true); 133 mdm_->set_dumper_registrations_ignored_for_testing(true);
132 mdm_->Initialize(delegate_.get(), is_coordinator); 134 mdm_->Initialize(delegate_.get(), is_coordinator);
133 } 135 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 DisableTracing(); 368 DisableTracing();
367 } 369 }
368 } 370 }
369 371
370 // Checks that the MemoryDumpManager respects the thread affinity when a 372 // Checks that the MemoryDumpManager respects the thread affinity when a
371 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 373 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8
372 // threads and registering a MemoryDumpProvider on each of them. At each 374 // threads and registering a MemoryDumpProvider on each of them. At each
373 // iteration, one thread is removed, to check the live unregistration logic. 375 // iteration, one thread is removed, to check the live unregistration logic.
374 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { 376 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) {
375 InitializeMemoryDumpManager(false /* is_coordinator */); 377 InitializeMemoryDumpManager(false /* is_coordinator */);
376 const uint32 kNumInitialThreads = 8; 378 const uint32_t kNumInitialThreads = 8;
377 379
378 std::vector<scoped_ptr<Thread>> threads; 380 std::vector<scoped_ptr<Thread>> threads;
379 std::vector<scoped_ptr<MockMemoryDumpProvider>> mdps; 381 std::vector<scoped_ptr<MockMemoryDumpProvider>> mdps;
380 382
381 // Create the threads and setup the expectations. Given that at each iteration 383 // Create the threads and setup the expectations. Given that at each iteration
382 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be 384 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be
383 // invoked a number of times equal to its index. 385 // invoked a number of times equal to its index.
384 for (uint32 i = kNumInitialThreads; i > 0; --i) { 386 for (uint32_t i = kNumInitialThreads; i > 0; --i) {
385 threads.push_back(make_scoped_ptr(new Thread("test thread"))); 387 threads.push_back(make_scoped_ptr(new Thread("test thread")));
386 auto thread = threads.back().get(); 388 auto thread = threads.back().get();
387 thread->Start(); 389 thread->Start();
388 scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner(); 390 scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner();
389 mdps.push_back(make_scoped_ptr(new MockMemoryDumpProvider())); 391 mdps.push_back(make_scoped_ptr(new MockMemoryDumpProvider()));
390 auto mdp = mdps.back().get(); 392 auto mdp = mdps.back().get();
391 RegisterDumpProvider(mdp, task_runner, kDefaultOptions); 393 RegisterDumpProvider(mdp, task_runner, kDefaultOptions);
392 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) 394 EXPECT_CALL(*mdp, OnMemoryDump(_, _))
393 .Times(i) 395 .Times(i)
394 .WillRepeatedly(Invoke( 396 .WillRepeatedly(Invoke(
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123))); 872 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123)));
871 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456))); 873 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456)));
872 ASSERT_EQ(1u, trace_analyzer::CountMatches( 874 ASSERT_EQ(1u, trace_analyzer::CountMatches(
873 events, Query::EventPidIs(GetCurrentProcId()))); 875 events, Query::EventPidIs(GetCurrentProcId())));
874 ASSERT_EQ(events[0]->id, events[1]->id); 876 ASSERT_EQ(events[0]->id, events[1]->id);
875 ASSERT_EQ(events[0]->id, events[2]->id); 877 ASSERT_EQ(events[0]->id, events[2]->id);
876 } 878 }
877 879
878 } // namespace trace_event 880 } // namespace trace_event
879 } // namespace base 881 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_dump_manager.h ('k') | base/trace_event/process_memory_dump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698