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

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

Powered by Google App Engine
This is Rietveld 408576698