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

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: Created 5 years, 4 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 }; 45 };
46 46
47 class MemoryDumpManagerTest : public testing::Test { 47 class MemoryDumpManagerTest : public testing::Test {
48 public: 48 public:
49 void SetUp() override { 49 void SetUp() override {
50 last_callback_success_ = false; 50 last_callback_success_ = false;
51 message_loop_.reset(new MessageLoop()); 51 message_loop_.reset(new MessageLoop());
52 mdm_.reset(new MemoryDumpManager()); 52 mdm_.reset(new MemoryDumpManager());
53 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); 53 MemoryDumpManager::SetInstanceForTesting(mdm_.get());
54 ASSERT_EQ(mdm_, MemoryDumpManager::GetInstance()); 54 ASSERT_EQ(mdm_, MemoryDumpManager::GetInstance());
55 MemoryDumpManager::GetInstance()->Initialize(); 55 mdm_->set_ignore_registrations_for_testing(true);
56 MemoryDumpManager::GetInstance()->SetDelegate(&delegate_); 56 mdm_->Initialize();
57 mdm_->SetDelegate(&delegate_);
57 } 58 }
58 59
59 void TearDown() override { 60 void TearDown() override {
60 MemoryDumpManager::SetInstanceForTesting(nullptr); 61 MemoryDumpManager::SetInstanceForTesting(nullptr);
61 mdm_.reset(); 62 mdm_.reset();
62 message_loop_.reset(); 63 message_loop_.reset();
63 TraceLog::DeleteForTesting(); 64 TraceLog::DeleteForTesting();
64 } 65 }
65 66
66 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, 67 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner,
67 Closure closure, 68 Closure closure,
68 uint64 dump_guid, 69 uint64 dump_guid,
69 bool success) { 70 bool success) {
70 last_callback_success_ = success; 71 last_callback_success_ = success;
71 task_runner->PostTask(FROM_HERE, closure); 72 task_runner->PostTask(FROM_HERE, closure);
72 } 73 }
73 74
74 protected: 75 protected:
75 const char* kTraceCategory = MemoryDumpManager::kTraceCategoryForTesting; 76 const char* kTraceCategory = MemoryDumpManager::kTraceCategoryForTesting;
76 77
77 void EnableTracing(const char* category) { 78 void EnableTracing(const char* category) {
79 bool registrations_ignored = mdm_->ignore_registrations_for_testing();
80 mdm_->set_ignore_registrations_for_testing(true);
78 TraceLog::GetInstance()->SetEnabled( 81 TraceLog::GetInstance()->SetEnabled(
79 TraceConfig(category, ""), TraceLog::RECORDING_MODE); 82 TraceConfig(category, ""), TraceLog::RECORDING_MODE);
83 mdm_->set_ignore_registrations_for_testing(registrations_ignored);
80 } 84 }
81 85
82 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } 86 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); }
83 87
88 void EnableRegistrations() {
Primiano Tucci (use gerrit) 2015/08/24 17:23:34 Nit: EnableMemoryDumpProviderRegistrations (Same b
Ruud van Asseldonk 2015/08/25 09:51:17 Done.
89 mdm_->set_ignore_registrations_for_testing(false);
90 }
91
92 void DisableRegistrations() {
93 mdm_->set_ignore_registrations_for_testing(true);
94 }
95
84 scoped_ptr<MemoryDumpManager> mdm_; 96 scoped_ptr<MemoryDumpManager> mdm_;
85 bool last_callback_success_; 97 bool last_callback_success_;
86 98
87 private: 99 private:
88 scoped_ptr<MessageLoop> message_loop_; 100 scoped_ptr<MessageLoop> message_loop_;
89 MemoryDumpManagerDelegateForTesting delegate_; 101 MemoryDumpManagerDelegateForTesting delegate_;
90 102
91 // We want our singleton torn down after each test. 103 // We want our singleton torn down after each test.
92 ShadowingAtExitManager at_exit_manager_; 104 ShadowingAtExitManager at_exit_manager_;
93 }; 105 };
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 MemoryDumpProvider* dump_provider_to_register_or_unregister; 171 MemoryDumpProvider* dump_provider_to_register_or_unregister;
160 172
161 private: 173 private:
162 MemoryDumpSessionState* last_session_state_; 174 MemoryDumpSessionState* last_session_state_;
163 scoped_refptr<SingleThreadTaskRunner> task_runner_; 175 scoped_refptr<SingleThreadTaskRunner> task_runner_;
164 const MemoryDumpArgs::LevelOfDetail level_of_detail_; 176 const MemoryDumpArgs::LevelOfDetail level_of_detail_;
165 }; 177 };
166 178
167 TEST_F(MemoryDumpManagerTest, SingleDumper) { 179 TEST_F(MemoryDumpManagerTest, SingleDumper) {
168 MockDumpProvider mdp; 180 MockDumpProvider mdp;
181 EnableRegistrations();
169 mdm_->RegisterDumpProvider(&mdp); 182 mdm_->RegisterDumpProvider(&mdp);
170 183
171 // Check that the dumper is not called if the memory category is not enabled. 184 // Check that the dumper is not called if the memory category is not enabled.
172 EnableTracing("foo-and-bar-but-not-memory"); 185 EnableTracing("foo-and-bar-but-not-memory");
173 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 186 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
174 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 187 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
175 high_detail_args); 188 high_detail_args);
176 DisableTracing(); 189 DisableTracing();
177 190
178 // Now repeat enabling the memory category and check that the dumper is 191 // Now repeat enabling the memory category and check that the dumper is
(...skipping 12 matching lines...) Expand all
191 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 204 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
192 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 205 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
193 high_detail_args); 206 high_detail_args);
194 TraceLog::GetInstance()->SetDisabled(); 207 TraceLog::GetInstance()->SetDisabled();
195 } 208 }
196 209
197 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { 210 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) {
198 // Check that requesting dumps with high level of detail actually propagates 211 // Check that requesting dumps with high level of detail actually propagates
199 // to OnMemoryDump() call on dump providers. 212 // to OnMemoryDump() call on dump providers.
200 MockDumpProvider mdp_high_detail(MemoryDumpArgs::LevelOfDetail::HIGH); 213 MockDumpProvider mdp_high_detail(MemoryDumpArgs::LevelOfDetail::HIGH);
214 EnableRegistrations();
201 mdm_->RegisterDumpProvider(&mdp_high_detail); 215 mdm_->RegisterDumpProvider(&mdp_high_detail);
202 216
203 EnableTracing(kTraceCategory); 217 EnableTracing(kTraceCategory);
204 EXPECT_CALL(mdp_high_detail, OnMemoryDump(_, _)) 218 EXPECT_CALL(mdp_high_detail, OnMemoryDump(_, _))
205 .Times(1) 219 .Times(1)
206 .WillRepeatedly( 220 .WillRepeatedly(
207 Invoke(&mdp_high_detail, 221 Invoke(&mdp_high_detail,
208 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs)); 222 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs));
209 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 223 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
210 high_detail_args); 224 high_detail_args);
(...skipping 13 matching lines...) Expand all
224 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs)); 238 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs));
225 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 239 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
226 low_detail_args); 240 low_detail_args);
227 DisableTracing(); 241 DisableTracing();
228 mdm_->UnregisterDumpProvider(&mdp_low_detail); 242 mdm_->UnregisterDumpProvider(&mdp_low_detail);
229 } 243 }
230 244
231 TEST_F(MemoryDumpManagerTest, SharedSessionState) { 245 TEST_F(MemoryDumpManagerTest, SharedSessionState) {
232 MockDumpProvider mdp1; 246 MockDumpProvider mdp1;
233 MockDumpProvider mdp2; 247 MockDumpProvider mdp2;
248 EnableRegistrations();
234 mdm_->RegisterDumpProvider(&mdp1); 249 mdm_->RegisterDumpProvider(&mdp1);
235 mdm_->RegisterDumpProvider(&mdp2); 250 mdm_->RegisterDumpProvider(&mdp2);
236 251
237 EnableTracing(kTraceCategory); 252 EnableTracing(kTraceCategory);
238 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 253 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
239 .Times(2) 254 .Times(2)
240 .WillRepeatedly( 255 .WillRepeatedly(
241 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_CheckSessionState)); 256 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_CheckSessionState));
242 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) 257 EXPECT_CALL(mdp2, OnMemoryDump(_, _))
243 .Times(2) 258 .Times(2)
244 .WillRepeatedly( 259 .WillRepeatedly(
245 Invoke(&mdp2, &MockDumpProvider::OnMemoryDump_CheckSessionState)); 260 Invoke(&mdp2, &MockDumpProvider::OnMemoryDump_CheckSessionState));
246 261
247 for (int i = 0; i < 2; ++i) 262 for (int i = 0; i < 2; ++i)
248 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 263 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
249 high_detail_args); 264 high_detail_args);
250 265
251 DisableTracing(); 266 DisableTracing();
252 } 267 }
253 268
254 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { 269 TEST_F(MemoryDumpManagerTest, MultipleDumpers) {
255 MockDumpProvider mdp1; 270 MockDumpProvider mdp1;
256 MockDumpProvider mdp2; 271 MockDumpProvider mdp2;
257 272
258 // Enable only mdp1. 273 // Enable only mdp1.
274 EnableRegistrations();
259 mdm_->RegisterDumpProvider(&mdp1); 275 mdm_->RegisterDumpProvider(&mdp1);
260 EnableTracing(kTraceCategory); 276 EnableTracing(kTraceCategory);
261 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); 277 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true));
262 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); 278 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0);
263 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 279 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
264 high_detail_args); 280 high_detail_args);
265 DisableTracing(); 281 DisableTracing();
266 282
267 // Invert: enable mdp1 and disable mdp2. 283 // Invert: enable mdp1 and disable mdp2.
268 mdm_->UnregisterDumpProvider(&mdp1); 284 mdm_->UnregisterDumpProvider(&mdp1);
(...skipping 12 matching lines...) Expand all
281 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); 297 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true));
282 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 298 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
283 high_detail_args); 299 high_detail_args);
284 DisableTracing(); 300 DisableTracing();
285 } 301 }
286 302
287 // Verify that whether OnMemoryDump is called depends only on the current 303 // Verify that whether OnMemoryDump is called depends only on the current
288 // registration state and not on previous registrations and dumps. 304 // registration state and not on previous registrations and dumps.
289 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { 305 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) {
290 MockDumpProvider mdp; 306 MockDumpProvider mdp;
307 EnableRegistrations();
291 308
292 mdm_->RegisterDumpProvider(&mdp); 309 mdm_->RegisterDumpProvider(&mdp);
293 310
294 { 311 {
295 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); 312 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1);
296 EnableTracing(kTraceCategory); 313 EnableTracing(kTraceCategory);
297 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 314 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
298 high_detail_args); 315 high_detail_args);
299 DisableTracing(); 316 DisableTracing();
300 } 317 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // Checks that the MemoryDumpManager respects the thread affinity when a 353 // Checks that the MemoryDumpManager respects the thread affinity when a
337 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 354 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8
338 // threads and registering a MemoryDumpProvider on each of them. At each 355 // threads and registering a MemoryDumpProvider on each of them. At each
339 // iteration, one thread is removed, to check the live unregistration logic. 356 // iteration, one thread is removed, to check the live unregistration logic.
340 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { 357 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) {
341 const uint32 kNumInitialThreads = 8; 358 const uint32 kNumInitialThreads = 8;
342 359
343 ScopedVector<Thread> threads; 360 ScopedVector<Thread> threads;
344 ScopedVector<MockDumpProvider> mdps; 361 ScopedVector<MockDumpProvider> mdps;
345 362
363 EnableRegistrations();
364
346 // Create the threads and setup the expectations. Given that at each iteration 365 // Create the threads and setup the expectations. Given that at each iteration
347 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be 366 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be
348 // invoked a number of times equal to its index. 367 // invoked a number of times equal to its index.
349 for (uint32 i = kNumInitialThreads; i > 0; --i) { 368 for (uint32 i = kNumInitialThreads; i > 0; --i) {
350 threads.push_back(new Thread("test thread")); 369 threads.push_back(new Thread("test thread"));
351 threads.back()->Start(); 370 threads.back()->Start();
352 mdps.push_back(new MockDumpProvider(threads.back()->task_runner())); 371 mdps.push_back(new MockDumpProvider(threads.back()->task_runner()));
353 MockDumpProvider* mdp = mdps.back(); 372 MockDumpProvider* mdp = mdps.back();
354 mdm_->RegisterDumpProvider(mdp, threads.back()->task_runner()); 373 mdm_->RegisterDumpProvider(mdp, threads.back()->task_runner());
355 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) 374 EXPECT_CALL(*mdp, OnMemoryDump(_, _))
356 .Times(i) 375 .Times(i)
357 .WillRepeatedly( 376 .WillRepeatedly(
358 Invoke(mdp, &MockDumpProvider::OnMemoryDump_CheckTaskRunner)); 377 Invoke(mdp, &MockDumpProvider::OnMemoryDump_CheckTaskRunner));
359 } 378 }
360 379
361 EnableTracing(kTraceCategory); 380 EnableTracing(kTraceCategory);
362 381
382 DisableRegistrations();
383
363 while (!threads.empty()) { 384 while (!threads.empty()) {
364 last_callback_success_ = false; 385 last_callback_success_ = false;
365 { 386 {
366 RunLoop run_loop; 387 RunLoop run_loop;
367 MemoryDumpCallback callback = 388 MemoryDumpCallback callback =
368 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 389 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
369 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 390 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
370 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 391 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
371 high_detail_args, callback); 392 high_detail_args, callback);
372 // This nested message loop (|run_loop|) will be quit if and only if 393 // This nested message loop (|run_loop|) will be quit if and only if
(...skipping 21 matching lines...) Expand all
394 415
395 DisableTracing(); 416 DisableTracing();
396 } 417 }
397 418
398 // Enable both dump providers, make sure that mdp gets disabled after 3 failures 419 // Enable both dump providers, make sure that mdp gets disabled after 3 failures
399 // and not disabled after 1. 420 // and not disabled after 1.
400 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { 421 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) {
401 MockDumpProvider mdp1; 422 MockDumpProvider mdp1;
402 MockDumpProvider mdp2; 423 MockDumpProvider mdp2;
403 424
425 EnableRegistrations();
404 mdm_->RegisterDumpProvider(&mdp1); 426 mdm_->RegisterDumpProvider(&mdp1);
405 mdm_->RegisterDumpProvider(&mdp2); 427 mdm_->RegisterDumpProvider(&mdp2);
406 EnableTracing(kTraceCategory); 428 EnableTracing(kTraceCategory);
407 429
408 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 430 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
409 .Times(MemoryDumpManager::kMaxConsecutiveFailuresCount) 431 .Times(MemoryDumpManager::kMaxConsecutiveFailuresCount)
410 .WillRepeatedly(Return(false)); 432 .WillRepeatedly(Return(false));
411 433
412 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) 434 EXPECT_CALL(mdp2, OnMemoryDump(_, _))
413 .Times(1 + MemoryDumpManager::kMaxConsecutiveFailuresCount) 435 .Times(1 + MemoryDumpManager::kMaxConsecutiveFailuresCount)
414 .WillOnce(Return(false)) 436 .WillOnce(Return(false))
415 .WillRepeatedly(Return(true)); 437 .WillRepeatedly(Return(true));
416 for (int i = 0; i < 1 + MemoryDumpManager::kMaxConsecutiveFailuresCount; 438 for (int i = 0; i < 1 + MemoryDumpManager::kMaxConsecutiveFailuresCount;
417 i++) { 439 i++) {
418 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 440 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
419 high_detail_args); 441 high_detail_args);
420 } 442 }
421 443
422 DisableTracing(); 444 DisableTracing();
423 } 445 }
424 446
425 // Sneakily register an extra memory dump provider while an existing one is 447 // Sneakily register an extra memory dump provider while an existing one is
426 // dumping and expect it to take part in the already active tracing session. 448 // dumping and expect it to take part in the already active tracing session.
427 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { 449 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) {
428 MockDumpProvider mdp1; 450 MockDumpProvider mdp1;
429 MockDumpProvider mdp2; 451 MockDumpProvider mdp2;
430 452
453 EnableRegistrations();
431 mdp1.dump_provider_to_register_or_unregister = &mdp2; 454 mdp1.dump_provider_to_register_or_unregister = &mdp2;
432 mdm_->RegisterDumpProvider(&mdp1); 455 mdm_->RegisterDumpProvider(&mdp1);
433 EnableTracing(kTraceCategory); 456 EnableTracing(kTraceCategory);
434 457
435 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 458 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
436 .Times(4) 459 .Times(4)
437 .WillOnce(Return(true)) 460 .WillOnce(Return(true))
438 .WillOnce(Invoke( 461 .WillOnce(Invoke(
439 &mdp1, &MockDumpProvider::OnMemoryDump_RegisterExtraDumpProvider)) 462 &mdp1, &MockDumpProvider::OnMemoryDump_RegisterExtraDumpProvider))
440 .WillRepeatedly(Return(true)); 463 .WillRepeatedly(Return(true));
(...skipping 10 matching lines...) Expand all
451 } 474 }
452 475
453 DisableTracing(); 476 DisableTracing();
454 } 477 }
455 478
456 // Like the above, but suddenly unregister the dump provider. 479 // Like the above, but suddenly unregister the dump provider.
457 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { 480 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) {
458 MockDumpProvider mdp1; 481 MockDumpProvider mdp1;
459 MockDumpProvider mdp2; 482 MockDumpProvider mdp2;
460 483
484 EnableRegistrations();
461 mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); 485 mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get());
462 mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); 486 mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get());
463 mdp1.dump_provider_to_register_or_unregister = &mdp2; 487 mdp1.dump_provider_to_register_or_unregister = &mdp2;
464 EnableTracing(kTraceCategory); 488 EnableTracing(kTraceCategory);
465 489
466 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 490 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
467 .Times(4) 491 .Times(4)
468 .WillOnce(Return(true)) 492 .WillOnce(Return(true))
469 .WillOnce( 493 .WillOnce(
470 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_UnregisterDumpProvider)) 494 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_UnregisterDumpProvider))
(...skipping 15 matching lines...) Expand all
486 510
487 // Verify that the dump does not abort when unregistering a provider while 511 // Verify that the dump does not abort when unregistering a provider while
488 // dumping from a different thread than the dumping thread. 512 // dumping from a different thread than the dumping thread.
489 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { 513 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) {
490 ScopedVector<TestIOThread> threads; 514 ScopedVector<TestIOThread> threads;
491 ScopedVector<MockDumpProvider> mdps; 515 ScopedVector<MockDumpProvider> mdps;
492 516
493 for (int i = 0; i < 2; i++) { 517 for (int i = 0; i < 2; i++) {
494 threads.push_back(new TestIOThread(TestIOThread::kAutoStart)); 518 threads.push_back(new TestIOThread(TestIOThread::kAutoStart));
495 mdps.push_back(new MockDumpProvider(threads.back()->task_runner())); 519 mdps.push_back(new MockDumpProvider(threads.back()->task_runner()));
520 EnableRegistrations();
496 mdm_->RegisterDumpProvider(mdps.back(), threads.back()->task_runner()); 521 mdm_->RegisterDumpProvider(mdps.back(), threads.back()->task_runner());
522 DisableRegistrations();
497 } 523 }
498 524
499 int on_memory_dump_call_count = 0; 525 int on_memory_dump_call_count = 0;
500 RunLoop run_loop; 526 RunLoop run_loop;
501 527
502 // When OnMemoryDump is called on either of the dump providers, it will 528 // When OnMemoryDump is called on either of the dump providers, it will
503 // unregister the other one. 529 // unregister the other one.
504 for (MockDumpProvider* mdp : mdps) { 530 for (MockDumpProvider* mdp : mdps) {
505 int other_idx = (mdps.front() == mdp); 531 int other_idx = (mdps.front() == mdp);
506 TestIOThread* other_thread = threads[other_idx]; 532 TestIOThread* other_thread = threads[other_idx];
(...skipping 30 matching lines...) Expand all
537 ASSERT_EQ(true, last_callback_success_); 563 ASSERT_EQ(true, last_callback_success_);
538 564
539 DisableTracing(); 565 DisableTracing();
540 } 566 }
541 567
542 // Ensures that a NACK callback is invoked if RequestGlobalDump is called when 568 // Ensures that a NACK callback is invoked if RequestGlobalDump is called when
543 // tracing is not enabled. 569 // tracing is not enabled.
544 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { 570 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) {
545 MockDumpProvider mdp1; 571 MockDumpProvider mdp1;
546 572
573 EnableRegistrations();
547 mdm_->RegisterDumpProvider(&mdp1); 574 mdm_->RegisterDumpProvider(&mdp1);
548 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); 575 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0);
549 576
550 last_callback_success_ = true; 577 last_callback_success_ = true;
551 { 578 {
552 RunLoop run_loop; 579 RunLoop run_loop;
553 MemoryDumpCallback callback = 580 MemoryDumpCallback callback =
554 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 581 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
555 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 582 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
556 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 583 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
557 high_detail_args, callback); 584 high_detail_args, callback);
558 run_loop.Run(); 585 run_loop.Run();
559 } 586 }
560 EXPECT_FALSE(last_callback_success_); 587 EXPECT_FALSE(last_callback_success_);
561 } 588 }
562 589
563 } // namespace trace_event 590 } // namespace trace_event
564 } // namespace base 591 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698