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

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

Issue 1308403002: [Tracing] Disable registration of regular dump providers during tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@reland-content-browsertest
Patch Set: Rename variable Created 5 years, 2 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 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 "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, 85 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner,
86 Closure closure, 86 Closure closure,
87 uint64 dump_guid, 87 uint64 dump_guid,
88 bool success) { 88 bool success) {
89 last_callback_success_ = success; 89 last_callback_success_ = success;
90 task_runner->PostTask(FROM_HERE, closure); 90 task_runner->PostTask(FROM_HERE, closure);
91 } 91 }
92 92
93 protected: 93 protected:
94 void InitializeMemoryDumpManager(bool is_coordinator) { 94 void InitializeMemoryDumpManager(bool is_coordinator) {
95 mdm_->set_dumper_registrations_ignored_for_testing(true);
95 mdm_->Initialize(delegate_.get(), is_coordinator); 96 mdm_->Initialize(delegate_.get(), is_coordinator);
96 } 97 }
97 98
98 void EnableTracingWithLegacyCategories(const char* category) { 99 void EnableTracingWithLegacyCategories(const char* category) {
100 bool registrations_ignored =
101 mdm_->dumper_registrations_ignored_for_testing();
Primiano Tucci (use gerrit) 2015/09/29 17:19:09 Why is this get and re-set needed?
Ruud van Asseldonk 2015/10/13 11:11:47 There should have been an additional disable there
99 TraceLog::GetInstance()->SetEnabled(TraceConfig(category, ""), 102 TraceLog::GetInstance()->SetEnabled(TraceConfig(category, ""),
100 TraceLog::RECORDING_MODE); 103 TraceLog::RECORDING_MODE);
104 mdm_->set_dumper_registrations_ignored_for_testing(registrations_ignored);
101 } 105 }
102 106
103 void EnableTracingWithTraceConfig(const std::string& trace_config) { 107 void EnableTracingWithTraceConfig(const std::string& trace_config) {
108 bool registrations_ignored =
109 mdm_->dumper_registrations_ignored_for_testing();
104 TraceLog::GetInstance()->SetEnabled(TraceConfig(trace_config), 110 TraceLog::GetInstance()->SetEnabled(TraceConfig(trace_config),
105 TraceLog::RECORDING_MODE); 111 TraceLog::RECORDING_MODE);
112 mdm_->set_dumper_registrations_ignored_for_testing(registrations_ignored);
106 } 113 }
107 114
108 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } 115 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); }
109 116
117 void EnableMemoryDumpProviderRegistrations() {
Primiano Tucci (use gerrit) 2015/09/29 17:19:09 I'd like that we used a slightly different approac
Ruud van Asseldonk 2015/10/13 11:11:47 That is much cleaner, great idea.
118 mdm_->set_dumper_registrations_ignored_for_testing(false);
119 }
120
121 void DisableMemoryDumpProviderRegistrations() {
122 mdm_->set_dumper_registrations_ignored_for_testing(true);
123 }
124
110 bool IsPeriodicDumpingEnabled() const { 125 bool IsPeriodicDumpingEnabled() const {
111 return mdm_->periodic_dump_timer_.IsRunning(); 126 return mdm_->periodic_dump_timer_.IsRunning();
112 } 127 }
113 128
114 int GetMaxConsecutiveFailuresCount() const { 129 int GetMaxConsecutiveFailuresCount() const {
115 return MemoryDumpManager::kMaxConsecutiveFailuresCount; 130 return MemoryDumpManager::kMaxConsecutiveFailuresCount;
116 } 131 }
117 132
118 scoped_ptr<MemoryDumpManager> mdm_; 133 scoped_ptr<MemoryDumpManager> mdm_;
119 scoped_ptr<MemoryDumpManagerDelegateForTesting> delegate_; 134 scoped_ptr<MemoryDumpManagerDelegateForTesting> delegate_;
120 bool last_callback_success_; 135 bool last_callback_success_;
121 136
122 private: 137 private:
123 scoped_ptr<MessageLoop> message_loop_; 138 scoped_ptr<MessageLoop> message_loop_;
124 139
125 // We want our singleton torn down after each test. 140 // We want our singleton torn down after each test.
126 ShadowingAtExitManager at_exit_manager_; 141 ShadowingAtExitManager at_exit_manager_;
127 }; 142 };
128 143
129 // Basic sanity checks. Registers a memory dump provider and checks that it is 144 // Basic sanity checks. Registers a memory dump provider and checks that it is
130 // called, but only when memory-infra is enabled. 145 // called, but only when memory-infra is enabled.
131 TEST_F(MemoryDumpManagerTest, SingleDumper) { 146 TEST_F(MemoryDumpManagerTest, SingleDumper) {
132 InitializeMemoryDumpManager(false /* is_coordinator */); 147 InitializeMemoryDumpManager(false /* is_coordinator */);
148 EnableMemoryDumpProviderRegistrations();
133 MockMemoryDumpProvider mdp; 149 MockMemoryDumpProvider mdp;
134 mdm_->RegisterDumpProvider(&mdp); 150 mdm_->RegisterDumpProvider(&mdp);
135 151
136 // Check that the dumper is not called if the memory category is not enabled. 152 // Check that the dumper is not called if the memory category is not enabled.
137 EnableTracingWithLegacyCategories("foobar-but-not-memory"); 153 EnableTracingWithLegacyCategories("foobar-but-not-memory");
138 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); 154 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0);
139 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 155 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
140 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 156 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
141 MemoryDumpLevelOfDetail::DETAILED); 157 MemoryDumpLevelOfDetail::DETAILED);
142 DisableTracing(); 158 DisableTracing();
(...skipping 17 matching lines...) Expand all
160 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 176 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
161 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 177 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
162 MemoryDumpLevelOfDetail::DETAILED); 178 MemoryDumpLevelOfDetail::DETAILED);
163 TraceLog::GetInstance()->SetDisabled(); 179 TraceLog::GetInstance()->SetDisabled();
164 } 180 }
165 181
166 // Checks that requesting dumps with high level of detail actually propagates 182 // Checks that requesting dumps with high level of detail actually propagates
167 // the level of the detail properly to OnMemoryDump() call on dump providers. 183 // the level of the detail properly to OnMemoryDump() call on dump providers.
168 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { 184 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) {
169 InitializeMemoryDumpManager(false /* is_coordinator */); 185 InitializeMemoryDumpManager(false /* is_coordinator */);
186 EnableMemoryDumpProviderRegistrations();
170 MockMemoryDumpProvider mdp; 187 MockMemoryDumpProvider mdp;
171 188
172 mdm_->RegisterDumpProvider(&mdp); 189 mdm_->RegisterDumpProvider(&mdp);
173 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 190 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
174 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 191 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
175 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true)); 192 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true));
176 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 193 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
177 MemoryDumpLevelOfDetail::DETAILED); 194 MemoryDumpLevelOfDetail::DETAILED);
178 DisableTracing(); 195 DisableTracing();
179 mdm_->UnregisterDumpProvider(&mdp); 196 mdm_->UnregisterDumpProvider(&mdp);
180 197
181 // Check that requesting dumps with low level of detail actually propagates to 198 // Check that requesting dumps with low level of detail actually propagates to
182 // OnMemoryDump() call on dump providers. 199 // OnMemoryDump() call on dump providers.
183 mdm_->RegisterDumpProvider(&mdp); 200 mdm_->RegisterDumpProvider(&mdp);
184 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 201 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
185 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 202 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
186 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); 203 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true));
187 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 204 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
188 MemoryDumpLevelOfDetail::LIGHT); 205 MemoryDumpLevelOfDetail::LIGHT);
189 DisableTracing(); 206 DisableTracing();
190 mdm_->UnregisterDumpProvider(&mdp); 207 mdm_->UnregisterDumpProvider(&mdp);
191 } 208 }
192 209
193 // Checks that the SharedSessionState object is acqually shared over time. 210 // Checks that the SharedSessionState object is acqually shared over time.
194 TEST_F(MemoryDumpManagerTest, SharedSessionState) { 211 TEST_F(MemoryDumpManagerTest, SharedSessionState) {
195 InitializeMemoryDumpManager(false /* is_coordinator */); 212 InitializeMemoryDumpManager(false /* is_coordinator */);
213 EnableMemoryDumpProviderRegistrations();
196 MockMemoryDumpProvider mdp1; 214 MockMemoryDumpProvider mdp1;
197 MockMemoryDumpProvider mdp2; 215 MockMemoryDumpProvider mdp2;
198 mdm_->RegisterDumpProvider(&mdp1); 216 mdm_->RegisterDumpProvider(&mdp1);
199 mdm_->RegisterDumpProvider(&mdp2); 217 mdm_->RegisterDumpProvider(&mdp2);
200 218
201 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 219 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
202 const MemoryDumpSessionState* session_state = mdm_->session_state().get(); 220 const MemoryDumpSessionState* session_state = mdm_->session_state().get();
203 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); 221 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2);
204 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 222 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
205 .Times(2) 223 .Times(2)
(...skipping 13 matching lines...) Expand all
219 for (int i = 0; i < 2; ++i) 237 for (int i = 0; i < 2; ++i)
220 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 238 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
221 MemoryDumpLevelOfDetail::DETAILED); 239 MemoryDumpLevelOfDetail::DETAILED);
222 240
223 DisableTracing(); 241 DisableTracing();
224 } 242 }
225 243
226 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. 244 // Checks that the (Un)RegisterDumpProvider logic behaves sanely.
227 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { 245 TEST_F(MemoryDumpManagerTest, MultipleDumpers) {
228 InitializeMemoryDumpManager(false /* is_coordinator */); 246 InitializeMemoryDumpManager(false /* is_coordinator */);
247 EnableMemoryDumpProviderRegistrations();
229 MockMemoryDumpProvider mdp1; 248 MockMemoryDumpProvider mdp1;
230 MockMemoryDumpProvider mdp2; 249 MockMemoryDumpProvider mdp2;
231 250
232 // Enable only mdp1. 251 // Enable only mdp1.
233 mdm_->RegisterDumpProvider(&mdp1); 252 mdm_->RegisterDumpProvider(&mdp1);
234 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 253 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
235 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 254 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
236 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); 255 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true));
237 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); 256 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0);
238 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 257 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
(...skipping 19 matching lines...) Expand all
258 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); 277 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true));
259 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 278 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
260 MemoryDumpLevelOfDetail::DETAILED); 279 MemoryDumpLevelOfDetail::DETAILED);
261 DisableTracing(); 280 DisableTracing();
262 } 281 }
263 282
264 // Checks that the dump provider invocations depend only on the current 283 // Checks that the dump provider invocations depend only on the current
265 // registration state and not on previous registrations and dumps. 284 // registration state and not on previous registrations and dumps.
266 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { 285 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) {
267 InitializeMemoryDumpManager(false /* is_coordinator */); 286 InitializeMemoryDumpManager(false /* is_coordinator */);
287 EnableMemoryDumpProviderRegistrations();
268 MockMemoryDumpProvider mdp; 288 MockMemoryDumpProvider mdp;
269 289
270 mdm_->RegisterDumpProvider(&mdp); 290 mdm_->RegisterDumpProvider(&mdp);
271 291
272 { 292 {
273 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 293 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
274 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); 294 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true));
275 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 295 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
276 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 296 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
277 MemoryDumpLevelOfDetail::DETAILED); 297 MemoryDumpLevelOfDetail::DETAILED);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 339 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8
320 // threads and registering a MemoryDumpProvider on each of them. At each 340 // threads and registering a MemoryDumpProvider on each of them. At each
321 // iteration, one thread is removed, to check the live unregistration logic. 341 // iteration, one thread is removed, to check the live unregistration logic.
322 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { 342 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) {
323 InitializeMemoryDumpManager(false /* is_coordinator */); 343 InitializeMemoryDumpManager(false /* is_coordinator */);
324 const uint32 kNumInitialThreads = 8; 344 const uint32 kNumInitialThreads = 8;
325 345
326 ScopedVector<Thread> threads; 346 ScopedVector<Thread> threads;
327 ScopedVector<MockMemoryDumpProvider> mdps; 347 ScopedVector<MockMemoryDumpProvider> mdps;
328 348
349 EnableMemoryDumpProviderRegistrations();
350
329 // Create the threads and setup the expectations. Given that at each iteration 351 // Create the threads and setup the expectations. Given that at each iteration
330 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be 352 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be
331 // invoked a number of times equal to its index. 353 // invoked a number of times equal to its index.
332 for (uint32 i = kNumInitialThreads; i > 0; --i) { 354 for (uint32 i = kNumInitialThreads; i > 0; --i) {
333 Thread* thread = new Thread("test thread"); 355 Thread* thread = new Thread("test thread");
334 threads.push_back(thread); 356 threads.push_back(thread);
335 threads.back()->Start(); 357 threads.back()->Start();
336 scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner(); 358 scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner();
337 MockMemoryDumpProvider* mdp = new MockMemoryDumpProvider(); 359 MockMemoryDumpProvider* mdp = new MockMemoryDumpProvider();
338 mdps.push_back(mdp); 360 mdps.push_back(mdp);
339 mdm_->RegisterDumpProvider(mdp, task_runner); 361 mdm_->RegisterDumpProvider(mdp, task_runner);
340 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) 362 EXPECT_CALL(*mdp, OnMemoryDump(_, _))
341 .Times(i) 363 .Times(i)
342 .WillRepeatedly(Invoke( 364 .WillRepeatedly(Invoke(
343 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { 365 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool {
344 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); 366 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread());
345 return true; 367 return true;
346 })); 368 }));
347 } 369 }
348 370
371 DisableMemoryDumpProviderRegistrations();
349 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 372 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
350 373
351 while (!threads.empty()) { 374 while (!threads.empty()) {
352 last_callback_success_ = false; 375 last_callback_success_ = false;
353 { 376 {
354 RunLoop run_loop; 377 RunLoop run_loop;
355 MemoryDumpCallback callback = 378 MemoryDumpCallback callback =
356 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 379 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
357 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 380 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
358 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 381 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
(...skipping 22 matching lines...) Expand all
381 threads.pop_back(); 404 threads.pop_back();
382 } 405 }
383 406
384 DisableTracing(); 407 DisableTracing();
385 } 408 }
386 409
387 // Checks that providers get disabled after 3 consecutive failures, but not 410 // Checks that providers get disabled after 3 consecutive failures, but not
388 // otherwise (e.g., if interleaved). 411 // otherwise (e.g., if interleaved).
389 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { 412 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) {
390 InitializeMemoryDumpManager(false /* is_coordinator */); 413 InitializeMemoryDumpManager(false /* is_coordinator */);
414 EnableMemoryDumpProviderRegistrations();
391 MockMemoryDumpProvider mdp1; 415 MockMemoryDumpProvider mdp1;
392 MockMemoryDumpProvider mdp2; 416 MockMemoryDumpProvider mdp2;
393 417
394 mdm_->RegisterDumpProvider(&mdp1); 418 mdm_->RegisterDumpProvider(&mdp1);
395 mdm_->RegisterDumpProvider(&mdp2); 419 mdm_->RegisterDumpProvider(&mdp2);
396 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 420 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
397 421
398 const int kNumDumps = 2 * GetMaxConsecutiveFailuresCount(); 422 const int kNumDumps = 2 * GetMaxConsecutiveFailuresCount();
399 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(kNumDumps); 423 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(kNumDumps);
400 424
(...skipping 14 matching lines...) Expand all
415 MemoryDumpLevelOfDetail::DETAILED); 439 MemoryDumpLevelOfDetail::DETAILED);
416 } 440 }
417 441
418 DisableTracing(); 442 DisableTracing();
419 } 443 }
420 444
421 // Sneakily registers an extra memory dump provider while an existing one is 445 // Sneakily registers an extra memory dump provider while an existing one is
422 // dumping and expect it to take part in the already active tracing session. 446 // dumping and expect it to take part in the already active tracing session.
423 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { 447 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) {
424 InitializeMemoryDumpManager(false /* is_coordinator */); 448 InitializeMemoryDumpManager(false /* is_coordinator */);
449 EnableMemoryDumpProviderRegistrations();
425 MockMemoryDumpProvider mdp1; 450 MockMemoryDumpProvider mdp1;
426 MockMemoryDumpProvider mdp2; 451 MockMemoryDumpProvider mdp2;
427 452
428 mdm_->RegisterDumpProvider(&mdp1); 453 mdm_->RegisterDumpProvider(&mdp1);
429 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 454 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
430 455
431 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); 456 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4);
432 457
433 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 458 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
434 .Times(4) 459 .Times(4)
(...skipping 15 matching lines...) Expand all
450 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 475 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
451 MemoryDumpLevelOfDetail::DETAILED); 476 MemoryDumpLevelOfDetail::DETAILED);
452 } 477 }
453 478
454 DisableTracing(); 479 DisableTracing();
455 } 480 }
456 481
457 // Like RegisterDumperWhileDumping, but unregister the dump provider instead. 482 // Like RegisterDumperWhileDumping, but unregister the dump provider instead.
458 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { 483 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) {
459 InitializeMemoryDumpManager(false /* is_coordinator */); 484 InitializeMemoryDumpManager(false /* is_coordinator */);
485 EnableMemoryDumpProviderRegistrations();
460 MockMemoryDumpProvider mdp1; 486 MockMemoryDumpProvider mdp1;
461 MockMemoryDumpProvider mdp2; 487 MockMemoryDumpProvider mdp2;
462 488
463 mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); 489 mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get());
464 mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); 490 mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get());
465 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 491 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
466 492
467 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); 493 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4);
468 494
469 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 495 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
(...skipping 23 matching lines...) Expand all
493 // Checks that the dump does not abort when unregistering a provider while 519 // Checks that the dump does not abort when unregistering a provider while
494 // dumping from a different thread than the dumping thread. 520 // dumping from a different thread than the dumping thread.
495 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { 521 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) {
496 InitializeMemoryDumpManager(false /* is_coordinator */); 522 InitializeMemoryDumpManager(false /* is_coordinator */);
497 ScopedVector<TestIOThread> threads; 523 ScopedVector<TestIOThread> threads;
498 ScopedVector<MockMemoryDumpProvider> mdps; 524 ScopedVector<MockMemoryDumpProvider> mdps;
499 525
500 for (int i = 0; i < 2; i++) { 526 for (int i = 0; i < 2; i++) {
501 threads.push_back(new TestIOThread(TestIOThread::kAutoStart)); 527 threads.push_back(new TestIOThread(TestIOThread::kAutoStart));
502 mdps.push_back(new MockMemoryDumpProvider()); 528 mdps.push_back(new MockMemoryDumpProvider());
529 EnableMemoryDumpProviderRegistrations();
503 mdm_->RegisterDumpProvider(mdps.back(), threads.back()->task_runner()); 530 mdm_->RegisterDumpProvider(mdps.back(), threads.back()->task_runner());
531 DisableMemoryDumpProviderRegistrations();
504 } 532 }
505 533
506 int on_memory_dump_call_count = 0; 534 int on_memory_dump_call_count = 0;
507 RunLoop run_loop; 535 RunLoop run_loop;
508 536
509 // When OnMemoryDump is called on either of the dump providers, it will 537 // When OnMemoryDump is called on either of the dump providers, it will
510 // unregister the other one. 538 // unregister the other one.
511 for (MockMemoryDumpProvider* mdp : mdps) { 539 for (MockMemoryDumpProvider* mdp : mdps) {
512 int other_idx = (mdps.front() == mdp); 540 int other_idx = (mdps.front() == mdp);
513 TestIOThread* other_thread = threads[other_idx]; 541 TestIOThread* other_thread = threads[other_idx];
(...skipping 30 matching lines...) Expand all
544 ASSERT_EQ(1, on_memory_dump_call_count); 572 ASSERT_EQ(1, on_memory_dump_call_count);
545 ASSERT_EQ(true, last_callback_success_); 573 ASSERT_EQ(true, last_callback_success_);
546 574
547 DisableTracing(); 575 DisableTracing();
548 } 576 }
549 577
550 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when 578 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when
551 // tracing is not enabled. 579 // tracing is not enabled.
552 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { 580 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) {
553 InitializeMemoryDumpManager(false /* is_coordinator */); 581 InitializeMemoryDumpManager(false /* is_coordinator */);
582 EnableMemoryDumpProviderRegistrations();
554 MockMemoryDumpProvider mdp1; 583 MockMemoryDumpProvider mdp1;
555 mdm_->RegisterDumpProvider(&mdp1); 584 mdm_->RegisterDumpProvider(&mdp1);
556 585
557 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); 586 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0);
558 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); 587 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0);
559 588
560 last_callback_success_ = true; 589 last_callback_success_ = true;
561 { 590 {
562 RunLoop run_loop; 591 RunLoop run_loop;
563 MemoryDumpCallback callback = 592 MemoryDumpCallback callback =
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 726
698 EnableTracingWithTraceConfig( 727 EnableTracingWithTraceConfig(
699 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( 728 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(
700 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); 729 kLightDumpPeriodMs, kHeavyDumpPeriodMs));
701 run_loop.Run(); 730 run_loop.Run();
702 DisableTracing(); 731 DisableTracing();
703 } 732 }
704 733
705 } // namespace trace_event 734 } // namespace trace_event
706 } // namespace base 735 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | content/browser/tracing/memory_tracing_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698