Chromium Code Reviews| 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 from collections import defaultdict | 7 from collections import defaultdict |
| 8 import os | 8 import os |
| 9 import unittest | 9 import unittest |
| 10 import sys | |
|
petrcermak
2016/08/03 08:49:27
nit: sort order ('s' < 'u')
nednguyen
2016/08/03 15:41:36
Done.
| |
| 10 | 11 |
| 12 from benchmarks import system_health | |
|
petrcermak
2016/08/03 08:49:27
nit: I would probably do `from benchmarks import s
nednguyen
2016/08/03 15:41:36
Done.
| |
| 13 from page_sets.system_health import system_health_stories | |
|
petrcermak
2016/08/03 08:49:26
nit: sort order ('b' < 'c' < 'p'). If you want to
nednguyen
2016/08/03 15:41:36
Done.
| |
| 11 from core import perf_benchmark | 14 from core import perf_benchmark |
| 12 | 15 |
| 13 from telemetry import benchmark as benchmark_module | 16 from telemetry import benchmark as benchmark_module |
| 14 from telemetry.core import discover | 17 from telemetry.core import discover |
| 15 from telemetry.internal.browser import browser_options | 18 from telemetry.internal.browser import browser_options |
| 16 from telemetry.testing import progress_reporter | 19 from telemetry.testing import progress_reporter |
| 17 | 20 |
| 18 | 21 |
| 19 def _GetPerfDir(*subdirs): | 22 def _GetPerfDir(*subdirs): |
| 20 perf_dir = os.path.dirname(os.path.dirname(__file__)) | 23 perf_dir = os.path.dirname(os.path.dirname(__file__)) |
| 21 return os.path.join(perf_dir, *subdirs) | 24 return os.path.join(perf_dir, *subdirs) |
| 22 | 25 |
| 23 | 26 |
| 24 def _GetAllPerfBenchmarks(): | 27 def _GetAllPerfBenchmarks(): |
| 25 return discover.DiscoverClasses( | 28 return discover.DiscoverClasses( |
| 26 _GetPerfDir('benchmarks'), _GetPerfDir(), benchmark_module.Benchmark, | 29 _GetPerfDir('benchmarks'), _GetPerfDir(), benchmark_module.Benchmark, |
| 27 index_by_class_name=True).values() | 30 index_by_class_name=True).values() |
| 28 | 31 |
| 29 | 32 |
| 33 def _GetAllSystemHealthBenchmarks(): | |
| 34 return [b for b in _GetAllPerfBenchmarks() if | |
| 35 sys.modules[b.__module__] == system_health] | |
| 36 | |
| 37 | |
| 30 def _BenchmarkOptionsTestGenerator(benchmark): | 38 def _BenchmarkOptionsTestGenerator(benchmark): |
| 31 def testBenchmarkOptions(self): # pylint: disable=unused-argument | 39 def testBenchmarkOptions(self): # pylint: disable=unused-argument |
| 32 """Invalid options will raise benchmark.InvalidOptionsError.""" | 40 """Invalid options will raise benchmark.InvalidOptionsError.""" |
| 33 options = browser_options.BrowserFinderOptions() | 41 options = browser_options.BrowserFinderOptions() |
| 34 parser = options.CreateParser() | 42 parser = options.CreateParser() |
| 35 benchmark.AddCommandLineArgs(parser) | 43 benchmark.AddCommandLineArgs(parser) |
| 36 benchmark_module.AddCommandLineArgs(parser) | 44 benchmark_module.AddCommandLineArgs(parser) |
| 37 benchmark.SetArgumentDefaults(parser) | 45 benchmark.SetArgumentDefaults(parser) |
| 38 return testBenchmarkOptions | 46 return testBenchmarkOptions |
| 39 | 47 |
| 40 | 48 |
| 41 class TestNoBenchmarkNamesDuplication(unittest.TestCase): | 49 class TestNoBenchmarkNamesDuplication(unittest.TestCase): |
| 42 | 50 |
| 43 def runTest(self): | 51 def runTest(self): |
| 44 all_benchmarks = _GetAllPerfBenchmarks() | 52 all_benchmarks = _GetAllPerfBenchmarks() |
| 45 names_to_benchmarks = defaultdict(list) | 53 names_to_benchmarks = defaultdict(list) |
| 46 for b in all_benchmarks: | 54 for b in all_benchmarks: |
| 47 names_to_benchmarks[b.Name()].append(b) | 55 names_to_benchmarks[b.Name()].append(b) |
| 48 for n in names_to_benchmarks: | 56 for n in names_to_benchmarks: |
| 49 self.assertEquals(1, len(names_to_benchmarks[n]), | 57 self.assertEquals(1, len(names_to_benchmarks[n]), |
| 50 'Multiple benchmarks with the same name %s are ' | 58 'Multiple benchmarks with the same name %s are ' |
| 51 'found: %s' % (n, str(names_to_benchmarks[n]))) | 59 'found: %s' % (n, str(names_to_benchmarks[n]))) |
| 52 | 60 |
| 53 | 61 |
| 62 class TestSystemHealthBenchmarks(unittest.TestCase): | |
| 63 | |
| 64 def testNaming(self): | |
| 65 for s in _GetAllSystemHealthBenchmarks(): | |
|
petrcermak
2016/08/03 08:49:27
nit: could you change the variable to |b| as well
nednguyen
2016/08/03 15:41:36
Done.
| |
| 66 self.assertTrue( | |
| 67 s.Name().startswith('system_health.'), | |
| 68 '%s must have name started with "system_health." prefix') | |
|
petrcermak
2016/08/03 08:49:26
you forgot to add `% s`
petrcermak
2016/08/03 08:49:27
also, I wonder whether '%r' wouldn't be more appli
nednguyen
2016/08/03 15:41:36
Done.
| |
| 69 | |
| 70 def testShouldTearDownStateAfterEachStoryRunIsTrue(self): | |
| 71 for b in _GetAllSystemHealthBenchmarks(): | |
| 72 self.assertTrue( | |
| 73 b.ShouldTearDownStateAfterEachStoryRun(), | |
| 74 '%s has ShouldTearDownStateAfterEachStoryRun set to False' % b) | |
| 75 | |
| 76 def testSystemHealthStorySetAreUsed(self): | |
| 77 for b in _GetAllSystemHealthBenchmarks(): | |
| 78 if b is system_health.WebviewStartupSystemHealthBenchmark: | |
| 79 continue | |
|
petrcermak
2016/08/03 08:49:27
nit: this should be indented only 2 spaces (-2)
petrcermak
2016/08/03 08:49:27
Does this mean that the WebView benchmark shouldn'
nednguyen
2016/08/03 15:41:36
Probably it should use the SH story set. We probab
| |
| 80 self.assertIsInstance( | |
| 81 b().CreateStorySet(None), | |
| 82 system_health_stories.SystemHealthStorySet, | |
| 83 '%s does not use SystemHealthStorySet' % b) | |
| 84 | |
| 85 | |
| 54 class TestNoOverrideCustomizeBrowserOptions(unittest.TestCase): | 86 class TestNoOverrideCustomizeBrowserOptions(unittest.TestCase): |
| 55 | 87 |
| 56 def runTest(self): | 88 def runTest(self): |
| 57 all_benchmarks = _GetAllPerfBenchmarks() | 89 all_benchmarks = _GetAllPerfBenchmarks() |
| 58 for benchmark in all_benchmarks: | 90 for benchmark in all_benchmarks: |
| 59 self.assertEquals(True, issubclass(benchmark, | 91 self.assertEquals(True, issubclass(benchmark, |
| 60 perf_benchmark.PerfBenchmark), | 92 perf_benchmark.PerfBenchmark), |
| 61 'Benchmark %s needs to subclass from PerfBenchmark' | 93 'Benchmark %s needs to subclass from PerfBenchmark' |
| 62 % benchmark.Name()) | 94 % benchmark.Name()) |
| 63 self.assertEquals( | 95 self.assertEquals( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 74 for benchmark in all_benchmarks: | 106 for benchmark in all_benchmarks: |
| 75 if not benchmark.options: | 107 if not benchmark.options: |
| 76 # No need to test benchmarks that have not defined options. | 108 # No need to test benchmarks that have not defined options. |
| 77 continue | 109 continue |
| 78 | 110 |
| 79 class BenchmarkOptionsTest(unittest.TestCase): | 111 class BenchmarkOptionsTest(unittest.TestCase): |
| 80 pass | 112 pass |
| 81 setattr(BenchmarkOptionsTest, benchmark.Name(), | 113 setattr(BenchmarkOptionsTest, benchmark.Name(), |
| 82 _BenchmarkOptionsTestGenerator(benchmark)) | 114 _BenchmarkOptionsTestGenerator(benchmark)) |
| 83 suite.addTest(BenchmarkOptionsTest(benchmark.Name())) | 115 suite.addTest(BenchmarkOptionsTest(benchmark.Name())) |
| 84 suite.addTest(TestNoBenchmarkNamesDuplication()) | |
| 85 suite.addTest(TestNoOverrideCustomizeBrowserOptions()) | |
| 86 | 116 |
| 87 | 117 |
| 88 def load_tests(loader, standard_tests, pattern): | 118 def load_tests(loader, standard_tests, pattern): |
| 89 del loader, standard_tests, pattern # unused | 119 del loader, pattern # unused |
| 90 suite = progress_reporter.TestSuite() | 120 suite = progress_reporter.TestSuite() |
| 121 for t in standard_tests: | |
| 122 suite.addTests(t) | |
| 91 _AddBenchmarkOptionsTests(suite) | 123 _AddBenchmarkOptionsTests(suite) |
| 92 return suite | 124 return suite |
| OLD | NEW |