| 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 # Local build of Chrome (not Chromium). |
| 31 _CHROME_PACKAGE = 'com.google.android.apps.chrome' |
| 32 |
| 33 |
| 34 def ResetChromeLocalState(device): |
| 35 """Remove the Chrome Profile and the various disk caches.""" |
| 36 profile_dirs = ['app_chrome/Default', 'cache', 'app_chrome/ShaderCache', |
| 37 'app_tabs'] |
| 38 cmd = ['rm', '-rf'] |
| 39 cmd.extend( |
| 40 '/data/data/{}/{}'.format(_CHROME_PACKAGE, d) for d in profile_dirs) |
| 41 device.adb.Shell(subprocess.list2cmdline(cmd)) |
| 42 |
| 43 |
| 29 def RunOnce(device, url, warmup, no_prerendering, delay_to_may_launch_url, | 44 def RunOnce(device, url, warmup, no_prerendering, delay_to_may_launch_url, |
| 30 delay_to_launch_url, cold): | 45 delay_to_launch_url, cold): |
| 31 """Runs a test on a device once. | 46 """Runs a test on a device once. |
| 32 | 47 |
| 33 Args: | 48 Args: |
| 34 device: (DeviceUtils) device to run the tests on. | 49 device: (DeviceUtils) device to run the tests on. |
| 35 warmup: (bool) Whether to call warmup. | 50 warmup: (bool) Whether to call warmup. |
| 36 no_prerendering: (bool) Whether to disable prerendering. | 51 no_prerendering: (bool) Whether to disable prerendering. |
| 37 delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. | 52 delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. |
| 38 delay_to_launch_url: (int) Delay to launchUrl() in ms. | 53 delay_to_launch_url: (int) Delay to launchUrl() in ms. |
| 39 cold: (bool) Whether the page cache should be dropped. | 54 cold: (bool) Whether the page cache should be dropped. |
| 40 | 55 |
| 41 Returns: | 56 Returns: |
| 42 The output line (str), like this (one line only): | 57 The output line (str), like this (one line only): |
| 43 <warmup>,<no_prerendering>,<delay_to_may_launch_url>,<intent_sent_ms>, | 58 <warmup>,<no_prerendering>,<delay_to_may_launch_url>,<intent_sent_ms>, |
| 44 <page_load_started_ms>,<page_load_finished_ms> | 59 <page_load_started_ms>,<page_load_finished_ms> |
| 45 or None on error. | 60 or None on error. |
| 46 """ | 61 """ |
| 47 launch_intent = intent.Intent( | 62 launch_intent = intent.Intent( |
| 48 action='android.intent.action.MAIN', | 63 action='android.intent.action.MAIN', |
| 49 package='org.chromium.customtabsclient.test', | 64 package='org.chromium.customtabsclient.test', |
| 50 activity='org.chromium.customtabs.test.MainActivity', | 65 activity='org.chromium.customtabs.test.MainActivity', |
| 51 extras={'url': url, 'warmup': warmup, 'no_prerendering': no_prerendering, | 66 extras={'url': url, 'warmup': warmup, 'no_prerendering': no_prerendering, |
| 52 'delay_to_may_launch_url': delay_to_may_launch_url, | 67 'delay_to_may_launch_url': delay_to_may_launch_url, |
| 53 'delay_to_launch_url': delay_to_launch_url}) | 68 'delay_to_launch_url': delay_to_launch_url}) |
| 54 result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') | 69 result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') |
| 55 logcat_monitor = device.GetLogcatMonitor(clear=True) | 70 logcat_monitor = device.GetLogcatMonitor(clear=True) |
| 56 logcat_monitor.Start() | 71 logcat_monitor.Start() |
| 57 device.ForceStop('com.google.android.apps.chrome') | 72 device.ForceStop(_CHROME_PACKAGE) |
| 58 device.ForceStop('org.chromium.customtabsclient.test') | 73 device.ForceStop('org.chromium.customtabsclient.test') |
| 74 ResetChromeLocalState(device) |
| 75 |
| 59 if cold: | 76 if cold: |
| 60 if not device.HasRoot(): | 77 if not device.HasRoot(): |
| 61 device.EnableRoot() | 78 device.EnableRoot() |
| 62 cache_control.CacheControl(device).DropRamCaches() | 79 cache_control.CacheControl(device).DropRamCaches() |
| 63 device.StartActivity(launch_intent, blocking=True) | 80 device.StartActivity(launch_intent, blocking=True) |
| 64 match = None | 81 match = None |
| 65 try: | 82 try: |
| 66 match = logcat_monitor.WaitFor(result_line_re, timeout=10) | 83 match = logcat_monitor.WaitFor(result_line_re, timeout=10) |
| 67 except device_errors.CommandTimeoutError as e: | 84 except device_errors.CommandTimeoutError as e: |
| 68 logging.warning('Timeout waiting for the result line') | 85 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.') | 183 logging.error('Device not found.') |
| 167 sys.exit(0) | 184 sys.exit(0) |
| 168 device = matching_devices[0] | 185 device = matching_devices[0] |
| 169 LoopOnDevice(device, options.url, options.warmup, options.no_prerendering, | 186 LoopOnDevice(device, options.url, options.warmup, options.no_prerendering, |
| 170 options.delay_to_may_launch_url, options.delay_to_launch_url, | 187 options.delay_to_may_launch_url, options.delay_to_launch_url, |
| 171 options.cold, options.output_file, options.once) | 188 options.cold, options.output_file, options.once) |
| 172 | 189 |
| 173 | 190 |
| 174 if __name__ == '__main__': | 191 if __name__ == '__main__': |
| 175 main() | 192 main() |
| OLD | NEW |