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

Unified Diff: base/trace_event/memory_dump_manager_unittest.cc

Issue 1222153004: [tracing] Simplify and improve thread-hopping logic of memory-infra (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re dsinclair #7 Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | content/browser/tracing/tracing_controller_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | content/browser/tracing/tracing_controller_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698