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

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

Issue 1884573002: Fix race condition when dump providers invoked within destroyed state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Promote the CreateProcessDump to public so it can be used by test fixtures. 110 // Promote the CreateProcessDump to public so it can be used by test fixtures.
111 using MemoryDumpManagerDelegate::CreateProcessDump; 111 using MemoryDumpManagerDelegate::CreateProcessDump;
112 }; 112 };
113 113
114 class MockMemoryDumpProvider : public MemoryDumpProvider { 114 class MockMemoryDumpProvider : public MemoryDumpProvider {
115 public: 115 public:
116 MOCK_METHOD0(Destructor, void()); 116 MOCK_METHOD0(Destructor, void());
117 MOCK_METHOD2(OnMemoryDump, 117 MOCK_METHOD2(OnMemoryDump,
118 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd)); 118 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd));
119 119
120 MockMemoryDumpProvider() : enable_mock_destructor(false) {} 120 MockMemoryDumpProvider() : enable_mock_destructor(false) {
121 ON_CALL(*this, OnMemoryDump(_, _))
122 .WillByDefault(Invoke([](const MemoryDumpArgs&,
123 ProcessMemoryDump* pmd) -> bool {
124 EXPECT_TRUE(pmd->session_state().get() != nullptr);
Primiano Tucci (use gerrit) 2016/04/13 20:19:16 Plz add a comment here explaining that under no ci
125 return true;
126 }));
127 }
121 ~MockMemoryDumpProvider() override { 128 ~MockMemoryDumpProvider() override {
122 if (enable_mock_destructor) 129 if (enable_mock_destructor)
123 Destructor(); 130 Destructor();
124 } 131 }
125 132
126 bool enable_mock_destructor; 133 bool enable_mock_destructor;
127 }; 134 };
128 135
129 class TestSequencedTaskRunner : public SequencedTaskRunner { 136 class TestSequencedTaskRunner : public SequencedTaskRunner {
130 public: 137 public:
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 938
932 EXPECT_FALSE(last_callback_success_); 939 EXPECT_FALSE(last_callback_success_);
933 } 940 }
934 941
935 // Tests against race conditions that can happen if tracing is disabled before 942 // Tests against race conditions that can happen if tracing is disabled before
936 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 . 943 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 .
937 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) { 944 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) {
938 base::WaitableEvent tracing_disabled_event(false, false); 945 base::WaitableEvent tracing_disabled_event(false, false);
939 InitializeMemoryDumpManager(false /* is_coordinator */); 946 InitializeMemoryDumpManager(false /* is_coordinator */);
940 947
941 MockMemoryDumpProvider mdp; 948 std::unique_ptr<Thread> thread = WrapUnique(new Thread("test thread"));
Primiano Tucci (use gerrit) 2016/04/13 20:19:16 as commented before, this WrapUnique is unnecessar
Primiano Tucci (use gerrit) 2016/04/13 20:19:16 s/thread/mdp_thread/ for consistency with the code
942 RegisterDumpProvider(&mdp); 949 thread->Start();
950
951 // Create both same-thread MDP and another MDP with dedicated thread
952 MockMemoryDumpProvider mdp1;
953 RegisterDumpProvider(&mdp1);
954 MockMemoryDumpProvider mdp2;
955 RegisterDumpProvider(&mdp2, thread->task_runner(), kDefaultOptions);
943 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 956 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
944 957
945 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)) 958 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _))
946 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args, 959 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args,
947 const MemoryDumpCallback& callback) { 960 const MemoryDumpCallback& callback) {
948 DisableTracing(); 961 DisableTracing();
949 delegate_->CreateProcessDump(args, callback); 962 delegate_->CreateProcessDump(args, callback);
950 })); 963 }));
951 964
965 // If tracing is disabled for current session CreateProcessDump() should NOT
966 // request dumps from providers. Real-world regression: crbug.com/600570 .
967 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0);
968 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0);
969
952 last_callback_success_ = true; 970 last_callback_success_ = true;
953 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 971 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
954 MemoryDumpLevelOfDetail::DETAILED); 972 MemoryDumpLevelOfDetail::DETAILED);
955 EXPECT_FALSE(last_callback_success_); 973 EXPECT_FALSE(last_callback_success_);
956 } 974 }
957 975
958 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) { 976 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) {
959 using trace_analyzer::Query; 977 using trace_analyzer::Query;
960 978
961 InitializeMemoryDumpManager(false /* is_coordinator */); 979 InitializeMemoryDumpManager(false /* is_coordinator */);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); 1091 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2);
1074 for (int i = 0; i < 2; ++i) { 1092 for (int i = 0; i < 2; ++i) {
1075 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 1093 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
1076 MemoryDumpLevelOfDetail::DETAILED); 1094 MemoryDumpLevelOfDetail::DETAILED);
1077 } 1095 }
1078 DisableTracing(); 1096 DisableTracing();
1079 } 1097 }
1080 1098
1081 } // namespace trace_event 1099 } // namespace trace_event
1082 } // namespace base 1100 } // namespace base
OLDNEW
« base/trace_event/memory_dump_manager.cc ('K') | « base/trace_event/memory_dump_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698