Index: base/trace_event/memory_dump_manager_unittest.cc |
diff --git a/base/trace_event/memory_dump_manager_unittest.cc b/base/trace_event/memory_dump_manager_unittest.cc |
index d90b7c6073563ba4d1bdab0250b2f78e9381f861..53c7d9250dab441711846adb0585bc2c0ed72819 100644 |
--- a/base/trace_event/memory_dump_manager_unittest.cc |
+++ b/base/trace_event/memory_dump_manager_unittest.cc |
@@ -8,6 +8,7 @@ |
#include "base/memory/scoped_vector.h" |
#include "base/message_loop/message_loop.h" |
#include "base/run_loop.h" |
+#include "base/thread_task_runner_handle.h" |
#include "base/threading/thread.h" |
#include "base/trace_event/memory_dump_provider.h" |
#include "base/trace_event/process_memory_dump.h" |
@@ -15,6 +16,7 @@ |
#include "testing/gtest/include/gtest/gtest.h" |
using testing::_; |
+using testing::Between; |
using testing::Invoke; |
using testing::Return; |
@@ -25,9 +27,8 @@ namespace trace_event { |
// instead of performing IPC dances. |
class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { |
public: |
- void RequestGlobalMemoryDump( |
- const base::trace_event::MemoryDumpRequestArgs& args, |
- const MemoryDumpCallback& callback) override { |
+ void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, |
+ const MemoryDumpCallback& callback) override { |
CreateProcessDump(args, callback); |
} |
@@ -81,7 +82,9 @@ class MemoryDumpManagerTest : public testing::Test { |
class MockDumpProvider : public MemoryDumpProvider { |
public: |
- MockDumpProvider() : last_session_state_(nullptr) {} |
+ MockDumpProvider() |
+ : dump_provider_to_register_or_unregister(nullptr), |
+ last_session_state_(nullptr) {} |
// Ctor used by the RespectTaskRunnerAffinity test. |
explicit MockDumpProvider( |
@@ -107,6 +110,23 @@ class MockDumpProvider : public MemoryDumpProvider { |
return true; |
} |
+ // OnMemoryDump() override for the RegisterDumperWhileDumping test. |
+ bool OnMemoryDump_RegisterExtraDumpProvider(ProcessMemoryDump* pmd) { |
+ MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
+ dump_provider_to_register_or_unregister); |
+ return true; |
+ } |
+ |
+ // OnMemoryDump() override for the UnegisterDumperWhileDumping test. |
+ bool OnMemoryDump_UnregisterDumpProvider(ProcessMemoryDump* pmd) { |
+ MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
+ dump_provider_to_register_or_unregister); |
+ return true; |
+ } |
+ |
+ // Used by OnMemoryDump_(Un)RegisterExtraDumpProvider. |
+ MemoryDumpProvider* dump_provider_to_register_or_unregister; |
+ |
private: |
MemoryDumpSessionState* last_session_state_; |
scoped_refptr<SingleThreadTaskRunner> task_runner_; |
@@ -263,6 +283,7 @@ TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { |
EXPECT_CALL(mdp1, OnMemoryDump(_)) |
.Times(MemoryDumpManager::kMaxConsecutiveFailuresCount) |
.WillRepeatedly(Return(false)); |
+ |
EXPECT_CALL(mdp2, OnMemoryDump(_)) |
.Times(1 + MemoryDumpManager::kMaxConsecutiveFailuresCount) |
.WillOnce(Return(false)) |
@@ -275,5 +296,65 @@ TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { |
DisableTracing(); |
} |
+// Sneakily register an extra memory dump provider while an existing one is |
+// dumping and expect it to take part in the already active tracing session. |
+TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { |
+ MockDumpProvider mdp1; |
+ MockDumpProvider mdp2; |
+ |
+ mdp1.dump_provider_to_register_or_unregister = &mdp2; |
+ mdm_->RegisterDumpProvider(&mdp1); |
+ EnableTracing(kTraceCategory); |
+ |
+ EXPECT_CALL(mdp1, OnMemoryDump(_)) |
+ .Times(4) |
+ .WillOnce(Return(true)) |
+ .WillOnce(Invoke( |
+ &mdp1, &MockDumpProvider::OnMemoryDump_RegisterExtraDumpProvider)) |
+ .WillRepeatedly(Return(true)); |
+ |
+ // Depending on the insertion order (before or after mdp1), mdp2 might be |
+ // called also immediately after it gets registered. |
+ EXPECT_CALL(mdp2, OnMemoryDump(_)) |
+ .Times(Between(2, 3)) |
+ .WillRepeatedly(Return(true)); |
+ |
+ for (int i = 0; i < 4; i++) { |
+ mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); |
+ } |
+ |
+ DisableTracing(); |
+} |
+ |
+// Like the above, but suddenly unregister the dump provider. |
+TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { |
+ MockDumpProvider mdp1; |
+ MockDumpProvider mdp2; |
+ |
+ mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); |
+ mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); |
+ mdp1.dump_provider_to_register_or_unregister = &mdp2; |
+ EnableTracing(kTraceCategory); |
+ |
+ EXPECT_CALL(mdp1, OnMemoryDump(_)) |
+ .Times(4) |
+ .WillOnce(Return(true)) |
+ .WillOnce(Invoke(&mdp1, |
+ &MockDumpProvider::OnMemoryDump_UnregisterDumpProvider)) |
+ .WillRepeatedly(Return(true)); |
+ |
+ // Depending on the insertion order (before or after mdp1), mdp2 might have |
+ // been already called when OnMemoryDump_UnregisterDumpProvider happens. |
+ EXPECT_CALL(mdp2, OnMemoryDump(_)) |
+ .Times(Between(1, 2)) |
+ .WillRepeatedly(Return(true)); |
+ |
+ for (int i = 0; i < 4; i++) { |
+ mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); |
+ } |
+ |
+ DisableTracing(); |
+} |
+ |
} // namespace trace_event |
} // namespace base |