OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/bind.h" | |
6 #include "base/test/trace_event_analyzer.h" | |
7 #include "testing/gmock/include/gmock/gmock.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace trace_analyzer { | |
11 | |
12 namespace { | |
13 | |
14 class TraceEventAnalyzerTest : public testing::Test { | |
15 public: | |
16 void ManualSetUp(); | |
17 void OnTraceDataCollected( | |
18 scoped_refptr<base::debug::TraceLog::RefCountedString> json_events_str); | |
19 void BeginTracing(); | |
20 void EndTracing(); | |
21 | |
22 base::debug::TraceResultBuffer::SimpleOutput output_; | |
23 base::debug::TraceResultBuffer buffer_; | |
24 }; | |
25 | |
26 void TraceEventAnalyzerTest::ManualSetUp() { | |
27 base::debug::TraceLog::Resurrect(); | |
28 base::debug::TraceLog* tracelog = base::debug::TraceLog::GetInstance(); | |
29 ASSERT_TRUE(tracelog); | |
30 tracelog->SetOutputCallback( | |
31 base::Bind(&TraceEventAnalyzerTest::OnTraceDataCollected, | |
32 base::Unretained(this))); | |
33 buffer_.SetOutputCallback(output_.GetCallback()); | |
34 output_.json_output.clear(); | |
35 } | |
36 | |
37 void TraceEventAnalyzerTest::OnTraceDataCollected( | |
38 scoped_refptr<base::debug::TraceLog::RefCountedString> json_events_str) { | |
39 buffer_.AddFragment(json_events_str->data); | |
40 } | |
41 | |
42 void TraceEventAnalyzerTest::BeginTracing() { | |
43 output_.json_output.clear(); | |
44 buffer_.Start(); | |
45 base::debug::TraceLog::GetInstance()->SetEnabled(true); | |
46 } | |
47 | |
48 void TraceEventAnalyzerTest::EndTracing() { | |
49 base::debug::TraceLog::GetInstance()->SetEnabled(false); | |
50 buffer_.Finish(); | |
51 } | |
52 | |
53 } // namespace | |
54 | |
55 TEST_F(TraceEventAnalyzerTest, NoEvents) { | |
56 using namespace trace_analyzer; | |
57 ManualSetUp(); | |
58 | |
59 // Create an empty JSON event string: | |
60 buffer_.Start(); | |
61 buffer_.Finish(); | |
62 | |
63 scoped_ptr<TraceAnalyzer> | |
64 analyzer(TraceAnalyzer::Create(output_.json_output)); | |
65 ASSERT_TRUE(analyzer.get()); | |
66 | |
67 // Search for all events and verify that nothing is returned. | |
68 TraceAnalyzer::TraceEventVector found; | |
69 analyzer->FindEvents(Query::Bool(true), &found); | |
70 EXPECT_EQ(0u, found.size()); | |
71 } | |
72 | |
73 TEST_F(TraceEventAnalyzerTest, QueryEventMember) { | |
74 using namespace trace_analyzer; | |
75 ManualSetUp(); | |
76 | |
77 TraceEvent event; | |
78 event.thread.process_id = 3; | |
79 event.thread.thread_id = 4; | |
80 event.timestamp = 1.5; | |
81 event.phase = base::debug::TRACE_EVENT_PHASE_BEGIN; | |
82 event.category = "category"; | |
83 event.name = "name"; | |
84 event.arg_numbers["num"] = 7.0; | |
85 event.arg_strings["str"] = "the string"; | |
86 | |
87 // Other event with all different members: | |
88 TraceEvent other; | |
89 other.thread.process_id = 5; | |
90 other.thread.thread_id = 6; | |
91 other.timestamp = 2.5; | |
92 other.phase = base::debug::TRACE_EVENT_PHASE_END; | |
93 other.category = "category2"; | |
94 other.name = "name2"; | |
95 other.arg_numbers["num2"] = 8.0; | |
96 other.arg_strings["str2"] = "the string 2"; | |
97 | |
98 event.other_event = &other; | |
99 double duration; | |
100 ASSERT_TRUE(event.GetAbsTimeToOtherEvent(&duration)); | |
101 | |
102 Query event_pid = (Query(EVENT_PID) == Query::Int(event.thread.process_id)); | |
103 Query event_tid = (Query(EVENT_TID) == Query::Int(event.thread.thread_id)); | |
104 Query event_time = (Query(EVENT_TIME) == Query::Double(event.timestamp)); | |
105 Query event_duration = (Query(EVENT_DURATION) == Query::Double(duration)); | |
106 Query event_phase = (Query(EVENT_PHASE) == Query::Phase(event.phase)); | |
107 Query event_category = | |
108 (Query(EVENT_CATEGORY) == Query::String(event.category)); | |
109 Query event_name = (Query(EVENT_NAME) == Query::String(event.name)); | |
110 Query event_has_arg1 = Query(EVENT_HAS_ARG, "num"); | |
111 Query event_has_arg2 = Query(EVENT_HAS_ARG, "str"); | |
112 Query event_arg1 = | |
113 (Query(EVENT_ARG, "num") == Query::Double(event.arg_numbers["num"])); | |
114 Query event_arg2 = | |
115 (Query(EVENT_ARG, "str") == Query::String(event.arg_strings["str"])); | |
116 Query event_has_other = Query(EVENT_HAS_OTHER); | |
117 Query other_pid = (Query(OTHER_PID) == Query::Int(other.thread.process_id)); | |
118 Query other_tid = (Query(OTHER_TID) == Query::Int(other.thread.thread_id)); | |
119 Query other_time = (Query(OTHER_TIME) == Query::Double(other.timestamp)); | |
120 Query other_phase = (Query(OTHER_PHASE) == Query::Phase(other.phase)); | |
121 Query other_category = | |
122 (Query(OTHER_CATEGORY) == Query::String(other.category)); | |
123 Query other_name = (Query(OTHER_NAME) == Query::String(other.name)); | |
124 Query other_has_arg1 = Query(OTHER_HAS_ARG, "num2"); | |
125 Query other_has_arg2 = Query(OTHER_HAS_ARG, "str2"); | |
126 Query other_arg1 = | |
127 (Query(OTHER_ARG, "num2") == Query::Double(other.arg_numbers["num2"])); | |
128 Query other_arg2 = | |
129 (Query(OTHER_ARG, "str2") == Query::String(other.arg_strings["str2"])); | |
130 | |
131 EXPECT_TRUE(event_pid.Evaluate(event)); | |
132 EXPECT_TRUE(event_tid.Evaluate(event)); | |
133 EXPECT_TRUE(event_time.Evaluate(event)); | |
134 EXPECT_TRUE(event_duration.Evaluate(event)); | |
135 EXPECT_TRUE(event_phase.Evaluate(event)); | |
136 EXPECT_TRUE(event_category.Evaluate(event)); | |
137 EXPECT_TRUE(event_name.Evaluate(event)); | |
138 EXPECT_TRUE(event_has_arg1.Evaluate(event)); | |
139 EXPECT_TRUE(event_has_arg2.Evaluate(event)); | |
140 EXPECT_TRUE(event_arg1.Evaluate(event)); | |
141 EXPECT_TRUE(event_arg2.Evaluate(event)); | |
142 EXPECT_TRUE(event_has_other.Evaluate(event)); | |
143 EXPECT_TRUE(other_pid.Evaluate(event)); | |
144 EXPECT_TRUE(other_tid.Evaluate(event)); | |
145 EXPECT_TRUE(other_time.Evaluate(event)); | |
146 EXPECT_TRUE(other_phase.Evaluate(event)); | |
147 EXPECT_TRUE(other_category.Evaluate(event)); | |
148 EXPECT_TRUE(other_name.Evaluate(event)); | |
149 EXPECT_TRUE(other_has_arg1.Evaluate(event)); | |
150 EXPECT_TRUE(other_has_arg2.Evaluate(event)); | |
151 EXPECT_TRUE(other_arg1.Evaluate(event)); | |
152 EXPECT_TRUE(other_arg2.Evaluate(event)); | |
153 | |
154 // Evaluate event queries against other to verify the queries fail when the | |
155 // event members are wrong. | |
156 EXPECT_FALSE(event_pid.Evaluate(other)); | |
157 EXPECT_FALSE(event_tid.Evaluate(other)); | |
158 EXPECT_FALSE(event_time.Evaluate(other)); | |
159 EXPECT_FALSE(event_duration.Evaluate(other)); | |
160 EXPECT_FALSE(event_phase.Evaluate(other)); | |
161 EXPECT_FALSE(event_category.Evaluate(other)); | |
162 EXPECT_FALSE(event_name.Evaluate(other)); | |
163 EXPECT_FALSE(event_has_arg1.Evaluate(other)); | |
164 EXPECT_FALSE(event_has_arg2.Evaluate(other)); | |
165 EXPECT_FALSE(event_arg1.Evaluate(other)); | |
166 EXPECT_FALSE(event_arg2.Evaluate(other)); | |
167 EXPECT_FALSE(event_has_other.Evaluate(other)); | |
168 } | |
169 | |
170 TEST_F(TraceEventAnalyzerTest, BooleanOperators) { | |
171 using namespace trace_analyzer; | |
172 ManualSetUp(); | |
173 | |
174 BeginTracing(); | |
175 { | |
176 TRACE_EVENT_INSTANT1("cat1", "name1", "num", 1); | |
177 TRACE_EVENT_INSTANT1("cat1", "name2", "num", 2); | |
178 TRACE_EVENT_INSTANT1("cat2", "name3", "num", 3); | |
179 TRACE_EVENT_INSTANT1("cat2", "name4", "num", 4); | |
180 } | |
181 EndTracing(); | |
182 | |
183 scoped_ptr<TraceAnalyzer> | |
184 analyzer(TraceAnalyzer::Create(output_.json_output)); | |
185 ASSERT_TRUE(!!analyzer.get()); | |
186 | |
187 TraceAnalyzer::TraceEventVector found; | |
188 | |
189 // == | |
190 | |
191 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat1"), &found); | |
192 ASSERT_EQ(2u, found.size()); | |
193 EXPECT_STREQ("name1", found[0]->name.c_str()); | |
194 EXPECT_STREQ("name2", found[1]->name.c_str()); | |
195 | |
196 analyzer->FindEvents(Query(EVENT_ARG, "num") == Query::Int(2), &found); | |
197 ASSERT_EQ(1u, found.size()); | |
198 EXPECT_STREQ("name2", found[0]->name.c_str()); | |
199 | |
200 // != | |
201 | |
202 analyzer->FindEvents(Query(EVENT_CATEGORY) != Query::String("cat1"), &found); | |
203 ASSERT_EQ(2u, found.size()); | |
204 EXPECT_STREQ("name3", found[0]->name.c_str()); | |
205 EXPECT_STREQ("name4", found[1]->name.c_str()); | |
206 | |
207 analyzer->FindEvents(Query(EVENT_ARG, "num") != Query::Int(2), &found); | |
208 ASSERT_EQ(3u, found.size()); | |
209 EXPECT_STREQ("name1", found[0]->name.c_str()); | |
210 EXPECT_STREQ("name3", found[1]->name.c_str()); | |
211 EXPECT_STREQ("name4", found[2]->name.c_str()); | |
212 | |
213 // < | |
214 analyzer->FindEvents(Query(EVENT_ARG, "num") < Query::Int(2), &found); | |
215 ASSERT_EQ(1u, found.size()); | |
216 EXPECT_STREQ("name1", found[0]->name.c_str()); | |
217 | |
218 // <= | |
219 analyzer->FindEvents(Query(EVENT_ARG, "num") <= Query::Int(2), &found); | |
220 ASSERT_EQ(2u, found.size()); | |
221 EXPECT_STREQ("name1", found[0]->name.c_str()); | |
222 EXPECT_STREQ("name2", found[1]->name.c_str()); | |
223 | |
224 // > | |
225 analyzer->FindEvents(Query(EVENT_ARG, "num") > Query::Int(3), &found); | |
226 ASSERT_EQ(1u, found.size()); | |
227 EXPECT_STREQ("name4", found[0]->name.c_str()); | |
228 | |
229 // >= | |
230 analyzer->FindEvents(Query(EVENT_ARG, "num") >= Query::Int(4), &found); | |
231 ASSERT_EQ(1u, found.size()); | |
232 EXPECT_STREQ("name4", found[0]->name.c_str()); | |
233 | |
234 // && | |
235 analyzer->FindEvents(Query(EVENT_NAME) != Query::String("name1") && | |
236 Query(EVENT_ARG, "num") < Query::Int(3), &found); | |
237 ASSERT_EQ(1u, found.size()); | |
238 EXPECT_STREQ("name2", found[0]->name.c_str()); | |
239 | |
240 // || | |
241 analyzer->FindEvents(Query(EVENT_NAME) == Query::String("name1") || | |
242 Query(EVENT_ARG, "num") == Query::Int(3), &found); | |
243 ASSERT_EQ(2u, found.size()); | |
244 EXPECT_STREQ("name1", found[0]->name.c_str()); | |
245 EXPECT_STREQ("name3", found[1]->name.c_str()); | |
246 | |
247 // ! | |
248 analyzer->FindEvents(!(Query(EVENT_NAME) == Query::String("name1") || | |
249 Query(EVENT_ARG, "num") == Query::Int(3)), &found); | |
250 ASSERT_EQ(2u, found.size()); | |
251 EXPECT_STREQ("name2", found[0]->name.c_str()); | |
252 EXPECT_STREQ("name4", found[1]->name.c_str()); | |
253 } | |
254 | |
255 TEST_F(TraceEventAnalyzerTest, ArithmeticOperators) { | |
256 using namespace trace_analyzer; | |
257 ManualSetUp(); | |
258 | |
259 BeginTracing(); | |
260 { | |
261 // These events are searched for: | |
262 TRACE_EVENT_INSTANT2("cat1", "math1", "a", 10, "b", 5); | |
263 TRACE_EVENT_INSTANT2("cat1", "math2", "a", 10, "b", 10); | |
264 // Extra events that never match, for noise: | |
265 TRACE_EVENT_INSTANT2("noise", "math3", "a", 1, "b", 3); | |
266 TRACE_EVENT_INSTANT2("noise", "math4", "c", 10, "d", 5); | |
267 } | |
268 EndTracing(); | |
269 | |
270 scoped_ptr<TraceAnalyzer> | |
271 analyzer(TraceAnalyzer::Create(output_.json_output)); | |
272 ASSERT_TRUE(analyzer.get()); | |
273 | |
274 TraceAnalyzer::TraceEventVector found; | |
275 | |
276 // Verify that arithmetic operators function: | |
277 | |
278 // + | |
279 analyzer->FindEvents(Query(EVENT_ARG, "a") + Query(EVENT_ARG, "b") == | |
280 Query::Int(20), &found); | |
281 EXPECT_EQ(1u, found.size()); | |
282 EXPECT_STREQ("math2", found.front()->name.c_str()); | |
283 | |
284 // - | |
285 analyzer->FindEvents(Query(EVENT_ARG, "a") - Query(EVENT_ARG, "b") == | |
286 Query::Int(5), &found); | |
287 EXPECT_EQ(1u, found.size()); | |
288 EXPECT_STREQ("math1", found.front()->name.c_str()); | |
289 | |
290 // * | |
291 analyzer->FindEvents(Query(EVENT_ARG, "a") * Query(EVENT_ARG, "b") == | |
292 Query::Int(50), &found); | |
293 EXPECT_EQ(1u, found.size()); | |
294 EXPECT_STREQ("math1", found.front()->name.c_str()); | |
295 | |
296 // / | |
297 analyzer->FindEvents(Query(EVENT_ARG, "a") / Query(EVENT_ARG, "b") == | |
298 Query::Int(2), &found); | |
299 EXPECT_EQ(1u, found.size()); | |
300 EXPECT_STREQ("math1", found.front()->name.c_str()); | |
301 | |
302 // % | |
303 analyzer->FindEvents(Query(EVENT_ARG, "a") % Query(EVENT_ARG, "b") == | |
304 Query::Int(0), &found); | |
305 EXPECT_EQ(2u, found.size()); | |
306 | |
307 // - (negate) | |
308 analyzer->FindEvents(-Query(EVENT_ARG, "b") == Query::Int(-10), &found); | |
309 EXPECT_EQ(1u, found.size()); | |
310 EXPECT_STREQ("math2", found.front()->name.c_str()); | |
311 } | |
312 | |
313 TEST_F(TraceEventAnalyzerTest, StringPattern) { | |
314 using namespace trace_analyzer; | |
315 ManualSetUp(); | |
316 | |
317 BeginTracing(); | |
318 { | |
319 TRACE_EVENT_INSTANT0("cat1", "name1"); | |
320 TRACE_EVENT_INSTANT0("cat1", "name2"); | |
321 TRACE_EVENT_INSTANT0("cat1", "no match"); | |
322 TRACE_EVENT_INSTANT0("cat1", "name3x"); | |
323 } | |
324 EndTracing(); | |
325 | |
326 scoped_ptr<TraceAnalyzer> | |
327 analyzer(TraceAnalyzer::Create(output_.json_output)); | |
328 ASSERT_TRUE(analyzer.get()); | |
329 | |
330 TraceAnalyzer::TraceEventVector found; | |
331 | |
332 analyzer->FindEvents(Query(EVENT_NAME) == Query::Pattern("name?"), &found); | |
333 ASSERT_EQ(2u, found.size()); | |
334 EXPECT_STREQ("name1", found[0]->name.c_str()); | |
335 EXPECT_STREQ("name2", found[1]->name.c_str()); | |
336 | |
337 analyzer->FindEvents(Query(EVENT_NAME) == Query::Pattern("name*"), &found); | |
338 ASSERT_EQ(3u, found.size()); | |
339 EXPECT_STREQ("name1", found[0]->name.c_str()); | |
340 EXPECT_STREQ("name2", found[1]->name.c_str()); | |
341 EXPECT_STREQ("name3x", found[2]->name.c_str()); | |
342 | |
343 analyzer->FindEvents(Query(EVENT_NAME) != Query::Pattern("name*"), &found); | |
344 ASSERT_EQ(1u, found.size()); | |
345 EXPECT_STREQ("no match", found[0]->name.c_str()); | |
346 } | |
347 | |
348 // Test that duration queries work. | |
349 TEST_F(TraceEventAnalyzerTest, Duration) { | |
350 using namespace trace_analyzer; | |
351 ManualSetUp(); | |
352 | |
353 int sleep_time_us = 200000; | |
354 // We will search for events that have a duration of greater than 90% of the | |
355 // sleep time, so that there is no flakiness. | |
356 int duration_cutoff_us = (sleep_time_us * 9) / 10; | |
357 | |
358 BeginTracing(); | |
359 { | |
360 TRACE_EVENT0("cat1", "name1"); // found by duration query | |
361 TRACE_EVENT0("noise", "name2"); // not searched for, just noise | |
362 { | |
363 TRACE_EVENT0("cat2", "name3"); // found by duration query | |
364 TRACE_EVENT_INSTANT0("noise", "name4"); // not searched for, just noise | |
365 base::PlatformThread::Sleep(sleep_time_us / 1000); | |
366 TRACE_EVENT0("cat2", "name5"); // not found (duration too short) | |
367 } | |
368 } | |
369 EndTracing(); | |
370 | |
371 scoped_ptr<TraceAnalyzer> | |
372 analyzer(TraceAnalyzer::Create(output_.json_output)); | |
373 ASSERT_TRUE(analyzer.get()); | |
374 analyzer->AssociateBeginEndEvents(); | |
375 | |
376 TraceAnalyzer::TraceEventVector found; | |
377 analyzer->FindEvents(Query::MatchBeginWithEnd() && | |
378 Query(EVENT_DURATION) > Query::Int(duration_cutoff_us) && | |
379 (Query(EVENT_CATEGORY) == Query::String("cat1") || | |
380 Query(EVENT_CATEGORY) == Query::String("cat2") || | |
381 Query(EVENT_CATEGORY) == Query::String("cat3")), &found); | |
382 ASSERT_EQ(2u, found.size()); | |
383 EXPECT_STREQ("name1", found[0]->name.c_str()); | |
384 EXPECT_STREQ("name3", found[1]->name.c_str()); | |
385 } | |
386 | |
387 // Test that arithmetic operators work. | |
388 TEST_F(TraceEventAnalyzerTest, BeginEndAssocations) { | |
389 using namespace trace_analyzer; | |
390 ManualSetUp(); | |
391 | |
392 BeginTracing(); | |
393 { | |
394 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin | |
395 TRACE_EVENT0("cat1", "name2"); | |
396 TRACE_EVENT_INSTANT0("cat1", "name3"); | |
397 TRACE_EVENT_BEGIN0("cat1", "name1"); | |
398 } | |
399 EndTracing(); | |
400 | |
401 scoped_ptr<TraceAnalyzer> | |
402 analyzer(TraceAnalyzer::Create(output_.json_output)); | |
403 ASSERT_TRUE(analyzer.get()); | |
404 analyzer->AssociateBeginEndEvents(); | |
405 | |
406 TraceAnalyzer::TraceEventVector found; | |
407 analyzer->FindEvents(Query::MatchBeginWithEnd(), &found); | |
408 ASSERT_EQ(1u, found.size()); | |
409 EXPECT_STREQ("name2", found[0]->name.c_str()); | |
410 } | |
411 | |
412 // Test that the TraceAnalyzer custom associations work. | |
413 TEST_F(TraceEventAnalyzerTest, CustomAssociations) { | |
414 using namespace trace_analyzer; | |
415 ManualSetUp(); | |
416 | |
417 // Add events that begin/end in pipelined ordering with unique ID parameter | |
418 // to match up the begin/end pairs. | |
419 BeginTracing(); | |
420 { | |
421 TRACE_EVENT_INSTANT1("cat1", "end", "id", 1); // no begin match | |
422 TRACE_EVENT_INSTANT1("cat2", "begin", "id", 2); // end is cat4 | |
423 TRACE_EVENT_INSTANT1("cat3", "begin", "id", 3); // end is cat5 | |
424 TRACE_EVENT_INSTANT1("cat4", "end", "id", 2); | |
425 TRACE_EVENT_INSTANT1("cat5", "end", "id", 3); | |
426 TRACE_EVENT_INSTANT1("cat6", "begin", "id", 1); // no end match | |
427 } | |
428 EndTracing(); | |
429 | |
430 scoped_ptr<TraceAnalyzer> | |
431 analyzer(TraceAnalyzer::Create(output_.json_output)); | |
432 ASSERT_TRUE(analyzer.get()); | |
433 | |
434 // begin, end, and match queries to find proper begin/end pairs. | |
435 Query begin(Query(EVENT_NAME) == Query::String("begin")); | |
436 Query end(Query(EVENT_NAME) == Query::String("end")); | |
437 Query match(Query(EVENT_ARG, "id") == Query(OTHER_ARG, "id")); | |
438 analyzer->AssociateEvents(begin, end, match); | |
439 | |
440 TraceAnalyzer::TraceEventVector found; | |
441 | |
442 // cat1 has no other_event. | |
443 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat1") && | |
444 Query(EVENT_HAS_OTHER), &found); | |
445 EXPECT_EQ(0u, found.size()); | |
446 | |
447 // cat1 has no other_event. | |
448 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat1") && | |
449 !Query(EVENT_HAS_OTHER), &found); | |
450 EXPECT_EQ(1u, found.size()); | |
451 | |
452 // cat6 has no other_event. | |
453 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat6") && | |
454 !Query(EVENT_HAS_OTHER), &found); | |
455 EXPECT_EQ(1u, found.size()); | |
456 | |
457 // cat2 and cat4 are a associated. | |
458 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat2") && | |
459 Query(OTHER_CATEGORY) == Query::String("cat4"), &found); | |
460 EXPECT_EQ(1u, found.size()); | |
461 | |
462 // cat4 and cat2 are a associated. | |
463 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat4") && | |
464 Query(OTHER_CATEGORY) == Query::String("cat2"), &found); | |
465 EXPECT_EQ(1u, found.size()); | |
466 | |
467 // cat3 and cat5 are a associated. | |
468 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat3") && | |
469 Query(OTHER_CATEGORY) == Query::String("cat5"), &found); | |
470 EXPECT_EQ(1u, found.size()); | |
471 | |
472 // cat5 and cat3 are a associated. | |
473 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat5") && | |
474 Query(OTHER_CATEGORY) == Query::String("cat3"), &found); | |
475 EXPECT_EQ(1u, found.size()); | |
476 } | |
477 | |
478 // Verify that Query literals and types are properly casted. | |
479 TEST_F(TraceEventAnalyzerTest, Literals) { | |
480 using namespace trace_analyzer; | |
481 ManualSetUp(); | |
482 | |
483 // Since these queries don't refer to the event data, the dummy event below | |
484 // will never be accessed. | |
485 TraceEvent dummy; | |
486 char char_num = 5; | |
487 short short_num = -5; | |
488 EXPECT_TRUE((Query::Double(5.0) == Query::Int(char_num)).Evaluate(dummy)); | |
489 EXPECT_TRUE((Query::Double(-5.0) == Query::Int(short_num)).Evaluate(dummy)); | |
490 EXPECT_TRUE((Query::Double(1.0) == Query::Uint(1u)).Evaluate(dummy)); | |
491 EXPECT_TRUE((Query::Double(1.0) == Query::Int(1)).Evaluate(dummy)); | |
492 EXPECT_TRUE((Query::Double(-1.0) == Query::Int(-1)).Evaluate(dummy)); | |
493 EXPECT_TRUE((Query::Double(1.0) == Query::Double(1.0f)).Evaluate(dummy)); | |
494 EXPECT_TRUE((Query::Bool(true) == Query::Int(1)).Evaluate(dummy)); | |
495 EXPECT_TRUE((Query::Bool(false) == Query::Int(0)).Evaluate(dummy)); | |
496 EXPECT_TRUE((Query::Bool(true) == Query::Double(1.0f)).Evaluate(dummy)); | |
497 EXPECT_TRUE((Query::Bool(false) == Query::Double(0.0f)).Evaluate(dummy)); | |
498 } | |
499 | |
500 | |
501 } // namespace trace_analyzer | |
502 | |
OLD | NEW |