OLD | NEW |
---|---|
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 import collections | 5 import collections |
6 import copy | 6 import copy |
7 import logging | 7 import logging |
8 import operator | 8 import operator |
9 import unittest | 9 import unittest |
10 | 10 |
11 import clovis_constants | |
blundell
2016/06/06 16:06:38
nit: this seems like a minor layering violation. a
pasko
2016/06/06 17:30:52
It does not look like a layering violation to me.
| |
11 import devtools_monitor | 12 import devtools_monitor |
12 | 13 |
13 from tracing import (Event, TracingTrack, _IntervalTree) | 14 from tracing import (Event, TracingTrack, _IntervalTree) |
14 | 15 |
15 | 16 |
16 class TracingTrackTestCase(unittest.TestCase): | 17 class TracingTrackTestCase(unittest.TestCase): |
17 _MIXED_EVENTS = [ | 18 _MIXED_EVENTS = [ |
18 {'ts': 3, 'ph': 'N', 'id': 1, 'args': {'name': 'A'}}, | 19 {'ts': 3, 'ph': 'N', 'id': 1, 'args': {'name': 'A'}}, |
19 {'ts': 5, 'ph': 'X', 'dur': 1, 'args': {'name': 'B'}}, | 20 {'ts': 5, 'ph': 'X', 'dur': 1, 'args': {'name': 'B'}}, |
20 {'ts': 7, 'ph': 'D', 'id': 1}, | 21 {'ts': 7, 'ph': 'D', 'id': 1}, |
(...skipping 14 matching lines...) Expand all Loading... | |
35 {'ts': 10, 'ph': 'X', 'dur': 2, 'pid': 2, 'tid': 2, | 36 {'ts': 10, 'ph': 'X', 'dur': 2, 'pid': 2, 'tid': 2, |
36 'args': {'name': 'D'}}, | 37 'args': {'name': 'D'}}, |
37 {'ts': 13, 'ph': 'X', 'dur': 1, 'pid': 2, 'tid': 1, | 38 {'ts': 13, 'ph': 'X', 'dur': 1, 'pid': 2, 'tid': 1, |
38 'args': {'name': 'F'}}, | 39 'args': {'name': 'F'}}, |
39 {'ts': 12, 'ph': 'X', 'dur': 3, 'pid': 2, 'tid': 1, | 40 {'ts': 12, 'ph': 'X', 'dur': 3, 'pid': 2, 'tid': 1, |
40 'args': {'name': 'E'}}] | 41 'args': {'name': 'E'}}] |
41 | 42 |
42 def setUp(self): | 43 def setUp(self): |
43 self.tree_threshold = _IntervalTree._TRESHOLD | 44 self.tree_threshold = _IntervalTree._TRESHOLD |
44 _IntervalTree._TRESHOLD = 2 # Expose more edge cases in the tree. | 45 _IntervalTree._TRESHOLD = 2 # Expose more edge cases in the tree. |
45 self.track = TracingTrack(None, additional_categories=('A', 'B', 'C', 'D')) | 46 self.track = TracingTrack(None, |
47 clovis_constants.DEFAULT_CATEGORIES + ['A', 'B', 'C', 'D']) | |
gabadie
2016/06/06 16:17:30
Why is it needed to add clovis_constants.DEFAULT_C
pasko
2016/06/06 17:30:52
You are right, this is not needed. Also blundell@
| |
46 | 48 |
47 def tearDown(self): | 49 def tearDown(self): |
48 _IntervalTree._TRESHOLD = self.tree_threshold | 50 _IntervalTree._TRESHOLD = self.tree_threshold |
49 | 51 |
50 def EventToMicroseconds(self, event): | 52 def EventToMicroseconds(self, event): |
51 result = copy.deepcopy(event) | 53 result = copy.deepcopy(event) |
52 if 'ts' in result: | 54 if 'ts' in result: |
53 result['ts'] *= 1000 | 55 result['ts'] *= 1000 |
54 if 'dur' in result: | 56 if 'dur' in result: |
55 result['dur'] *= 1000 | 57 result['dur'] *= 1000 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 self.assertListEqual([tracing_events[0], tracing_events[3]], | 355 self.assertListEqual([tracing_events[0], tracing_events[3]], |
354 filtered_events) | 356 filtered_events) |
355 filtered_events = self.track.Filter(categories=set(['Z'])).GetEvents() | 357 filtered_events = self.track.Filter(categories=set(['Z'])).GetEvents() |
356 self.assertEquals(0, len(filtered_events)) | 358 self.assertEquals(0, len(filtered_events)) |
357 filtered_events = self.track.Filter(categories=set(['B', 'C'])).GetEvents() | 359 filtered_events = self.track.Filter(categories=set(['B', 'C'])).GetEvents() |
358 self.assertEquals(3, len(filtered_events)) | 360 self.assertEquals(3, len(filtered_events)) |
359 self.assertListEqual(tracing_events[1:], filtered_events) | 361 self.assertListEqual(tracing_events[1:], filtered_events) |
360 self.assertSetEqual( | 362 self.assertSetEqual( |
361 set('A'), self.track.Filter(categories=set('A')).Categories()) | 363 set('A'), self.track.Filter(categories=set('A')).Categories()) |
362 | 364 |
363 def testAdditionalCategories(self): | |
364 track = TracingTrack(None, additional_categories=('best-category-ever',)) | |
365 self.assertIn('best-category-ever', track.Categories()) | |
366 # Cannot re-enable a category. | |
367 with self.assertRaises(AssertionError): | |
368 TracingTrack(None, additional_categories=('cc',)) | |
369 # Cannot disable categories via |additional_categories|. | |
370 with self.assertRaises(AssertionError): | |
371 TracingTrack(None, additional_categories=('-best-category-ever',)) | |
372 | |
373 def testDisabledCategories(self): | |
374 track = TracingTrack(None, disabled_categories=('toplevel',)) | |
375 self.assertNotIn('toplevel', track.Categories()) | |
376 self.assertIn('-toplevel', track.Categories()) | |
377 # Can only disable categories that are enabled by default. | |
378 with self.assertRaises(AssertionError): | |
379 TracingTrack(None, disabled_categories=('best-category-ever',)) | |
380 with self.assertRaises(AssertionError): | |
381 TracingTrack(None, disabled_categories=('cc',)) | |
382 | |
383 def _HandleEvents(self, events): | 365 def _HandleEvents(self, events): |
384 self.track.Handle('Tracing.dataCollected', {'params': {'value': [ | 366 self.track.Handle('Tracing.dataCollected', {'params': {'value': [ |
385 self.EventToMicroseconds(e) for e in events]}}) | 367 self.EventToMicroseconds(e) for e in events]}}) |
386 | 368 |
387 | 369 |
388 class IntervalTreeTestCase(unittest.TestCase): | 370 class IntervalTreeTestCase(unittest.TestCase): |
389 class FakeEvent(object): | 371 class FakeEvent(object): |
390 def __init__(self, start_msec, end_msec): | 372 def __init__(self, start_msec, end_msec): |
391 self.start_msec = start_msec | 373 self.start_msec = start_msec |
392 self.end_msec = end_msec | 374 self.end_msec = end_msec |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 'cat': 'bar,baz,bizbiz', | 441 'cat': 'bar,baz,bizbiz', |
460 'ph': 'X', | 442 'ph': 'X', |
461 'ts': 0, 'dur': 0}) | 443 'ts': 0, 'dur': 0}) |
462 self.assertTrue(event.Matches('bar', 'foo')) | 444 self.assertTrue(event.Matches('bar', 'foo')) |
463 self.assertTrue(event.Matches('baz', 'foo')) | 445 self.assertTrue(event.Matches('baz', 'foo')) |
464 self.assertFalse(event.Matches('bar', 'biz')) | 446 self.assertFalse(event.Matches('bar', 'biz')) |
465 self.assertFalse(event.Matches('biz', 'foo')) | 447 self.assertFalse(event.Matches('biz', 'foo')) |
466 | 448 |
467 if __name__ == '__main__': | 449 if __name__ == '__main__': |
468 unittest.main() | 450 unittest.main() |
OLD | NEW |