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

Side by Side Diff: tools/perf/benchmarks/benchmark_unittest.py

Issue 641823004: telemetry: Allow page tests to be configured via constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Add debug output to figure out why pixel tests fail on bots. Created 6 years, 1 month 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 """For all the benchmarks that set options, test that the options are valid.""" 5 """For all the benchmarks that set options, test that the options are valid."""
6 6
7 import os 7 import os
8 import unittest 8 import unittest
9 9
10 from telemetry import benchmark as benchmark_module 10 from telemetry import benchmark as benchmark_module
11 from telemetry.core import browser_options 11 from telemetry.core import browser_options
12 from telemetry.core import discover 12 from telemetry.core import discover
13 from telemetry.unittest import progress_reporter 13 from telemetry.unittest import progress_reporter
14 14
15 15
16 def _GetPerfDir(*subdirs): 16 def _GetPerfDir(*subdirs):
17 perf_dir = os.path.dirname(os.path.dirname(__file__)) 17 perf_dir = os.path.dirname(os.path.dirname(__file__))
18 return os.path.join(perf_dir, *subdirs) 18 return os.path.join(perf_dir, *subdirs)
19 19
20 20
21 def _BenchmarkOptionsTestGenerator(benchmark): 21 def _BenchmarkOptionsTestGenerator(benchmark_class):
22 def testBenchmarkOptions(self): # pylint: disable=W0613 22 def testBenchmarkOptions(self): # pylint: disable=W0613
23 """Invalid options will raise benchmark.InvalidOptionsError.""" 23 """Invalid options will raise benchmark.InvalidOptionsError."""
24 options = browser_options.BrowserFinderOptions() 24 options = browser_options.BrowserFinderOptions()
25 parser = options.CreateParser() 25 parser = options.CreateParser()
26 benchmark = benchmark_class()
26 benchmark.AddCommandLineArgs(parser) 27 benchmark.AddCommandLineArgs(parser)
27 benchmark_module.AddCommandLineArgs(parser) 28 benchmark_module.AddCommandLineArgs(parser)
28 benchmark.SetArgumentDefaults(parser) 29 benchmark.SetArgumentDefaults(parser)
29 return testBenchmarkOptions 30 return testBenchmarkOptions
30 31
31 32
32 def _AddBenchmarkOptionsTests(suite): 33 def _AddBenchmarkOptionsTests(suite):
33 # Using |index_by_class_name=True| allows returning multiple benchmarks 34 # Using |index_by_class_name=True| allows returning multiple benchmarks
34 # from a module. 35 # from a module.
35 all_benchmarks = discover.DiscoverClasses( 36 all_benchmarks = discover.DiscoverClasses(
36 _GetPerfDir('benchmarks'), _GetPerfDir(), benchmark_module.Benchmark, 37 _GetPerfDir('benchmarks'), _GetPerfDir(), benchmark_module.Benchmark,
37 index_by_class_name=True).values() 38 index_by_class_name=True).values()
38 for benchmark in all_benchmarks: 39 for benchmark in all_benchmarks:
39 if not benchmark.options: 40 if not benchmark.options:
40 # No need to test benchmarks that have not defined options. 41 # No need to test benchmarks that have not defined options.
41 continue 42 continue
42 class BenchmarkOptionsTest(unittest.TestCase): 43 class BenchmarkOptionsTest(unittest.TestCase):
43 pass 44 pass
44 setattr(BenchmarkOptionsTest, benchmark.Name(), 45 setattr(BenchmarkOptionsTest, benchmark.Name(),
45 _BenchmarkOptionsTestGenerator(benchmark)) 46 _BenchmarkOptionsTestGenerator(benchmark))
46 suite.addTest(BenchmarkOptionsTest(benchmark.Name())) 47 suite.addTest(BenchmarkOptionsTest(benchmark.Name()))
47 48
48 49
49 def load_tests(_, _2, _3): 50 def load_tests(_, _2, _3):
50 suite = progress_reporter.TestSuite() 51 suite = progress_reporter.TestSuite()
51 _AddBenchmarkOptionsTests(suite) 52 _AddBenchmarkOptionsTests(suite)
52 return suite 53 return suite
OLDNEW
« no previous file with comments | « tools/perf/benchmarks/benchmark_smoke_unittest.py ('k') | tools/perf/measurements/page_cycler.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698