Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / tools / perf / benchmarks / benchmark_unittest.py
blob22a4db76cd6a8c348ea1a33d7d9620ca85e52d1c
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."""
7 import os
8 import unittest
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
34 # from a module.
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.
41 continue
42 class BenchmarkOptionsTest(unittest.TestCase):
43 pass
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)
52 return suite