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

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

Issue 818053003: [Telemetry] Add test that make sure no two benchmarks have the same name (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 12 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 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 logging
7 import os 8 import os
8 import unittest 9 import unittest
10 from collections import defaultdict
9 11
10 from telemetry import benchmark as benchmark_module 12 from telemetry import benchmark as benchmark_module
11 from telemetry.core import browser_options 13 from telemetry.core import browser_options
12 from telemetry.core import discover 14 from telemetry.core import discover
13 from telemetry.unittest_util import progress_reporter 15 from telemetry.unittest_util import progress_reporter
14 16
15 17
16 def _GetPerfDir(*subdirs): 18 def _GetPerfDir(*subdirs):
17 perf_dir = os.path.dirname(os.path.dirname(__file__)) 19 perf_dir = os.path.dirname(os.path.dirname(__file__))
18 return os.path.join(perf_dir, *subdirs) 20 return os.path.join(perf_dir, *subdirs)
19 21
20 22
23 def _GetAllPerfBenchmarks():
24 return discover.DiscoverClasses(
25 _GetPerfDir('benchmarks'), _GetPerfDir(), benchmark_module.Benchmark,
26 index_by_class_name=True).values()
27
21 def _BenchmarkOptionsTestGenerator(benchmark): 28 def _BenchmarkOptionsTestGenerator(benchmark):
22 def testBenchmarkOptions(self): # pylint: disable=W0613 29 def testBenchmarkOptions(self): # pylint: disable=W0613
23 """Invalid options will raise benchmark.InvalidOptionsError.""" 30 """Invalid options will raise benchmark.InvalidOptionsError."""
24 options = browser_options.BrowserFinderOptions() 31 options = browser_options.BrowserFinderOptions()
25 parser = options.CreateParser() 32 parser = options.CreateParser()
26 benchmark.AddCommandLineArgs(parser) 33 benchmark.AddCommandLineArgs(parser)
27 benchmark_module.AddCommandLineArgs(parser) 34 benchmark_module.AddCommandLineArgs(parser)
28 benchmark.SetArgumentDefaults(parser) 35 benchmark.SetArgumentDefaults(parser)
29 return testBenchmarkOptions 36 return testBenchmarkOptions
30 37
31 38
39 class TestNoBenchmarkNamesDuplication(unittest.TestCase):
40 def runTest(self):
41 all_benchmarks = _GetAllPerfBenchmarks()
42 names_to_benchmarks = defaultdict(list)
43 for b in all_benchmarks:
44 names_to_benchmarks[b.Name()].append(b)
45 for n in names_to_benchmarks:
46 self.assertEquals(1, len(names_to_benchmarks[n]),
47 'Multiple benchmarks with the same name %s are '
48 'found: %s' % (n, str(names_to_benchmarks[n])))
49
50
32 def _AddBenchmarkOptionsTests(suite): 51 def _AddBenchmarkOptionsTests(suite):
33 # Using |index_by_class_name=True| allows returning multiple benchmarks 52 # Using |index_by_class_name=True| allows returning multiple benchmarks
34 # from a module. 53 # from a module.
35 all_benchmarks = discover.DiscoverClasses( 54 all_benchmarks = _GetAllPerfBenchmarks()
36 _GetPerfDir('benchmarks'), _GetPerfDir(), benchmark_module.Benchmark,
37 index_by_class_name=True).values()
38 for benchmark in all_benchmarks: 55 for benchmark in all_benchmarks:
39 if not benchmark.options: 56 if not benchmark.options:
40 # No need to test benchmarks that have not defined options. 57 # No need to test benchmarks that have not defined options.
41 continue 58 continue
42 class BenchmarkOptionsTest(unittest.TestCase): 59 class BenchmarkOptionsTest(unittest.TestCase):
43 pass 60 pass
44 setattr(BenchmarkOptionsTest, benchmark.Name(), 61 setattr(BenchmarkOptionsTest, benchmark.Name(),
45 _BenchmarkOptionsTestGenerator(benchmark)) 62 _BenchmarkOptionsTestGenerator(benchmark))
46 suite.addTest(BenchmarkOptionsTest(benchmark.Name())) 63 suite.addTest(BenchmarkOptionsTest(benchmark.Name()))
64 suite.addTest(TestNoBenchmarkNamesDuplication())
47 65
48 66
49 def load_tests(_, _2, _3): 67 def load_tests(_, _2, _3):
50 suite = progress_reporter.TestSuite() 68 suite = progress_reporter.TestSuite()
51 _AddBenchmarkOptionsTests(suite) 69 _AddBenchmarkOptionsTests(suite)
52 return suite 70 return suite
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