| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 glob | 7 import glob |
| 8 import logging | 8 import logging |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| 11 import random | 11 import random |
| 12 import sys | 12 import sys |
| 13 import tempfile | 13 import tempfile |
| 14 import time | 14 import time |
| 15 | 15 |
| 16 from telemetry import decorators | 16 from telemetry import decorators |
| 17 from telemetry.core import browser_finder | 17 from telemetry.core import browser_finder |
| 18 from telemetry.core import exceptions | 18 from telemetry.core import exceptions |
| 19 from telemetry.core import util | 19 from telemetry.core import util |
| 20 from telemetry.core import wpr_modes | 20 from telemetry.core import wpr_modes |
| 21 from telemetry.core.platform.profiler import profiler_finder | 21 from telemetry.core.platform.profiler import profiler_finder |
| 22 from telemetry.page import cloud_storage |
| 22 from telemetry.page import page_filter | 23 from telemetry.page import page_filter |
| 23 from telemetry.page import page_runner_repeat | 24 from telemetry.page import page_runner_repeat |
| 24 from telemetry.page import page_test | 25 from telemetry.page import page_test |
| 25 from telemetry.page import results_options | 26 from telemetry.page import results_options |
| 26 from telemetry.page.actions import navigate | 27 from telemetry.page.actions import navigate |
| 27 from telemetry.page.actions import page_action | 28 from telemetry.page.actions import page_action |
| 28 from telemetry.util import exception_formatter | 29 from telemetry.util import exception_formatter |
| 29 | 30 |
| 30 | 31 |
| 31 class _RunState(object): | 32 class _RunState(object): |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 state.StopBrowser() | 304 state.StopBrowser() |
| 304 if not tries: | 305 if not tries: |
| 305 logging.error('Lost connection to browser 3 times. Failing.') | 306 logging.error('Lost connection to browser 3 times. Failing.') |
| 306 raise | 307 raise |
| 307 if test.is_multi_tab_test: | 308 if test.is_multi_tab_test: |
| 308 logging.error( | 309 logging.error( |
| 309 'Lost connection to browser during multi-tab test. Failing.') | 310 'Lost connection to browser during multi-tab test. Failing.') |
| 310 raise | 311 raise |
| 311 | 312 |
| 312 | 313 |
| 314 def _UpdatePageSetArchivesIfChanged(page_set): |
| 315 # Attempt to download the credentials file. |
| 316 if page_set.credentials_path: |
| 317 try: |
| 318 cloud_storage.GetIfChanged( |
| 319 os.path.join(page_set.base_dir, page_set.credentials_path)) |
| 320 except (cloud_storage.CredentialsError, cloud_storage.PermissionError): |
| 321 logging.warning('Cannot retrieve credential file: %s', |
| 322 page_set.credentials_path) |
| 323 # Scan every serving directory for .sha1 files |
| 324 # and download them from Cloud Storage. Assume all data is public. |
| 325 all_serving_dirs = page_set.serving_dirs.copy() |
| 326 # Add individual page dirs to all serving dirs. |
| 327 for page in page_set: |
| 328 if page.is_file: |
| 329 all_serving_dirs.add(page.serving_dir) |
| 330 # Scan all serving dirs. |
| 331 for serving_dir in all_serving_dirs: |
| 332 if os.path.splitdrive(serving_dir)[1] == '/': |
| 333 raise ValueError('Trying to serve root directory from HTTP server.') |
| 334 for dirpath, _, filenames in os.walk(serving_dir): |
| 335 for filename in filenames: |
| 336 path, extension = os.path.splitext( |
| 337 os.path.join(dirpath, filename)) |
| 338 if extension != '.sha1': |
| 339 continue |
| 340 cloud_storage.GetIfChanged(path) |
| 341 |
| 342 |
| 313 def Run(test, page_set, expectations, finder_options): | 343 def Run(test, page_set, expectations, finder_options): |
| 314 """Runs a given test against a given page_set with the given options.""" | 344 """Runs a given test against a given page_set with the given options.""" |
| 315 results = results_options.PrepareResults(test, finder_options) | 345 results = results_options.PrepareResults(test, finder_options) |
| 316 browser_options = finder_options.browser_options | 346 browser_options = finder_options.browser_options |
| 317 | 347 |
| 318 test.ValidatePageSet(page_set) | 348 test.ValidatePageSet(page_set) |
| 319 | 349 |
| 320 # Create a possible_browser with the given options. | 350 # Create a possible_browser with the given options. |
| 321 test.CustomizeBrowserOptions(finder_options) | 351 test.CustomizeBrowserOptions(finder_options) |
| 322 try: | 352 try: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 335 | 365 |
| 336 if not decorators.IsEnabled( | 366 if not decorators.IsEnabled( |
| 337 test, browser_options.browser_type, possible_browser.platform): | 367 test, browser_options.browser_type, possible_browser.platform): |
| 338 return results | 368 return results |
| 339 | 369 |
| 340 # Reorder page set based on options. | 370 # Reorder page set based on options. |
| 341 pages = _ShuffleAndFilterPageSet(page_set, finder_options) | 371 pages = _ShuffleAndFilterPageSet(page_set, finder_options) |
| 342 | 372 |
| 343 if (not finder_options.use_live_sites and | 373 if (not finder_options.use_live_sites and |
| 344 browser_options.wpr_mode != wpr_modes.WPR_RECORD): | 374 browser_options.wpr_mode != wpr_modes.WPR_RECORD): |
| 375 _UpdatePageSetArchivesIfChanged(page_set) |
| 345 pages = _CheckArchives(page_set, pages, results) | 376 pages = _CheckArchives(page_set, pages, results) |
| 346 | 377 |
| 347 # Verify credentials path. | 378 # Verify credentials path. |
| 348 credentials_path = None | 379 credentials_path = None |
| 349 if page_set.credentials_path: | 380 if page_set.credentials_path: |
| 350 credentials_path = os.path.join(os.path.dirname(page_set.file_path), | 381 credentials_path = os.path.join(os.path.dirname(page_set.file_path), |
| 351 page_set.credentials_path) | 382 page_set.credentials_path) |
| 352 if not os.path.exists(credentials_path): | 383 if not os.path.exists(credentials_path): |
| 353 credentials_path = None | 384 credentials_path = None |
| 354 | 385 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 logging.error('Device is thermally throttled before running ' | 594 logging.error('Device is thermally throttled before running ' |
| 564 'performance tests, results will vary.') | 595 'performance tests, results will vary.') |
| 565 | 596 |
| 566 | 597 |
| 567 def _CheckThermalThrottling(platform): | 598 def _CheckThermalThrottling(platform): |
| 568 if not platform.CanMonitorThermalThrottling(): | 599 if not platform.CanMonitorThermalThrottling(): |
| 569 return | 600 return |
| 570 if platform.HasBeenThermallyThrottled(): | 601 if platform.HasBeenThermallyThrottled(): |
| 571 logging.error('Device has been thermally throttled during ' | 602 logging.error('Device has been thermally throttled during ' |
| 572 'performance tests, results will vary.') | 603 'performance tests, results will vary.') |
| OLD | NEW |