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

Side by Side Diff: base/debug/trace_event_win_unittest.cc

Issue 3945002: Move debug-related stuff from base to the base/debug directory and use the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « base/debug/trace_event_win.cc ('k') | base/debug_on_start.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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.h" 5 #include "base/debug/trace_event.h"
6 6
7 #include <strstream> 7 #include <strstream>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/event_trace_consumer_win.h" 12 #include "base/event_trace_consumer_win.h"
13 #include "base/event_trace_controller_win.h" 13 #include "base/event_trace_controller_win.h"
14 #include "base/win/windows_version.h" 14 #include "base/win/windows_version.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include <initguid.h> // NOLINT - must be last include. 17 #include <initguid.h> // NOLINT - must be last include.
18 18
19 namespace base {
20 namespace debug {
21
19 namespace { 22 namespace {
23
20 using testing::_; 24 using testing::_;
21 using testing::AnyNumber; 25 using testing::AnyNumber;
22 using testing::InSequence; 26 using testing::InSequence;
23 using testing::Ge; 27 using testing::Ge;
24 using testing::Le; 28 using testing::Le;
25 using testing::NotNull; 29 using testing::NotNull;
26 30
27 // Data for unittests traces. 31 // Data for unittests traces.
28 const char kEmpty[] = ""; 32 const char kEmpty[] = "";
29 const char kName[] = "unittest.trace_name"; 33 const char kName[] = "unittest.trace_name";
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 }; 78 };
75 79
76 TestEventConsumer* TestEventConsumer::current_ = NULL; 80 TestEventConsumer* TestEventConsumer::current_ = NULL;
77 81
78 class TraceEventTest: public testing::Test { 82 class TraceEventTest: public testing::Test {
79 public: 83 public:
80 TraceEventTest() { 84 TraceEventTest() {
81 } 85 }
82 86
83 void SetUp() { 87 void SetUp() {
84 bool is_xp = base::win::GetVersion() < base::win::VERSION_VISTA; 88 bool is_xp = win::GetVersion() < base::win::VERSION_VISTA;
85 89
86 if (is_xp) { 90 if (is_xp) {
87 // Tear down any dangling session from an earlier failing test. 91 // Tear down any dangling session from an earlier failing test.
88 EtwTraceProperties ignore; 92 EtwTraceProperties ignore;
89 EtwTraceController::Stop(kTestSessionName, &ignore); 93 EtwTraceController::Stop(kTestSessionName, &ignore);
90 } 94 }
91 95
92 // Resurrect and initialize the TraceLog singleton instance. 96 // Resurrect and initialize the TraceLog singleton instance.
93 // On Vista and better, we need the provider registered before we 97 // On Vista and better, we need the provider registered before we
94 // start the private, in-proc session, but on XP we need the global 98 // start the private, in-proc session, but on XP we need the global
95 // session created and the provider enabled before we register our 99 // session created and the provider enabled before we register our
96 // provider. 100 // provider.
97 base::TraceLog* tracelog = NULL; 101 TraceLog* tracelog = NULL;
98 if (!is_xp) { 102 if (!is_xp) {
99 base::TraceLog::Resurrect(); 103 TraceLog::Resurrect();
100 tracelog = base::TraceLog::Get(); 104 tracelog = TraceLog::Get();
101 ASSERT_TRUE(tracelog != NULL); 105 ASSERT_TRUE(tracelog != NULL);
102 ASSERT_FALSE(tracelog->IsTracing()); 106 ASSERT_FALSE(tracelog->IsTracing());
103 } 107 }
104 108
105 // Create the log file. 109 // Create the log file.
106 ASSERT_TRUE(file_util::CreateTemporaryFile(&log_file_)); 110 ASSERT_TRUE(file_util::CreateTemporaryFile(&log_file_));
107 111
108 // Create a private log session on the file. 112 // Create a private log session on the file.
109 EtwTraceProperties prop; 113 EtwTraceProperties prop;
110 ASSERT_HRESULT_SUCCEEDED(prop.SetLoggerFileName(log_file_.value().c_str())); 114 ASSERT_HRESULT_SUCCEEDED(prop.SetLoggerFileName(log_file_.value().c_str()));
111 EVENT_TRACE_PROPERTIES& p = *prop.get(); 115 EVENT_TRACE_PROPERTIES& p = *prop.get();
112 p.Wnode.ClientContext = 1; // QPC timer accuracy. 116 p.Wnode.ClientContext = 1; // QPC timer accuracy.
113 p.LogFileMode = EVENT_TRACE_FILE_MODE_SEQUENTIAL; // Sequential log. 117 p.LogFileMode = EVENT_TRACE_FILE_MODE_SEQUENTIAL; // Sequential log.
114 118
115 // On Vista and later, we create a private in-process log session, because 119 // On Vista and later, we create a private in-process log session, because
116 // otherwise we'd need administrator privileges. Unfortunately we can't 120 // otherwise we'd need administrator privileges. Unfortunately we can't
117 // do the same on XP and better, because the semantics of a private 121 // do the same on XP and better, because the semantics of a private
118 // logger session are different, and the IN_PROC flag is not supported. 122 // logger session are different, and the IN_PROC flag is not supported.
119 if (!is_xp) { 123 if (!is_xp) {
120 p.LogFileMode |= EVENT_TRACE_PRIVATE_IN_PROC | // In-proc for non-admin. 124 p.LogFileMode |= EVENT_TRACE_PRIVATE_IN_PROC | // In-proc for non-admin.
121 EVENT_TRACE_PRIVATE_LOGGER_MODE; // Process-private log. 125 EVENT_TRACE_PRIVATE_LOGGER_MODE; // Process-private log.
122 } 126 }
123 127
124 p.MaximumFileSize = 100; // 100M file size. 128 p.MaximumFileSize = 100; // 100M file size.
125 p.FlushTimer = 1; // 1 second flush lag. 129 p.FlushTimer = 1; // 1 second flush lag.
126 ASSERT_HRESULT_SUCCEEDED(controller_.Start(kTestSessionName, &prop)); 130 ASSERT_HRESULT_SUCCEEDED(controller_.Start(kTestSessionName, &prop));
127 131
128 // Enable the TraceLog provider GUID. 132 // Enable the TraceLog provider GUID.
129 ASSERT_HRESULT_SUCCEEDED( 133 ASSERT_HRESULT_SUCCEEDED(
130 controller_.EnableProvider(base::kChromeTraceProviderName, 134 controller_.EnableProvider(kChromeTraceProviderName,
131 TRACE_LEVEL_INFORMATION, 135 TRACE_LEVEL_INFORMATION,
132 0)); 136 0));
133 137
134 if (is_xp) { 138 if (is_xp) {
135 base::TraceLog::Resurrect(); 139 TraceLog::Resurrect();
136 tracelog = base::TraceLog::Get(); 140 tracelog = TraceLog::Get();
137 } 141 }
138 ASSERT_TRUE(tracelog != NULL); 142 ASSERT_TRUE(tracelog != NULL);
139 EXPECT_TRUE(tracelog->IsTracing()); 143 EXPECT_TRUE(tracelog->IsTracing());
140 } 144 }
141 145
142 void TearDown() { 146 void TearDown() {
143 EtwTraceProperties prop; 147 EtwTraceProperties prop;
144 if (controller_.session() != 0) 148 if (controller_.session() != 0)
145 EXPECT_HRESULT_SUCCEEDED(controller_.Stop(&prop)); 149 EXPECT_HRESULT_SUCCEEDED(controller_.Stop(&prop));
146 150
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 EXPECT_HRESULT_SUCCEEDED(controller_.Flush(&prop)); 183 EXPECT_HRESULT_SUCCEEDED(controller_.Flush(&prop));
180 EXPECT_HRESULT_SUCCEEDED(controller_.Stop(&prop)); 184 EXPECT_HRESULT_SUCCEEDED(controller_.Stop(&prop));
181 ASSERT_HRESULT_SUCCEEDED( 185 ASSERT_HRESULT_SUCCEEDED(
182 consumer_.OpenFileSession(log_file_.value().c_str())); 186 consumer_.OpenFileSession(log_file_.value().c_str()));
183 187
184 ASSERT_HRESULT_SUCCEEDED(consumer_.Consume()); 188 ASSERT_HRESULT_SUCCEEDED(consumer_.Consume());
185 } 189 }
186 190
187 private: 191 private:
188 // We want our singleton torn down after each test. 192 // We want our singleton torn down after each test.
189 base::ShadowingAtExitManager at_exit_manager_; 193 ShadowingAtExitManager at_exit_manager_;
190 EtwTraceController controller_; 194 EtwTraceController controller_;
191 FilePath log_file_; 195 FilePath log_file_;
192 TestEventConsumer consumer_; 196 TestEventConsumer consumer_;
193 }; 197 };
194 198
195 } // namespace 199 } // namespace
196 200
197 201
198 TEST_F(TraceEventTest, TraceLog) { 202 TEST_F(TraceEventTest, TraceLog) {
199 ExpectPlayLog(); 203 ExpectPlayLog();
200 204
201 // The events should arrive in the same sequence as the expects. 205 // The events should arrive in the same sequence as the expects.
202 InSequence in_sequence; 206 InSequence in_sequence;
203 207
204 // Full argument version, passing lengths explicitly. 208 // Full argument version, passing lengths explicitly.
205 base::TraceLog::Trace(kName, 209 TraceLog::Trace(kName,
206 strlen(kName), 210 strlen(kName),
207 base::TraceLog::EVENT_BEGIN, 211 TraceLog::EVENT_BEGIN,
208 kId, 212 kId,
209 kExtra, 213 kExtra,
210 strlen(kExtra)); 214 strlen(kExtra));
211 215
212 ExpectEvent(base::kTraceEventClass32, 216 ExpectEvent(kTraceEventClass32,
213 base::kTraceEventTypeBegin, 217 kTraceEventTypeBegin,
214 kName, strlen(kName), 218 kName, strlen(kName),
215 kId, 219 kId,
216 kExtra, strlen(kExtra)); 220 kExtra, strlen(kExtra));
217 221
218 // Const char* version. 222 // Const char* version.
219 base::TraceLog::Trace(static_cast<const char*>(kName), 223 TraceLog::Trace(static_cast<const char*>(kName),
220 base::TraceLog::EVENT_END, 224 TraceLog::EVENT_END,
221 kId, 225 kId,
222 static_cast<const char*>(kExtra)); 226 static_cast<const char*>(kExtra));
223 227
224 ExpectEvent(base::kTraceEventClass32, 228 ExpectEvent(kTraceEventClass32,
225 base::kTraceEventTypeEnd, 229 kTraceEventTypeEnd,
226 kName, strlen(kName), 230 kName, strlen(kName),
227 kId, 231 kId,
228 kExtra, strlen(kExtra)); 232 kExtra, strlen(kExtra));
229 233
230 // std::string extra version. 234 // std::string extra version.
231 base::TraceLog::Trace(static_cast<const char*>(kName), 235 TraceLog::Trace(static_cast<const char*>(kName),
232 base::TraceLog::EVENT_INSTANT, 236 TraceLog::EVENT_INSTANT,
233 kId, 237 kId,
234 std::string(kExtra)); 238 std::string(kExtra));
235 239
236 ExpectEvent(base::kTraceEventClass32, 240 ExpectEvent(kTraceEventClass32,
237 base::kTraceEventTypeInstant, 241 kTraceEventTypeInstant,
238 kName, strlen(kName), 242 kName, strlen(kName),
239 kId, 243 kId,
240 kExtra, strlen(kExtra)); 244 kExtra, strlen(kExtra));
241 245
242 246
243 // Test for sanity on NULL inputs. 247 // Test for sanity on NULL inputs.
244 base::TraceLog::Trace(NULL, 248 TraceLog::Trace(NULL,
245 0, 249 0,
246 base::TraceLog::EVENT_BEGIN, 250 TraceLog::EVENT_BEGIN,
247 kId, 251 kId,
248 NULL, 252 NULL,
249 0); 253 0);
250 254
251 ExpectEvent(base::kTraceEventClass32, 255 ExpectEvent(kTraceEventClass32,
252 base::kTraceEventTypeBegin, 256 kTraceEventTypeBegin,
253 kEmpty, 0, 257 kEmpty, 0,
254 kId, 258 kId,
255 kEmpty, 0); 259 kEmpty, 0);
256 260
257 base::TraceLog::Trace(NULL, 261 TraceLog::Trace(NULL,
258 -1, 262 -1,
259 base::TraceLog::EVENT_END, 263 TraceLog::EVENT_END,
260 kId, 264 kId,
261 NULL, 265 NULL,
262 -1); 266 -1);
263 267
264 ExpectEvent(base::kTraceEventClass32, 268 ExpectEvent(kTraceEventClass32,
265 base::kTraceEventTypeEnd, 269 kTraceEventTypeEnd,
266 kEmpty, 0, 270 kEmpty, 0,
267 kId, 271 kId,
268 kEmpty, 0); 272 kEmpty, 0);
269 273
270 PlayLog(); 274 PlayLog();
271 } 275 }
272 276
273 TEST_F(TraceEventTest, Macros) { 277 TEST_F(TraceEventTest, Macros) {
274 ExpectPlayLog(); 278 ExpectPlayLog();
275 279
276 // The events should arrive in the same sequence as the expects. 280 // The events should arrive in the same sequence as the expects.
277 InSequence in_sequence; 281 InSequence in_sequence;
278 282
279 TRACE_EVENT_BEGIN(kName, kId, kExtra); 283 TRACE_EVENT_BEGIN(kName, kId, kExtra);
280 ExpectEvent(base::kTraceEventClass32, 284 ExpectEvent(kTraceEventClass32,
281 base::kTraceEventTypeBegin, 285 kTraceEventTypeBegin,
282 kName, strlen(kName), 286 kName, strlen(kName),
283 kId, 287 kId,
284 kExtra, strlen(kExtra)); 288 kExtra, strlen(kExtra));
285 289
286 TRACE_EVENT_END(kName, kId, kExtra); 290 TRACE_EVENT_END(kName, kId, kExtra);
287 ExpectEvent(base::kTraceEventClass32, 291 ExpectEvent(kTraceEventClass32,
288 base::kTraceEventTypeEnd, 292 kTraceEventTypeEnd,
289 kName, strlen(kName), 293 kName, strlen(kName),
290 kId, 294 kId,
291 kExtra, strlen(kExtra)); 295 kExtra, strlen(kExtra));
292 296
293 TRACE_EVENT_INSTANT(kName, kId, kExtra); 297 TRACE_EVENT_INSTANT(kName, kId, kExtra);
294 ExpectEvent(base::kTraceEventClass32, 298 ExpectEvent(kTraceEventClass32,
295 base::kTraceEventTypeInstant, 299 kTraceEventTypeInstant,
296 kName, strlen(kName), 300 kName, strlen(kName),
297 kId, 301 kId,
298 kExtra, strlen(kExtra)); 302 kExtra, strlen(kExtra));
299 303
300 PlayLog(); 304 PlayLog();
301 } 305 }
306
307 } // namespace debug
308 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/trace_event_win.cc ('k') | base/debug_on_start.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698