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

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

Issue 1108993004: Move user_story.shared_user_story_state to story.shared_state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rename_user_story
Patch Set: Created 5 years, 7 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 sys 8 import sys
9 import time 9 import time
10 10
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 try: 105 try:
106 state.DidRunUserStory(results) 106 state.DidRunUserStory(results)
107 except Exception: 107 except Exception:
108 if not has_existing_exception: 108 if not has_existing_exception:
109 raise 109 raise
110 # Print current exception and propagate existing exception. 110 # Print current exception and propagate existing exception.
111 exception_formatter.PrintFormattedException( 111 exception_formatter.PrintFormattedException(
112 msg='Exception from DidRunUserStory: ') 112 msg='Exception from DidRunUserStory: ')
113 113
114 class UserStoryGroup(object): 114 class UserStoryGroup(object):
115 def __init__(self, shared_user_story_state_class): 115 def __init__(self, shared_state_class):
116 self._shared_user_story_state_class = shared_user_story_state_class 116 self._shared_state_class = shared_state_class
117 self._user_stories = [] 117 self._user_stories = []
118 118
119 @property 119 @property
120 def shared_user_story_state_class(self): 120 def shared_state_class(self):
121 return self._shared_user_story_state_class 121 return self._shared_state_class
122 122
123 @property 123 @property
124 def user_stories(self): 124 def user_stories(self):
125 return self._user_stories 125 return self._user_stories
126 126
127 def AddUserStory(self, user_story): 127 def AddUserStory(self, user_story):
128 assert (user_story.shared_user_story_state_class is 128 assert (user_story.shared_state_class is
129 self._shared_user_story_state_class) 129 self._shared_state_class)
130 self._user_stories.append(user_story) 130 self._user_stories.append(user_story)
131 131
132 132
133 def StoriesGroupedByStateClass(user_story_set, allow_multiple_groups): 133 def StoriesGroupedByStateClass(user_story_set, allow_multiple_groups):
134 """ Returns a list of user story groups which each contains user stories with 134 """ Returns a list of user story groups which each contains user stories with
135 the same shared_user_story_state_class. 135 the same shared_state_class.
136 136
137 Example: 137 Example:
138 Assume A1, A2, A3 are user stories with same shared user story class, and 138 Assume A1, A2, A3 are user stories with same shared user story class, and
139 similar for B1, B2. 139 similar for B1, B2.
140 If their orders in user story set is A1 A2 B1 B2 A3, then the grouping will 140 If their orders in user story set is A1 A2 B1 B2 A3, then the grouping will
141 be [A1 A2] [B1 B2] [A3]. 141 be [A1 A2] [B1 B2] [A3].
142 142
143 It's purposefully done this way to make sure that order of user 143 It's purposefully done this way to make sure that order of user
144 stories are the same of that defined in user_story_set. It's recommended that 144 stories are the same of that defined in user_story_set. It's recommended that
145 user stories with the same states should be arranged next to each others in 145 user stories with the same states should be arranged next to each others in
146 user story sets to reduce the overhead of setting up & tearing down the 146 user story sets to reduce the overhead of setting up & tearing down the
147 shared user story state. 147 shared user story state.
148 """ 148 """
149 user_story_groups = [] 149 user_story_groups = []
150 user_story_groups.append( 150 user_story_groups.append(
151 UserStoryGroup(user_story_set[0].shared_user_story_state_class)) 151 UserStoryGroup(user_story_set[0].shared_state_class))
152 for user_story in user_story_set: 152 for user_story in user_story_set:
153 if (user_story.shared_user_story_state_class is not 153 if (user_story.shared_state_class is not
154 user_story_groups[-1].shared_user_story_state_class): 154 user_story_groups[-1].shared_state_class):
155 if not allow_multiple_groups: 155 if not allow_multiple_groups:
156 raise ValueError('This UserStorySet is only allowed to have one ' 156 raise ValueError('This UserStorySet is only allowed to have one '
157 'SharedUserStoryState but contains the following ' 157 'SharedState but contains the following '
158 'SharedUserStoryState classes: %s, %s.\n Either ' 158 'SharedState classes: %s, %s.\n Either '
159 'remove the extra SharedUserStoryStates or override ' 159 'remove the extra SharedStates or override '
160 'allow_mixed_story_states.' % ( 160 'allow_mixed_story_states.' % (
161 user_story_groups[-1].shared_user_story_state_class, 161 user_story_groups[-1].shared_state_class,
162 user_story.shared_user_story_state_class)) 162 user_story.shared_state_class))
163 user_story_groups.append( 163 user_story_groups.append(
164 UserStoryGroup(user_story.shared_user_story_state_class)) 164 UserStoryGroup(user_story.shared_state_class))
165 user_story_groups[-1].AddUserStory(user_story) 165 user_story_groups[-1].AddUserStory(user_story)
166 return user_story_groups 166 return user_story_groups
167 167
168 168
169 def Run(test, user_story_set, expectations, finder_options, results, 169 def Run(test, user_story_set, expectations, finder_options, results,
170 max_failures=None): 170 max_failures=None):
171 """Runs a given test against a given page_set with the given options. 171 """Runs a given test against a given page_set with the given options.
172 172
173 Stop execution for unexpected exceptions such as KeyboardInterrupt. 173 Stop execution for unexpected exceptions such as KeyboardInterrupt.
174 We "white list" certain exceptions for which the user story runner 174 We "white list" certain exceptions for which the user story runner
(...skipping 26 matching lines...) Expand all
201 user_stories, 201 user_stories,
202 user_story_set.allow_mixed_story_states) 202 user_story_set.allow_mixed_story_states)
203 203
204 for group in user_story_groups: 204 for group in user_story_groups:
205 state = None 205 state = None
206 try: 206 try:
207 for _ in xrange(finder_options.pageset_repeat): 207 for _ in xrange(finder_options.pageset_repeat):
208 for user_story in group.user_stories: 208 for user_story in group.user_stories:
209 for _ in xrange(finder_options.page_repeat): 209 for _ in xrange(finder_options.page_repeat):
210 if not state: 210 if not state:
211 state = group.shared_user_story_state_class( 211 state = group.shared_state_class(
212 test, finder_options, user_story_set) 212 test, finder_options, user_story_set)
213 results.WillRunPage(user_story) 213 results.WillRunPage(user_story)
214 try: 214 try:
215 _WaitForThermalThrottlingIfNeeded(state.platform) 215 _WaitForThermalThrottlingIfNeeded(state.platform)
216 _RunUserStoryAndProcessErrorIfNeeded( 216 _RunUserStoryAndProcessErrorIfNeeded(
217 expectations, user_story, results, state) 217 expectations, user_story, results, state)
218 except exceptions.Error: 218 except exceptions.Error:
219 # Catch all Telemetry errors to give the story a chance to retry. 219 # Catch all Telemetry errors to give the story a chance to retry.
220 # The retry is enabled by tearing down the state and creating 220 # The retry is enabled by tearing down the state and creating
221 # a new state instance in the next iteration. 221 # a new state instance in the next iteration.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 logging.warning('Device is thermally throttled before running ' 332 logging.warning('Device is thermally throttled before running '
333 'performance tests, results will vary.') 333 'performance tests, results will vary.')
334 334
335 335
336 def _CheckThermalThrottling(platform): 336 def _CheckThermalThrottling(platform):
337 if not platform.CanMonitorThermalThrottling(): 337 if not platform.CanMonitorThermalThrottling():
338 return 338 return
339 if platform.HasBeenThermallyThrottled(): 339 if platform.HasBeenThermallyThrottled():
340 logging.warning('Device has been thermally throttled during ' 340 logging.warning('Device has been thermally throttled during '
341 'performance tests, results will vary.') 341 'performance tests, results will vary.')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698