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

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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return MemoryDumpManager::kInvalidTracingProcessId; 107 return MemoryDumpManager::kInvalidTracingProcessId;
108 } 108 }
109 109
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,
Primiano Tucci (use gerrit) 2016/04/13 17:08:41 Nothing in this test is checking that the session_
kraynov 2016/04/13 17:17:41 Acknowledged.
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 ~MockMemoryDumpProvider() override { 121 ~MockMemoryDumpProvider() override {
122 if (enable_mock_destructor) 122 if (enable_mock_destructor)
123 Destructor(); 123 Destructor();
124 } 124 }
125 125
126 bool enable_mock_destructor; 126 bool enable_mock_destructor;
127 }; 127 };
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 931
932 EXPECT_FALSE(last_callback_success_); 932 EXPECT_FALSE(last_callback_success_);
933 } 933 }
934 934
935 // Tests against race conditions that can happen if tracing is disabled before 935 // Tests against race conditions that can happen if tracing is disabled before
936 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 . 936 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 .
937 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) { 937 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) {
938 base::WaitableEvent tracing_disabled_event(false, false); 938 base::WaitableEvent tracing_disabled_event(false, false);
939 InitializeMemoryDumpManager(false /* is_coordinator */); 939 InitializeMemoryDumpManager(false /* is_coordinator */);
940 940
941 auto thread = WrapUnique(new Thread("test thread"));
Primiano Tucci (use gerrit) 2016/04/13 17:08:41 I think we don't allow yet auto with WrapUnique.
kraynov 2016/04/13 17:17:41 Acknowledged.
942 thread->Start();
943
941 MockMemoryDumpProvider mdp; 944 MockMemoryDumpProvider mdp;
942 RegisterDumpProvider(&mdp); 945 RegisterDumpProvider(&mdp, thread->task_runner(), kDefaultOptions);
Primiano Tucci (use gerrit) 2016/04/13 17:08:41 hmm here you are overriding the previous behavior.
kraynov 2016/04/13 17:17:41 Acknowledged.
943 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 946 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
944 947
945 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)) 948 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _))
946 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args, 949 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args,
947 const MemoryDumpCallback& callback) { 950 const MemoryDumpCallback& callback) {
948 DisableTracing(); 951 DisableTracing();
949 delegate_->CreateProcessDump(args, callback); 952 delegate_->CreateProcessDump(args, callback);
950 })); 953 }));
951 954
955 // If tracing is disabled for current session CreateProcessDump() should NOT
956 // request dumps from providers. Real-world regression: crbug.com/600570 .
957 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
958
952 last_callback_success_ = true; 959 last_callback_success_ = true;
953 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 960 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
954 MemoryDumpLevelOfDetail::DETAILED); 961 MemoryDumpLevelOfDetail::DETAILED);
955 EXPECT_FALSE(last_callback_success_); 962 EXPECT_FALSE(last_callback_success_);
956 } 963 }
957 964
958 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) { 965 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) {
959 using trace_analyzer::Query; 966 using trace_analyzer::Query;
960 967
961 InitializeMemoryDumpManager(false /* is_coordinator */); 968 InitializeMemoryDumpManager(false /* is_coordinator */);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); 1080 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2);
1074 for (int i = 0; i < 2; ++i) { 1081 for (int i = 0; i < 2; ++i) {
1075 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 1082 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
1076 MemoryDumpLevelOfDetail::DETAILED); 1083 MemoryDumpLevelOfDetail::DETAILED);
1077 } 1084 }
1078 DisableTracing(); 1085 DisableTracing();
1079 } 1086 }
1080 1087
1081 } // namespace trace_event 1088 } // namespace trace_event
1082 } // namespace base 1089 } // 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