Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1002)

Side by Side Diff: tools/telemetry/telemetry/user_story/user_story_runner.py

Issue 838253005: Refactor serving_dirs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed import. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
13 from telemetry import page as page_module 12 from telemetry import page as page_module
14 from telemetry.core import exceptions 13 from telemetry.core import exceptions
15 from telemetry.core import wpr_modes 14 from telemetry.core import wpr_modes
16 from telemetry.page import page_set as page_set_module 15 from telemetry.page import page_set as page_set_module
17 from telemetry.page import page_test 16 from telemetry.page import page_test
18 from telemetry.page.actions import page_action 17 from telemetry.page.actions import page_action
19 from telemetry.results import results_options 18 from telemetry.results import results_options
20 from telemetry.user_story import user_story_filter 19 from telemetry.user_story import user_story_filter
21 from telemetry.user_story import user_story_set as user_story_set_module 20 from telemetry.user_story import user_story_set as user_story_set_module
22 from telemetry.util import cloud_storage 21 from telemetry.util import cloud_storage
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 has_existing_exception = sys.exc_info() is not None 108 has_existing_exception = sys.exc_info() is not None
110 try: 109 try:
111 state.DidRunUserStory(results) 110 state.DidRunUserStory(results)
112 except Exception: 111 except Exception:
113 if not has_existing_exception: 112 if not has_existing_exception:
114 raise 113 raise
115 # Print current exception and propagate existing exception. 114 # Print current exception and propagate existing exception.
116 exception_formatter.PrintFormattedException( 115 exception_formatter.PrintFormattedException(
117 msg='Exception from DidRunUserStory: ') 116 msg='Exception from DidRunUserStory: ')
118 117
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
141 class UserStoryGroup(object): 118 class UserStoryGroup(object):
142 def __init__(self, shared_user_story_state_class): 119 def __init__(self, shared_user_story_state_class):
143 self._shared_user_story_state_class = shared_user_story_state_class 120 self._shared_user_story_state_class = shared_user_story_state_class
144 self._user_stories = [] 121 self._user_stories = []
145 122
146 @property 123 @property
147 def shared_user_story_state_class(self): 124 def shared_user_story_state_class(self):
148 return self._shared_user_story_state_class 125 return self._shared_user_story_state_class
149 126
150 @property 127 @property
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 Stop execution for unexpected exceptions such as KeyboardInterrupt. 177 Stop execution for unexpected exceptions such as KeyboardInterrupt.
201 We "white list" certain exceptions for which the user story runner 178 We "white list" certain exceptions for which the user story runner
202 can continue running the remaining user stories. 179 can continue running the remaining user stories.
203 """ 180 """
204 # Filter page set based on options. 181 # Filter page set based on options.
205 user_stories = filter(user_story_filter.UserStoryFilter.IsSelected, 182 user_stories = filter(user_story_filter.UserStoryFilter.IsSelected,
206 user_story_set) 183 user_story_set)
207 184
208 if (not finder_options.use_live_sites and user_story_set.bucket and 185 if (not finder_options.use_live_sites and user_story_set.bucket and
209 finder_options.browser_options.wpr_mode != wpr_modes.WPR_RECORD): 186 finder_options.browser_options.wpr_mode != wpr_modes.WPR_RECORD):
210 _UpdateUserStoryArchivesIfChanged(user_story_set) 187 serving_dirs = user_story_set.serving_dirs
188 for directory in serving_dirs:
189 cloud_storage.GetFilesInDirectoryIfChanged(directory,
190 user_story_set.bucket)
211 if not _UpdateAndCheckArchives( 191 if not _UpdateAndCheckArchives(
212 user_story_set.archive_data_file, user_story_set.wpr_archive_info, 192 user_story_set.archive_data_file, user_story_set.wpr_archive_info,
213 user_stories): 193 user_stories):
214 return 194 return
215 195
216 if not user_stories: 196 if not user_stories:
217 return 197 return
218 198
219 # Effective max failures gives priority to command-line flag value. 199 # Effective max failures gives priority to command-line flag value.
220 effective_max_failures = finder_options.max_failures 200 effective_max_failures = finder_options.max_failures
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 logging.warning('Device is thermally throttled before running ' 336 logging.warning('Device is thermally throttled before running '
357 'performance tests, results will vary.') 337 'performance tests, results will vary.')
358 338
359 339
360 def _CheckThermalThrottling(platform): 340 def _CheckThermalThrottling(platform):
361 if not platform.CanMonitorThermalThrottling(): 341 if not platform.CanMonitorThermalThrottling():
362 return 342 return
363 if platform.HasBeenThermallyThrottled(): 343 if platform.HasBeenThermallyThrottled():
364 logging.warning('Device has been thermally throttled during ' 344 logging.warning('Device has been thermally throttled during '
365 'performance tests, results will vary.') 345 'performance tests, results will vary.')
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/user_story/__init__.py ('k') | tools/telemetry/telemetry/user_story/user_story_set.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698