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

Side by Side Diff: tools/telemetry/telemetry/benchmark_runner.py

Issue 659673002: telemetry: Remove PageTest support from benchmark_runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 """Parses the command line, discovers the appropriate tests, and runs them. 5 """Parses the command line, discovers the appropriate tests, and runs them.
6 6
7 Handles test configuration, but all the logic for 7 Handles test configuration, but all the logic for
8 actually running the test is in Test and PageRunner.""" 8 actually running the test is in Test and PageRunner."""
9 9
10 import hashlib 10 import hashlib
11 import inspect 11 import inspect
12 import json 12 import json
13 import os 13 import os
14 import sys 14 import sys
15 15
16 from telemetry import benchmark 16 from telemetry import benchmark
17 from telemetry import decorators 17 from telemetry import decorators
18 from telemetry.core import browser_finder 18 from telemetry.core import browser_finder
19 from telemetry.core import browser_options 19 from telemetry.core import browser_options
20 from telemetry.core import command_line 20 from telemetry.core import command_line
21 from telemetry.core import discover 21 from telemetry.core import discover
22 from telemetry.core import environment 22 from telemetry.core import environment
23 from telemetry.core import util 23 from telemetry.core import util
24 from telemetry.page import page_set 24 from telemetry.page import page_set
25 from telemetry.page import page_test
26 from telemetry.page import profile_creator
27 from telemetry.util import find_dependencies 25 from telemetry.util import find_dependencies
28 26
29 27
30 class Deps(find_dependencies.FindDependenciesCommand): 28 class Deps(find_dependencies.FindDependenciesCommand):
31 """Prints all dependencies""" 29 """Prints all dependencies"""
32 30
33 def Run(self, args): 31 def Run(self, args):
34 main_module = sys.modules['__main__'] 32 main_module = sys.modules['__main__']
35 args.positional_args.append(os.path.realpath(main_module.__file__)) 33 args.positional_args.append(os.path.realpath(main_module.__file__))
36 return super(Deps, self).Run(args) 34 return super(Deps, self).Run(args)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 f.write(_GetJsonTestList(possible_browser, possible_reference_browser, 97 f.write(_GetJsonTestList(possible_browser, possible_reference_browser,
100 args.tests, args.num_shards)) 98 args.tests, args.num_shards))
101 else: 99 else:
102 _PrintTestList(args.tests) 100 _PrintTestList(args.tests)
103 return 0 101 return 0
104 102
105 103
106 class Run(command_line.OptparseCommand): 104 class Run(command_line.OptparseCommand):
107 """Run one or more tests (default)""" 105 """Run one or more tests (default)"""
108 106
109 usage = 'test_name [page_set] [<options>]' 107 usage = 'test_name [page_set] [<options>]'
nednguyen 2014/10/16 02:25:31 Remove [page_set]. I would also change the word "t
110 108
111 @classmethod 109 @classmethod
112 def CreateParser(cls): 110 def CreateParser(cls):
113 options = browser_options.BrowserFinderOptions() 111 options = browser_options.BrowserFinderOptions()
114 parser = options.CreateParser('%%prog %s %s' % (cls.Name(), cls.usage)) 112 parser = options.CreateParser('%%prog %s %s' % (cls.Name(), cls.usage))
115 return parser 113 return parser
116 114
117 @classmethod 115 @classmethod
118 def AddCommandLineArgs(cls, parser): 116 def AddCommandLineArgs(cls, parser):
119 benchmark.AddCommandLineArgs(parser) 117 benchmark.AddCommandLineArgs(parser)
(...skipping 26 matching lines...) Expand all
146 sys.exit(-1) 144 sys.exit(-1)
147 145
148 if len(matching_tests) > 1: 146 if len(matching_tests) > 1:
149 print >> sys.stderr, 'Multiple tests named "%s".' % input_test_name 147 print >> sys.stderr, 'Multiple tests named "%s".' % input_test_name
150 print >> sys.stderr, 'Did you mean one of these?' 148 print >> sys.stderr, 'Did you mean one of these?'
151 print >> sys.stderr 149 print >> sys.stderr
152 _PrintTestList(matching_tests) 150 _PrintTestList(matching_tests)
153 sys.exit(-1) 151 sys.exit(-1)
154 152
155 test_class = matching_tests.pop() 153 test_class = matching_tests.pop()
156 if issubclass(test_class, page_test.PageTest): 154 if len(args.positional_args) > 1:
157 if len(args.positional_args) < 2: 155 parser.error('Too many arguments.')
158 parser.error('Need to specify a page set for "%s".' % test_class.Name())
159 if len(args.positional_args) > 2:
160 parser.error('Too many arguments.')
161 page_set_name = args.positional_args[1]
162 page_set_class = _MatchPageSetName(page_set_name)
163 if page_set_class is None:
164 parser.error("Page set %s not found. Available sets:\n%s" %
165 (page_set_name, _AvailablePageSetNamesString()))
166
167 class TestWrapper(benchmark.Benchmark):
168 test = test_class
169
170 @classmethod
171 def CreatePageSet(cls, options):
172 return page_set_class()
173
174 test_class = TestWrapper
175 else:
176 if len(args.positional_args) > 1:
177 parser.error('Too many arguments.')
178 156
179 assert issubclass(test_class, benchmark.Benchmark), ( 157 assert issubclass(test_class, benchmark.Benchmark), (
180 'Trying to run a non-Benchmark?!') 158 'Trying to run a non-Benchmark?!')
181 159
182 benchmark.ProcessCommandLineArgs(parser, args) 160 benchmark.ProcessCommandLineArgs(parser, args)
183 test_class.ProcessCommandLineArgs(parser, args) 161 test_class.ProcessCommandLineArgs(parser, args)
184 162
185 cls._test = test_class 163 cls._test = test_class
186 164
187 def Run(self, args): 165 def Run(self, args):
(...skipping 11 matching lines...) Expand all
199 continue 177 continue
200 if not issubclass(cls, command_line.Command): 178 if not issubclass(cls, command_line.Command):
201 continue 179 continue
202 yield cls 180 yield cls
203 181
204 def _MatchingCommands(string): 182 def _MatchingCommands(string):
205 return [command for command in _Commands() 183 return [command for command in _Commands()
206 if command.Name().startswith(string)] 184 if command.Name().startswith(string)]
207 185
208 @decorators.Cache 186 @decorators.Cache
209 def _Tests(): 187 def _Tests():
nednguyen 2014/10/16 02:25:31 s/_Tests/_Benchmarks.
ernstm 2014/10/16 17:54:28 Done.
210 tests = [] 188 tests = []
211 for base_dir in config.base_paths: 189 for base_dir in config.base_paths:
212 tests += discover.DiscoverClasses(base_dir, base_dir, benchmark.Benchmark, 190 tests += discover.DiscoverClasses(base_dir, base_dir, benchmark.Benchmark,
213 index_by_class_name=True).values() 191 index_by_class_name=True).values()
214 page_tests = discover.DiscoverClasses(base_dir, base_dir,
215 page_test.PageTest,
216 index_by_class_name=True).values()
217 tests += [test_class for test_class in page_tests
218 if not issubclass(test_class, profile_creator.ProfileCreator)]
219 return tests 192 return tests
220 193
221 194
222 # TODO(ariblue): Use discover.py's abstracted _MatchName class (in pending CL 195 # TODO(ariblue): Use discover.py's abstracted _MatchName class (in pending CL
223 # 432543003) and eliminate _MatchPageSetName and _MatchTestName. 196 # 432543003) and eliminate _MatchPageSetName and _MatchTestName.
224 def _MatchPageSetName(input_name): 197 def _MatchPageSetName(input_name):
nednguyen 2014/10/16 02:25:31 Remove this?
ernstm 2014/10/16 17:54:28 Done.
225 page_sets = [] 198 page_sets = []
226 for base_dir in config.base_paths: 199 for base_dir in config.base_paths:
227 page_sets += discover.DiscoverClasses(base_dir, base_dir, page_set.PageSet, 200 page_sets += discover.DiscoverClasses(base_dir, base_dir, page_set.PageSet,
228 index_by_class_name=True).values() 201 index_by_class_name=True).values()
229 for p in page_sets: 202 for p in page_sets:
230 if input_name == p.Name(): 203 if input_name == p.Name():
231 return p 204 return p
232 return None 205 return None
233 206
234 207
235 def _AvailablePageSetNamesString(): 208 def _AvailablePageSetNamesString():
nednguyen 2014/10/16 02:25:31 Dead code.
ernstm 2014/10/16 17:54:28 Done.
236 result = "" 209 result = ""
237 for base_dir in config.base_paths: 210 for base_dir in config.base_paths:
238 for p in discover.DiscoverClasses(base_dir, base_dir, page_set.PageSet, 211 for p in discover.DiscoverClasses(base_dir, base_dir, page_set.PageSet,
239 index_by_class_name=True).values(): 212 index_by_class_name=True).values():
240 result += p.Name() + "\n" 213 result += p.Name() + "\n"
241 return result 214 return result
242 215
243 216
244 def _MatchTestName(input_test_name, exact_matches=True): 217 def _MatchTestName(input_test_name, exact_matches=True):
nednguyen 2014/10/16 02:25:31 _MatchBenchmarkName
ernstm 2014/10/16 17:54:28 Done.
245 def _Matches(input_string, search_string): 218 def _Matches(input_string, search_string):
246 if search_string.startswith(input_string): 219 if search_string.startswith(input_string):
247 return True 220 return True
248 for part in search_string.split('.'): 221 for part in search_string.split('.'):
249 if part.startswith(input_string): 222 if part.startswith(input_string):
250 return True 223 return True
251 return False 224 return False
252 225
253 # Exact matching. 226 # Exact matching.
254 if exact_matches: 227 if exact_matches:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 307
335 filtered_tests = [test_class for test_class in tests 308 filtered_tests = [test_class for test_class in tests
336 if issubclass(test_class, benchmark.Benchmark)] 309 if issubclass(test_class, benchmark.Benchmark)]
337 if filtered_tests: 310 if filtered_tests:
338 print >> sys.stderr, 'Available tests are:' 311 print >> sys.stderr, 'Available tests are:'
339 for test_class in sorted(filtered_tests, key=lambda t: t.Name()): 312 for test_class in sorted(filtered_tests, key=lambda t: t.Name()):
340 print >> sys.stderr, format_string % ( 313 print >> sys.stderr, format_string % (
341 test_class.Name(), test_class.Description()) 314 test_class.Name(), test_class.Description())
342 print >> sys.stderr 315 print >> sys.stderr
343 316
344 filtered_tests = [test_class for test_class in tests
345 if issubclass(test_class, page_test.PageTest)]
346 if filtered_tests:
347 print >> sys.stderr, 'Available page tests are:'
348 for test_class in sorted(filtered_tests, key=lambda t: t.Name()):
349 print >> sys.stderr, format_string % (
350 test_class.Name(), test_class.Description())
351 print >> sys.stderr
352
353 317
354 config = environment.Environment([util.GetBaseDir()]) 318 config = environment.Environment([util.GetBaseDir()])
355 319
356 320
357 def main(): 321 def main():
358 # Get the command name from the command line. 322 # Get the command name from the command line.
359 if len(sys.argv) > 1 and sys.argv[1] == '--help': 323 if len(sys.argv) > 1 and sys.argv[1] == '--help':
360 sys.argv[1] = 'help' 324 sys.argv[1] = 'help'
361 325
362 command_name = 'run' 326 command_name = 'run'
(...skipping 18 matching lines...) Expand all
381 345
382 # Parse and run the command. 346 # Parse and run the command.
383 parser = command.CreateParser() 347 parser = command.CreateParser()
384 command.AddCommandLineArgs(parser) 348 command.AddCommandLineArgs(parser)
385 options, args = parser.parse_args() 349 options, args = parser.parse_args()
386 if commands: 350 if commands:
387 args = args[1:] 351 args = args[1:]
388 options.positional_args = args 352 options.positional_args = args
389 command.ProcessCommandLineArgs(parser, options) 353 command.ProcessCommandLineArgs(parser, options)
390 return command().Run(options) 354 return command().Run(options)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698