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

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: Add unittests. Created 5 years, 10 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 util 14 from telemetry.core import util
16 from telemetry.core import wpr_modes 15 from telemetry.core import wpr_modes
17 from telemetry.page import page_set as page_set_module 16 from telemetry.page import page_set as page_set_module
18 from telemetry.page import page_test 17 from telemetry.page import page_test
19 from telemetry.page.actions import page_action 18 from telemetry.page.actions import page_action
20 from telemetry.results import results_options 19 from telemetry.results import results_options
21 from telemetry.user_story import user_story_filter 20 from telemetry.user_story import user_story_filter
22 from telemetry.util import cloud_storage 21 from telemetry.util import cloud_storage
23 from telemetry.util import exception_formatter
24 from telemetry.value import failure 22 from telemetry.value import failure
25 from telemetry.value import skip 23 from telemetry.value import skip
26 24
27 25
28 class ArchiveError(Exception): 26 class ArchiveError(Exception):
29 pass 27 pass
30 28
31 29
32 def AddCommandLineArgs(parser): 30 def AddCommandLineArgs(parser):
33 user_story_filter.UserStoryFilter.AddCommandLineArgs(parser) 31 user_story_filter.UserStoryFilter.AddCommandLineArgs(parser)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 has_existing_exception = sys.exc_info() is not None 118 has_existing_exception = sys.exc_info() is not None
121 try: 119 try:
122 state.DidRunUserStory(results) 120 state.DidRunUserStory(results)
123 except Exception: 121 except Exception:
124 if not has_existing_exception: 122 if not has_existing_exception:
125 raise 123 raise
126 # Print current exception and propagate existing exception. 124 # Print current exception and propagate existing exception.
127 exception_formatter.PrintFormattedException( 125 exception_formatter.PrintFormattedException(
128 msg='Exception from DidRunUserStory: ') 126 msg='Exception from DidRunUserStory: ')
129 127
130 @decorators.Cache
131 def _UpdateUserStoryArchivesIfChanged(user_story_set):
132 # Scan every serving directory for .sha1 files
133 # and download them from Cloud Storage. Assume all data is public.
134 all_serving_dirs = user_story_set.serving_dirs.copy()
135 # Add individual page dirs to all serving dirs.
136 for user_story in user_story_set:
137 if isinstance(user_story, page_module.Page) and user_story.is_file:
138 all_serving_dirs.add(user_story.serving_dir)
139 # Scan all serving dirs.
140 for serving_dir in all_serving_dirs:
141 if os.path.splitdrive(serving_dir)[1] == '/':
142 raise ValueError('Trying to serve root directory from HTTP server.')
143 for dirpath, _, filenames in os.walk(serving_dir):
144 for filename in filenames:
145 path, extension = os.path.splitext(
146 os.path.join(dirpath, filename))
147 if extension != '.sha1':
148 continue
149 cloud_storage.GetIfChanged(path, user_story_set.bucket)
150
151
152 class UserStoryGroup(object): 128 class UserStoryGroup(object):
153 def __init__(self, shared_user_story_state_class): 129 def __init__(self, shared_user_story_state_class):
154 self._shared_user_story_state_class = shared_user_story_state_class 130 self._shared_user_story_state_class = shared_user_story_state_class
155 self._user_stories = [] 131 self._user_stories = []
156 132
157 @property 133 @property
158 def shared_user_story_state_class(self): 134 def shared_user_story_state_class(self):
159 return self._shared_user_story_state_class 135 return self._shared_user_story_state_class
160 136
161 @property 137 @property
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 """ 182 """
207 # TODO(slamm): Remove special-case for PageTest. https://crbug.com/440101 183 # TODO(slamm): Remove special-case for PageTest. https://crbug.com/440101
208 if isinstance(test, page_test.PageTest): 184 if isinstance(test, page_test.PageTest):
209 test.ValidatePageSet(user_story_set) 185 test.ValidatePageSet(user_story_set)
210 186
211 # Reorder page set based on options. 187 # Reorder page set based on options.
212 user_stories = _ShuffleAndFilterUserStorySet(user_story_set, finder_options) 188 user_stories = _ShuffleAndFilterUserStorySet(user_story_set, finder_options)
213 189
214 if (not finder_options.use_live_sites and user_story_set.bucket and 190 if (not finder_options.use_live_sites and user_story_set.bucket and
215 finder_options.browser_options.wpr_mode != wpr_modes.WPR_RECORD): 191 finder_options.browser_options.wpr_mode != wpr_modes.WPR_RECORD):
216 _UpdateUserStoryArchivesIfChanged(user_story_set) 192 serving_dirs = user_story_set.serving_dirs
193 for directory in serving_dirs:
194 cloud_storage.GetFilesInDirectoryIfChanged(directory,
195 user_story_set.bucket)
217 if not _UpdateAndCheckArchives( 196 if not _UpdateAndCheckArchives(
218 user_story_set.archive_data_file, user_story_set.wpr_archive_info, 197 user_story_set.archive_data_file, user_story_set.wpr_archive_info,
219 user_stories): 198 user_stories):
220 return 199 return
221 200
222 # TODO(slamm): Remove special-case for PageTest. https://crbug.com/440101 201 # TODO(slamm): Remove special-case for PageTest. https://crbug.com/440101
223 if isinstance(test, page_test.PageTest): 202 if isinstance(test, page_test.PageTest):
224 for user_story in list(user_stories): 203 for user_story in list(user_stories):
225 if not test.CanRunForPage(user_story): 204 if not test.CanRunForPage(user_story):
226 results.WillRunPage(user_story) 205 results.WillRunPage(user_story)
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 logging.warning('Device is thermally throttled before running ' 374 logging.warning('Device is thermally throttled before running '
396 'performance tests, results will vary.') 375 'performance tests, results will vary.')
397 376
398 377
399 def _CheckThermalThrottling(platform): 378 def _CheckThermalThrottling(platform):
400 if not platform.CanMonitorThermalThrottling(): 379 if not platform.CanMonitorThermalThrottling():
401 return 380 return
402 if platform.HasBeenThermallyThrottled(): 381 if platform.HasBeenThermallyThrottled():
403 logging.warning('Device has been thermally throttled during ' 382 logging.warning('Device has been thermally throttled during '
404 'performance tests, results will vary.') 383 'performance tests, results will vary.')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698