Chromium Code Reviews| 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 contextlib | 9 import contextlib |
| 10 import logging | 10 import logging |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 Returns: | 83 Returns: |
| 84 The output line (str), like this (one line only): | 84 The output line (str), like this (one line only): |
| 85 <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>, | 85 <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>, |
| 86 <intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms>, | 86 <intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms>, |
| 87 <first_contentful_paint> | 87 <first_contentful_paint> |
| 88 or None on error. | 88 or None on error. |
| 89 """ | 89 """ |
| 90 if not device.HasRoot(): | 90 if not device.HasRoot(): |
| 91 device.EnableRoot() | 91 device.EnableRoot() |
| 92 | 92 |
| 93 timeout_s = 20 | |
| 94 logcat_timeout = int(timeout_s + delay_to_launch_url / 1000. | |
| 95 + delay_to_launch_url / 1000.) + 3; | |
|
droger
2016/11/24 14:08:10
Why is delay_to_launch_url repeated? did you mean
Benoit L
2016/11/24 14:34:17
Oops, thanks!
Done.
| |
| 96 | |
| 93 with device_setup.FlagReplacer(device, _COMMAND_LINE_PATH, chrome_args): | 97 with device_setup.FlagReplacer(device, _COMMAND_LINE_PATH, chrome_args): |
| 94 launch_intent = intent.Intent( | 98 launch_intent = intent.Intent( |
| 95 action='android.intent.action.MAIN', | 99 action='android.intent.action.MAIN', |
| 96 package=_TEST_APP_PACKAGE_NAME, | 100 package=_TEST_APP_PACKAGE_NAME, |
| 97 activity='org.chromium.customtabs.test.MainActivity', | 101 activity='org.chromium.customtabs.test.MainActivity', |
| 98 extras={'url': str(url), 'warmup': warmup, | 102 extras={'url': str(url), 'warmup': warmup, |
| 99 'speculation_mode': str(speculation_mode), | 103 'speculation_mode': str(speculation_mode), |
| 100 'delay_to_may_launch_url': delay_to_may_launch_url, | 104 'delay_to_may_launch_url': delay_to_may_launch_url, |
| 101 'delay_to_launch_url': delay_to_launch_url}) | 105 'delay_to_launch_url': delay_to_launch_url, |
| 106 'timeout': timeout_s}) | |
| 102 result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') | 107 result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') |
| 103 logcat_monitor = device.GetLogcatMonitor(clear=True) | 108 logcat_monitor = device.GetLogcatMonitor(clear=True) |
| 104 logcat_monitor.Start() | 109 logcat_monitor.Start() |
| 105 device.ForceStop(_CHROME_PACKAGE) | 110 device.ForceStop(_CHROME_PACKAGE) |
| 106 device.ForceStop(_TEST_APP_PACKAGE_NAME) | 111 device.ForceStop(_TEST_APP_PACKAGE_NAME) |
| 107 | 112 |
| 108 ResetChromeLocalState(device) | 113 ResetChromeLocalState(device) |
| 109 | 114 |
| 110 if cold: | 115 if cold: |
| 111 cache_control.CacheControl(device).DropRamCaches() | 116 cache_control.CacheControl(device).DropRamCaches() |
| 112 | 117 |
| 113 device.StartActivity(launch_intent, blocking=True) | 118 device.StartActivity(launch_intent, blocking=True) |
| 114 | 119 |
| 115 match = None | 120 match = None |
| 116 try: | 121 try: |
| 117 match = logcat_monitor.WaitFor(result_line_re, timeout=20) | 122 match = logcat_monitor.WaitFor(result_line_re, timeout=logcat_timeout) |
| 118 except device_errors.CommandTimeoutError as _: | 123 except device_errors.CommandTimeoutError as _: |
| 119 logging.warning('Timeout waiting for the result line') | 124 logging.warning('Timeout waiting for the result line') |
| 120 logcat_monitor.Stop() | 125 logcat_monitor.Stop() |
| 121 logcat_monitor.Close() | 126 logcat_monitor.Close() |
| 122 return match.group(1) if match is not None else None | 127 return match.group(1) if match is not None else None |
| 123 | 128 |
| 124 | 129 |
| 125 def LoopOnDevice(device, configs, output_filename, wpr_archive_path=None, | 130 def LoopOnDevice(device, configs, output_filename, wpr_archive_path=None, |
| 126 wpr_record=None, network_condition=None, wpr_log_path=None, | 131 wpr_record=None, network_condition=None, wpr_log_path=None, |
| 127 once=False, should_stop=None): | 132 once=False, should_stop=None): |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 default='https://www.android.com') | 208 default='https://www.android.com') |
| 204 parser.add_option('--warmup', help='Call warmup.', default=False, | 209 parser.add_option('--warmup', help='Call warmup.', default=False, |
| 205 action='store_true') | 210 action='store_true') |
| 206 parser.add_option('--speculation_mode', default='prerender', | 211 parser.add_option('--speculation_mode', default='prerender', |
| 207 help='The speculation mode (prerender, disabled, ' | 212 help='The speculation mode (prerender, disabled, ' |
| 208 'speculative_prefetch or no_state_prefetch).', | 213 'speculative_prefetch or no_state_prefetch).', |
| 209 choices=['prerender', 'disabled', 'speculative_prefetch', | 214 choices=['prerender', 'disabled', 'speculative_prefetch', |
| 210 'no_state_prefetch']) | 215 'no_state_prefetch']) |
| 211 parser.add_option('--delay_to_may_launch_url', | 216 parser.add_option('--delay_to_may_launch_url', |
| 212 help='Delay before calling mayLaunchUrl() in ms.', | 217 help='Delay before calling mayLaunchUrl() in ms.', |
| 213 type='int') | 218 type='int', default=1000) |
| 214 parser.add_option('--delay_to_launch_url', | 219 parser.add_option('--delay_to_launch_url', |
| 215 help='Delay before calling launchUrl() in ms.', | 220 help='Delay before calling launchUrl() in ms.', |
| 216 type='int') | 221 type='int', default=-1) |
| 217 parser.add_option('--cold', help='Purge the page cache before each run.', | 222 parser.add_option('--cold', help='Purge the page cache before each run.', |
| 218 default=False, action='store_true') | 223 default=False, action='store_true') |
| 219 parser.add_option('--output_file', help='Output file (append). "-" for ' | 224 parser.add_option('--output_file', help='Output file (append). "-" for ' |
| 220 'stdout') | 225 'stdout') |
| 221 parser.add_option('--once', help='Run only one iteration.', | 226 parser.add_option('--once', help='Run only one iteration.', |
| 222 action='store_true', default=False) | 227 action='store_true', default=False) |
| 223 | 228 |
| 224 # WebPageReplay-related options. | 229 # WebPageReplay-related options. |
| 225 group = optparse.OptionGroup( | 230 group = optparse.OptionGroup( |
| 226 parser, 'WebPageReplay options', | 231 parser, 'WebPageReplay options', |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 'delay_to_launch_url': options.delay_to_launch_url, | 282 'delay_to_launch_url': options.delay_to_launch_url, |
| 278 'cold': options.cold, | 283 'cold': options.cold, |
| 279 } | 284 } |
| 280 LoopOnDevice(device, [config], options.output_file, options.wpr_archive, | 285 LoopOnDevice(device, [config], options.output_file, options.wpr_archive, |
| 281 options.record, options.network_condition, options.wpr_log, | 286 options.record, options.network_condition, options.wpr_log, |
| 282 once=options.once) | 287 once=options.once) |
| 283 | 288 |
| 284 | 289 |
| 285 if __name__ == '__main__': | 290 if __name__ == '__main__': |
| 286 main() | 291 main() |
| OLD | NEW |