OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Loops Custom Tabs tests and outputs the results into a CSV file.""" | 7 """Loops Custom Tabs tests and outputs the results into a CSV file.""" |
8 | 8 |
9 import logging | 9 import logging |
10 import optparse | 10 import optparse |
11 import os | 11 import os |
12 import re | 12 import re |
13 import subprocess | |
13 import sys | 14 import sys |
14 import time | 15 import time |
15 | 16 |
16 _SRC_PATH = os.path.abspath(os.path.join( | 17 _SRC_PATH = os.path.abspath(os.path.join( |
17 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)) | 18 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)) |
18 | 19 |
19 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil')) | 20 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil')) |
20 from devil.android import device_errors | 21 from devil.android import device_errors |
21 from devil.android import device_utils | 22 from devil.android import device_utils |
22 from devil.android.perf import cache_control | 23 from devil.android.perf import cache_control |
23 from devil.android.sdk import intent | 24 from devil.android.sdk import intent |
24 | 25 |
25 sys.path.append(os.path.join(_SRC_PATH, 'build', 'android')) | 26 sys.path.append(os.path.join(_SRC_PATH, 'build', 'android')) |
26 import devil_chromium | 27 import devil_chromium |
27 | 28 |
28 | 29 |
30 _CHROME_PACKAGE = 'com.google.android.apps.chrome' | |
Benoit L
2016/09/27 14:54:45
Maybe add a comment to say that it corresponds to
droger
2016/09/27 15:39:13
Done.
| |
31 | |
32 | |
33 def ResetChromeLocalState(device): | |
34 """Remove the Chrome Profile and the various disk caches.""" | |
35 for directory in ['app_chrome/Default', 'cache', 'app_chrome/ShaderCache', | |
Benoit L
2016/09/27 14:54:45
Where does this list come?
droger
2016/09/27 15:39:13
This comes from controller.py:
https://cs.chromium
| |
36 'app_tabs']: | |
37 cmd = ['rm', '-rf', '/data/data/{}/{}'.format(_CHROME_PACKAGE, directory)] | |
Benoit L
2016/09/27 14:54:45
rm can take several arguments, it woulb be a bit f
droger
2016/09/27 15:39:13
Done.
| |
38 device.adb.Shell(subprocess.list2cmdline(cmd)) | |
39 | |
40 | |
29 def RunOnce(device, url, warmup, no_prerendering, delay_to_may_launch_url, | 41 def RunOnce(device, url, warmup, no_prerendering, delay_to_may_launch_url, |
30 delay_to_launch_url, cold): | 42 delay_to_launch_url, cold): |
31 """Runs a test on a device once. | 43 """Runs a test on a device once. |
32 | 44 |
33 Args: | 45 Args: |
34 device: (DeviceUtils) device to run the tests on. | 46 device: (DeviceUtils) device to run the tests on. |
35 warmup: (bool) Whether to call warmup. | 47 warmup: (bool) Whether to call warmup. |
36 no_prerendering: (bool) Whether to disable prerendering. | 48 no_prerendering: (bool) Whether to disable prerendering. |
37 delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. | 49 delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. |
38 delay_to_launch_url: (int) Delay to launchUrl() in ms. | 50 delay_to_launch_url: (int) Delay to launchUrl() in ms. |
39 cold: (bool) Whether the page cache should be dropped. | 51 cold: (bool) Whether the page cache should be dropped. |
40 | 52 |
41 Returns: | 53 Returns: |
42 The output line (str), like this (one line only): | 54 The output line (str), like this (one line only): |
43 <warmup>,<no_prerendering>,<delay_to_may_launch_url>,<intent_sent_ms>, | 55 <warmup>,<no_prerendering>,<delay_to_may_launch_url>,<intent_sent_ms>, |
44 <page_load_started_ms>,<page_load_finished_ms> | 56 <page_load_started_ms>,<page_load_finished_ms> |
45 or None on error. | 57 or None on error. |
46 """ | 58 """ |
47 launch_intent = intent.Intent( | 59 launch_intent = intent.Intent( |
48 action='android.intent.action.MAIN', | 60 action='android.intent.action.MAIN', |
49 package='org.chromium.customtabsclient.test', | 61 package='org.chromium.customtabsclient.test', |
50 activity='org.chromium.customtabs.test.MainActivity', | 62 activity='org.chromium.customtabs.test.MainActivity', |
51 extras={'url': url, 'warmup': warmup, 'no_prerendering': no_prerendering, | 63 extras={'url': url, 'warmup': warmup, 'no_prerendering': no_prerendering, |
52 'delay_to_may_launch_url': delay_to_may_launch_url, | 64 'delay_to_may_launch_url': delay_to_may_launch_url, |
53 'delay_to_launch_url': delay_to_launch_url}) | 65 'delay_to_launch_url': delay_to_launch_url}) |
54 result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') | 66 result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') |
55 logcat_monitor = device.GetLogcatMonitor(clear=True) | 67 logcat_monitor = device.GetLogcatMonitor(clear=True) |
56 logcat_monitor.Start() | 68 logcat_monitor.Start() |
57 device.ForceStop('com.google.android.apps.chrome') | 69 device.ForceStop(_CHROME_PACKAGE) |
58 device.ForceStop('org.chromium.customtabsclient.test') | 70 device.ForceStop('org.chromium.customtabsclient.test') |
71 ResetChromeLocalState(device) | |
72 | |
59 if cold: | 73 if cold: |
60 if not device.HasRoot(): | 74 if not device.HasRoot(): |
61 device.EnableRoot() | 75 device.EnableRoot() |
62 cache_control.CacheControl(device).DropRamCaches() | 76 cache_control.CacheControl(device).DropRamCaches() |
63 device.StartActivity(launch_intent, blocking=True) | 77 device.StartActivity(launch_intent, blocking=True) |
64 match = None | 78 match = None |
65 try: | 79 try: |
66 match = logcat_monitor.WaitFor(result_line_re, timeout=10) | 80 match = logcat_monitor.WaitFor(result_line_re, timeout=10) |
67 except device_errors.CommandTimeoutError as e: | 81 except device_errors.CommandTimeoutError as e: |
68 logging.warning('Timeout waiting for the result line') | 82 logging.warning('Timeout waiting for the result line') |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 logging.error('Device not found.') | 180 logging.error('Device not found.') |
167 sys.exit(0) | 181 sys.exit(0) |
168 device = matching_devices[0] | 182 device = matching_devices[0] |
169 LoopOnDevice(device, options.url, options.warmup, options.no_prerendering, | 183 LoopOnDevice(device, options.url, options.warmup, options.no_prerendering, |
170 options.delay_to_may_launch_url, options.delay_to_launch_url, | 184 options.delay_to_may_launch_url, options.delay_to_launch_url, |
171 options.cold, options.output_file, options.once) | 185 options.cold, options.output_file, options.once) |
172 | 186 |
173 | 187 |
174 if __name__ == '__main__': | 188 if __name__ == '__main__': |
175 main() | 189 main() |
OLD | NEW |