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
3 # found in the LICENSE file.
5 """For all the benchmarks that set options, test that the options are valid."""
10 from telemetry
import benchmark
as benchmark_module
11 from telemetry
.core
import browser_options
12 from telemetry
.core
import discover
13 from telemetry
.unittest_util
import progress_reporter
16 def _GetPerfDir(*subdirs
):
17 perf_dir
= os
.path
.dirname(os
.path
.dirname(__file__
))
18 return os
.path
.join(perf_dir
, *subdirs
)
21 def _BenchmarkOptionsTestGenerator(benchmark
):
22 def testBenchmarkOptions(self
): # pylint: disable=W0613
23 """Invalid options will raise benchmark.InvalidOptionsError."""
24 options
= browser_options
.BrowserFinderOptions()
25 parser
= options
.CreateParser()
26 benchmark
.AddCommandLineArgs(parser
)
27 benchmark_module
.AddCommandLineArgs(parser
)
28 benchmark
.SetArgumentDefaults(parser
)
29 return testBenchmarkOptions
32 def _AddBenchmarkOptionsTests(suite
):
33 # Using |index_by_class_name=True| allows returning multiple benchmarks
35 all_benchmarks
= discover
.DiscoverClasses(
36 _GetPerfDir('benchmarks'), _GetPerfDir(), benchmark_module
.Benchmark
,
37 index_by_class_name
=True).values()
38 for benchmark
in all_benchmarks
:
39 if not benchmark
.options
:
40 # No need to test benchmarks that have not defined options.
42 class BenchmarkOptionsTest(unittest
.TestCase
):
44 setattr(BenchmarkOptionsTest
, benchmark
.Name(),
45 _BenchmarkOptionsTestGenerator(benchmark
))
46 suite
.addTest(BenchmarkOptionsTest(benchmark
.Name()))
49 def load_tests(_
, _2
, _3
):
50 suite
= progress_reporter
.TestSuite()
51 _AddBenchmarkOptionsTests(suite
)