OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2016 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. | |
4 | |
5 """Run all the system health stories used by system health benchmarks. | |
petrcermak
2016/06/29 21:32:52
nit: I'd move "the" in front of "system health ben
nednguyen
2016/06/29 21:49:36
Done.
| |
6 | |
7 Only memory benchmarks are used when running these stories to make the total | |
8 cycle time manageable. Other system health benchmarks should be using the same | |
9 stories as memory's ones, only with fewer actions (no memory dumping). | |
petrcermak
2016/06/29 21:32:53
nitL s/memory's ones/the memory ones/
nednguyen
2016/06/29 21:49:36
Done.
| |
10 """ | |
11 | |
12 import unittest | |
13 | |
14 from core import perf_benchmark | |
15 | |
16 from telemetry import benchmark as benchmark_module | |
17 from telemetry import decorators | |
18 from telemetry.core import discover | |
19 from telemetry.internal.browser import browser_finder | |
20 from telemetry.testing import options_for_unittests | |
21 from telemetry.testing import progress_reporter | |
22 | |
23 from benchmarks import system_health | |
24 | |
25 | |
26 # We only cover memory system health | |
27 _SH_BENCHMARKS_TO_SMOKE_TEST = [ | |
28 system_health.DesktopMemorySystemHealth, | |
29 system_health.MobileMemorySystemHealth, | |
30 ] | |
31 | |
32 | |
33 def GetSystemHealthBenchmarksToSmokeTest(): | |
34 sh_benchmark_classes = discover.DiscoverClassesInModule( | |
35 system_health, perf_benchmark.PerfBenchmark, | |
36 index_by_class_name=True).values() | |
37 return list(b for b in sh_benchmark_classes if | |
38 b.Name().startswith('system_health.memory')) | |
39 | |
40 | |
41 _DISABLED_TESTS = [ | |
42 # crbug.com/624474 | |
43 'benchmarks.system_health_smoke_test.SystemHealthBenchmarkSmokeTest.system_hea lth.memory_desktop.load:tools:dropbox', # pylint: disable=line-too-long | |
44 ] | |
45 | |
46 | |
47 def _GenerateSmokeTestCase(benchmark_class, story_to_smoke_test): | |
48 | |
49 | |
petrcermak
2016/06/29 21:32:52
Please remove at least one blank line here (or bot
nednguyen
2016/06/29 21:49:36
Done.
| |
50 # NOTE TO SHERIFFS: DO NOT DISABLE THIS TEST. | |
51 # | |
52 # This smoke test dynamically tests all system health user stories. So | |
53 # disabling it for one failing or flaky benchmark would disable a much | |
petrcermak
2016/06/29 21:32:52
you have a double space here after "one" and after
nednguyen
2016/06/29 21:49:36
Done.
| |
54 # wider swath of coverage than is usally intended. Instead, if a test is | |
55 # failing, disable it by putting it in _DISABLED_TESTS list above. | |
petrcermak
2016/06/29 21:32:53
nit: s/in/into the/
nednguyen
2016/06/29 21:49:36
Done.
| |
56 @benchmark_module.Disabled('chromeos') # crbug.com/351114 | |
57 def runTest(self): | |
petrcermak
2016/06/29 21:32:52
method names should use CamelCase (not camelCase)
nednguyen
2016/06/29 21:49:36
Done.
| |
58 | |
59 class SinglePageBenchmark(benchmark_class): # pylint: disable=no-init | |
60 | |
petrcermak
2016/06/29 21:32:53
nit: I think that this would be more readable with
nednguyen
2016/06/29 21:49:36
Done.
| |
61 def CreateStorySet(self, options): | |
62 # pylint: disable=super-on-old-class | |
63 story_set = super(SinglePageBenchmark, self).CreateStorySet(options) | |
64 assert story_to_smoke_test in story_set.stories | |
65 story_set.stories = [story_to_smoke_test] | |
66 return story_set | |
67 | |
68 options = GenerateBenchmarkOptions(benchmark_class) | |
69 # Only measure a single story so that this test cycles reasonably quickly. | |
70 options.pageset_repeat = 1 | |
petrcermak
2016/06/29 21:32:52
Why don't you put these two lines inside GenerateB
nednguyen
2016/06/29 21:49:36
Done.
| |
71 options.page_repeat = 1 | |
72 possible_browser = browser_finder.FindBrowser(options) | |
73 if possible_browser is None: | |
74 self.skipTest('Cannot find the browser to run the test.') | |
75 if (SinglePageBenchmark.ShouldDisable(possible_browser) or | |
76 not decorators.IsEnabled(benchmark_class, possible_browser)[0]): | |
77 self.skipTest('Benchmark %s is disabled' % SinglePageBenchmark.Name()) | |
78 | |
79 if self.id() in _DISABLED_TESTS: | |
80 self.skipTest('Test is explictly disabled') | |
81 | |
82 self.assertEqual(0, SinglePageBenchmark().Run(options), | |
83 msg='Failed: %s' % benchmark_class) | |
84 | |
85 # We attach the test method to SystemHealthBenchmarkSmokeTest dynamically | |
86 # so that we can set the test method name to include | |
87 # '<benchmark class name>.<story display name>'. | |
88 test_method_name = '%s.%s' % ( | |
89 benchmark_class.Name(), story_to_smoke_test.display_name) | |
90 | |
91 class SystemHealthBenchmarkSmokeTest(unittest.TestCase): | |
92 pass | |
93 | |
94 setattr(SystemHealthBenchmarkSmokeTest, test_method_name, runTest) | |
95 | |
96 return SystemHealthBenchmarkSmokeTest(methodName=test_method_name) | |
97 | |
98 | |
99 def GenerateBenchmarkOptions(benchmark_class): | |
petrcermak
2016/06/29 21:32:53
I suppose this should be private (since it's only
nednguyen
2016/06/29 21:49:36
Done.
| |
100 # Set the benchmark's default arguments. | |
101 options = options_for_unittests.GetCopy() | |
petrcermak
2016/06/29 21:32:52
This whole method is super-complicated and I have
nednguyen
2016/06/29 21:49:36
Done.
| |
102 options.output_format = 'none' | |
103 parser = options.CreateParser() | |
104 | |
105 benchmark_class.AddCommandLineArgs(parser) | |
106 benchmark_module.AddCommandLineArgs(parser) | |
107 benchmark_class.SetArgumentDefaults(parser) | |
108 options.MergeDefaultValues(parser.get_default_values()) | |
109 | |
110 benchmark_class.ProcessCommandLineArgs(None, options) | |
111 benchmark_module.ProcessCommandLineArgs(None, options) | |
112 return options | |
113 | |
114 | |
115 def load_tests(loader, standard_tests, pattern): | |
116 del loader, standard_tests, pattern # unused | |
117 suite = progress_reporter.TestSuite() | |
118 benchmark_classes = GetSystemHealthBenchmarksToSmokeTest() | |
119 assert benchmark_classes, 'This list should never be empty' | |
120 for benchmark_class in benchmark_classes: | |
121 | |
122 # HACK: these options should be derived from options_for_unittests which is | |
petrcermak
2016/06/29 21:32:53
nit: s/is/are/
nednguyen
2016/06/29 21:49:36
Done.
| |
123 # the resolved options from run_tests' arguments. However, options is only | |
petrcermak
2016/06/29 21:32:52
nit: s/is/are/
nednguyen
2016/06/29 21:49:36
Done.
| |
124 # parsed during test time which happens after load_tests is called. | |
125 # Since none of our system health benchmark create stories based on command | |
petrcermak
2016/06/29 21:32:52
nit: s/benchmark/benchmarks/ and s/create/creates/
nednguyen
2016/06/29 21:49:36
Done.
| |
126 # line options, it should be ok to pass options=None to CreateStorySet. | |
127 for story_to_smoke_test in ( | |
128 benchmark_class().CreateStorySet(options=None).stories): | |
129 suite.addTest( | |
130 _GenerateSmokeTestCase(benchmark_class, story_to_smoke_test)) | |
131 | |
132 return suite | |
OLD | NEW |