OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2014 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 import os | |
6 import json | |
7 import unittest | |
8 | |
9 from chrome_profiler import controllers | |
10 from chrome_profiler import profiler | |
11 | |
12 from pylib import android_commands | |
13 from pylib.device import device_utils | |
14 | |
15 | |
16 _BROWSER = 'stable' | |
17 | |
18 | |
19 class ControllersTest(unittest.TestCase): | |
20 def setUp(self): | |
21 devices = android_commands.GetAttachedDevices() | |
22 self.assertEquals(len(devices), 1) | |
Dominik Grewe
2014/05/22 18:07:10
Is this always true on the bots?
Sami
2014/05/27 11:03:54
You're right, it isn't. I think I'll just pick the
| |
23 self.package_info = profiler.GetSupportedBrowsers()[_BROWSER] | |
24 self.device = device_utils.DeviceUtils(devices[0]) | |
25 | |
26 adb = android_commands.AndroidCommands(devices[0]) | |
27 adb.StartActivity(self.package_info.package, | |
28 self.package_info.activity, | |
29 wait_for_completion=True) | |
30 | |
31 def testChromeTracingGetCategories(self): | |
32 # Not supported on stable yet. | |
33 if _BROWSER == 'stable': | |
Dominik Grewe
2014/05/22 18:07:10
Currently this will always be false, won't it? Are
Sami
2014/05/27 11:03:54
That's right, this is really here only for manual
| |
34 return | |
35 | |
36 categories = \ | |
37 controllers.ChromeTracingController.GetCategories(self.device, | |
38 self.package_info) | |
39 self.assertEquals(len(categories), 2) | |
40 self.assertTrue(categories[0]) | |
41 self.assertTrue(categories[1]) | |
42 | |
43 def testChromeTracing(self): | |
44 categories = '*' | |
45 ring_buffer = False | |
46 controller = controllers.ChromeTracingController(self.device, | |
47 self.package_info, | |
48 categories, | |
49 ring_buffer) | |
50 | |
51 interval = 1 | |
52 try: | |
53 controller.StartTracing(interval) | |
54 finally: | |
55 controller.StopTracing() | |
56 | |
57 result = controller.PullTrace() | |
58 try: | |
59 with open(result) as f: | |
60 json.loads(f.read()) | |
61 finally: | |
62 os.remove(result) | |
63 | |
64 def testSystraceGetCategories(self): | |
65 categories = controllers.SystraceController.GetCategories(self.device) | |
66 self.assertTrue(categories) | |
67 | |
68 def testSystrace(self): | |
69 categories = ['gfx', 'input', 'view'] | |
70 ring_buffer = False | |
71 controller = controllers.SystraceController(self.device, | |
72 categories, | |
73 ring_buffer) | |
74 | |
75 interval = 1 | |
76 try: | |
77 controller.StartTracing(interval) | |
78 finally: | |
79 controller.StopTracing() | |
80 | |
81 result = controller.PullTrace() | |
82 try: | |
83 with open(result) as f: | |
84 self.assertTrue('CPU#' in f.read()) | |
85 finally: | |
86 os.remove(result) | |
OLD | NEW |