| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 logging | 5 import logging |
| 6 import optparse | 6 import optparse |
| 7 import os | 7 import os |
| 8 import random | 8 import random |
| 9 import sys | 9 import sys |
| 10 import time | 10 import time |
| 11 | 11 |
| 12 from telemetry import decorators |
| 12 from telemetry import page as page_module | 13 from telemetry import page as page_module |
| 13 from telemetry.core import exceptions | 14 from telemetry.core import exceptions |
| 14 from telemetry.core import wpr_modes | 15 from telemetry.core import wpr_modes |
| 15 from telemetry.page import page_set as page_set_module | 16 from telemetry.page import page_set as page_set_module |
| 16 from telemetry.page import page_test | 17 from telemetry.page import page_test |
| 17 from telemetry.page.actions import page_action | 18 from telemetry.page.actions import page_action |
| 18 from telemetry.results import results_options | 19 from telemetry.results import results_options |
| 19 from telemetry.user_story import user_story_filter | 20 from telemetry.user_story import user_story_filter |
| 20 from telemetry.user_story import user_story_set as user_story_set_module | 21 from telemetry.user_story import user_story_set as user_story_set_module |
| 21 from telemetry.util import cloud_storage | 22 from telemetry.util import cloud_storage |
| 23 from telemetry.util import exception_formatter |
| 22 from telemetry.value import failure | 24 from telemetry.value import failure |
| 23 from telemetry.value import skip | 25 from telemetry.value import skip |
| 24 | 26 |
| 25 | 27 |
| 26 class ArchiveError(Exception): | 28 class ArchiveError(Exception): |
| 27 pass | 29 pass |
| 28 | 30 |
| 29 | 31 |
| 30 def AddCommandLineArgs(parser): | 32 def AddCommandLineArgs(parser): |
| 31 user_story_filter.UserStoryFilter.AddCommandLineArgs(parser) | 33 user_story_filter.UserStoryFilter.AddCommandLineArgs(parser) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 has_existing_exception = sys.exc_info() is not None | 109 has_existing_exception = sys.exc_info() is not None |
| 108 try: | 110 try: |
| 109 state.DidRunUserStory(results) | 111 state.DidRunUserStory(results) |
| 110 except Exception: | 112 except Exception: |
| 111 if not has_existing_exception: | 113 if not has_existing_exception: |
| 112 raise | 114 raise |
| 113 # Print current exception and propagate existing exception. | 115 # Print current exception and propagate existing exception. |
| 114 exception_formatter.PrintFormattedException( | 116 exception_formatter.PrintFormattedException( |
| 115 msg='Exception from DidRunUserStory: ') | 117 msg='Exception from DidRunUserStory: ') |
| 116 | 118 |
| 119 @decorators.Cache |
| 120 def _UpdateUserStoryArchivesIfChanged(user_story_set): |
| 121 # Scan every serving directory for .sha1 files |
| 122 # and download them from Cloud Storage. Assume all data is public. |
| 123 all_serving_dirs = user_story_set.serving_dirs.copy() |
| 124 # Add individual page dirs to all serving dirs. |
| 125 for user_story in user_story_set: |
| 126 if isinstance(user_story, page_module.Page) and user_story.is_file: |
| 127 all_serving_dirs.add(user_story.serving_dir) |
| 128 # Scan all serving dirs. |
| 129 for serving_dir in all_serving_dirs: |
| 130 if os.path.splitdrive(serving_dir)[1] == '/': |
| 131 raise ValueError('Trying to serve root directory from HTTP server.') |
| 132 for dirpath, _, filenames in os.walk(serving_dir): |
| 133 for filename in filenames: |
| 134 path, extension = os.path.splitext( |
| 135 os.path.join(dirpath, filename)) |
| 136 if extension != '.sha1': |
| 137 continue |
| 138 cloud_storage.GetIfChanged(path, user_story_set.bucket) |
| 139 |
| 140 |
| 117 class UserStoryGroup(object): | 141 class UserStoryGroup(object): |
| 118 def __init__(self, shared_user_story_state_class): | 142 def __init__(self, shared_user_story_state_class): |
| 119 self._shared_user_story_state_class = shared_user_story_state_class | 143 self._shared_user_story_state_class = shared_user_story_state_class |
| 120 self._user_stories = [] | 144 self._user_stories = [] |
| 121 | 145 |
| 122 @property | 146 @property |
| 123 def shared_user_story_state_class(self): | 147 def shared_user_story_state_class(self): |
| 124 return self._shared_user_story_state_class | 148 return self._shared_user_story_state_class |
| 125 | 149 |
| 126 @property | 150 @property |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 Stop execution for unexpected exceptions such as KeyboardInterrupt. | 200 Stop execution for unexpected exceptions such as KeyboardInterrupt. |
| 177 We "white list" certain exceptions for which the user story runner | 201 We "white list" certain exceptions for which the user story runner |
| 178 can continue running the remaining user stories. | 202 can continue running the remaining user stories. |
| 179 """ | 203 """ |
| 180 # Filter page set based on options. | 204 # Filter page set based on options. |
| 181 user_stories = filter(user_story_filter.UserStoryFilter.IsSelected, | 205 user_stories = filter(user_story_filter.UserStoryFilter.IsSelected, |
| 182 user_story_set) | 206 user_story_set) |
| 183 | 207 |
| 184 if (not finder_options.use_live_sites and user_story_set.bucket and | 208 if (not finder_options.use_live_sites and user_story_set.bucket and |
| 185 finder_options.browser_options.wpr_mode != wpr_modes.WPR_RECORD): | 209 finder_options.browser_options.wpr_mode != wpr_modes.WPR_RECORD): |
| 186 serving_dirs = user_story_set.serving_dirs | 210 _UpdateUserStoryArchivesIfChanged(user_story_set) |
| 187 for directory in serving_dirs: | |
| 188 cloud_storage.GetFilesInDirectoryIfChanged(directory, | |
| 189 user_story_set.bucket) | |
| 190 if not _UpdateAndCheckArchives( | 211 if not _UpdateAndCheckArchives( |
| 191 user_story_set.archive_data_file, user_story_set.wpr_archive_info, | 212 user_story_set.archive_data_file, user_story_set.wpr_archive_info, |
| 192 user_stories): | 213 user_stories): |
| 193 return | 214 return |
| 194 | 215 |
| 195 if not user_stories: | 216 if not user_stories: |
| 196 return | 217 return |
| 197 | 218 |
| 198 # Effective max failures gives priority to command-line flag value. | 219 # Effective max failures gives priority to command-line flag value. |
| 199 effective_max_failures = finder_options.max_failures | 220 effective_max_failures = finder_options.max_failures |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 logging.warning('Device is thermally throttled before running ' | 356 logging.warning('Device is thermally throttled before running ' |
| 336 'performance tests, results will vary.') | 357 'performance tests, results will vary.') |
| 337 | 358 |
| 338 | 359 |
| 339 def _CheckThermalThrottling(platform): | 360 def _CheckThermalThrottling(platform): |
| 340 if not platform.CanMonitorThermalThrottling(): | 361 if not platform.CanMonitorThermalThrottling(): |
| 341 return | 362 return |
| 342 if platform.HasBeenThermallyThrottled(): | 363 if platform.HasBeenThermallyThrottled(): |
| 343 logging.warning('Device has been thermally throttled during ' | 364 logging.warning('Device has been thermally throttled during ' |
| 344 'performance tests, results will vary.') | 365 'performance tests, results will vary.') |
| OLD | NEW |