OLD | NEW |
---|---|
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 logging |
8 import os | 8 import os |
9 import unittest | 9 import unittest |
10 from collections import defaultdict | 10 from collections import defaultdict |
(...skipping 29 matching lines...) Expand all Loading... | |
40 def runTest(self): | 40 def runTest(self): |
41 all_benchmarks = _GetAllPerfBenchmarks() | 41 all_benchmarks = _GetAllPerfBenchmarks() |
42 names_to_benchmarks = defaultdict(list) | 42 names_to_benchmarks = defaultdict(list) |
43 for b in all_benchmarks: | 43 for b in all_benchmarks: |
44 names_to_benchmarks[b.Name()].append(b) | 44 names_to_benchmarks[b.Name()].append(b) |
45 for n in names_to_benchmarks: | 45 for n in names_to_benchmarks: |
46 self.assertEquals(1, len(names_to_benchmarks[n]), | 46 self.assertEquals(1, len(names_to_benchmarks[n]), |
47 'Multiple benchmarks with the same name %s are ' | 47 'Multiple benchmarks with the same name %s are ' |
48 'found: %s' % (n, str(names_to_benchmarks[n]))) | 48 'found: %s' % (n, str(names_to_benchmarks[n]))) |
49 | 49 |
50 # Test all perf benchmarks explicitly define the Name() method and the name | |
51 # values are the same as the default one. | |
52 # TODO(nednguyen): remove this test after all perf benchmarks define Name() and | |
53 # checked in. | |
54 class TestPerfBenchmarkNames(unittest.TestCase): | |
dtu
2015/01/15 21:27:23
Do you even want to check in this check? Just runn
| |
55 def runTest(self): | |
56 all_benchmarks = _GetAllPerfBenchmarks() | |
57 | |
58 def BenchmarkName(cls): # Copy from Benchmark.Name()'s implementation | |
59 name = cls.__module__.split('.')[-1] | |
60 if hasattr(cls, 'tag'): | |
61 name += '.' + cls.tag | |
62 if hasattr(cls, 'page_set'): | |
63 name += '.' + cls.page_set.Name() | |
64 return name | |
65 | |
66 for b in all_benchmarks: | |
67 self.assertNotEquals(b.Name, benchmark_module.Benchmark.Name) | |
68 self.assertEquals(b.Name(), BenchmarkName(b)) | |
69 | |
50 | 70 |
51 def _AddBenchmarkOptionsTests(suite): | 71 def _AddBenchmarkOptionsTests(suite): |
52 # Using |index_by_class_name=True| allows returning multiple benchmarks | 72 # Using |index_by_class_name=True| allows returning multiple benchmarks |
53 # from a module. | 73 # from a module. |
54 all_benchmarks = _GetAllPerfBenchmarks() | 74 all_benchmarks = _GetAllPerfBenchmarks() |
55 for benchmark in all_benchmarks: | 75 for benchmark in all_benchmarks: |
56 if not benchmark.options: | 76 if not benchmark.options: |
57 # No need to test benchmarks that have not defined options. | 77 # No need to test benchmarks that have not defined options. |
58 continue | 78 continue |
59 class BenchmarkOptionsTest(unittest.TestCase): | 79 class BenchmarkOptionsTest(unittest.TestCase): |
60 pass | 80 pass |
61 setattr(BenchmarkOptionsTest, benchmark.Name(), | 81 setattr(BenchmarkOptionsTest, benchmark.Name(), |
62 _BenchmarkOptionsTestGenerator(benchmark)) | 82 _BenchmarkOptionsTestGenerator(benchmark)) |
63 suite.addTest(BenchmarkOptionsTest(benchmark.Name())) | 83 suite.addTest(BenchmarkOptionsTest(benchmark.Name())) |
64 suite.addTest(TestNoBenchmarkNamesDuplication()) | 84 suite.addTest(TestNoBenchmarkNamesDuplication()) |
85 suite.addTest(TestPerfBenchmarkNames()) | |
65 | 86 |
66 | 87 |
67 def load_tests(_, _2, _3): | 88 def load_tests(_, _2, _3): |
68 suite = progress_reporter.TestSuite() | 89 suite = progress_reporter.TestSuite() |
69 _AddBenchmarkOptionsTests(suite) | 90 _AddBenchmarkOptionsTests(suite) |
70 return suite | 91 return suite |
OLD | NEW |