Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 from telemetry.page import page_runner | 4 from telemetry.page import page_runner |
| 5 from telemetry.page import page_set | 5 from telemetry.page import page_set |
| 6 from telemetry.page import page_test | 6 from telemetry.page import page_test |
| 7 | 7 |
| 8 | 8 |
| 9 __all__ = ["Test", "RunOnMastersNamed"] | |
|
dtu
2013/07/03 01:25:43
single quotes
| |
| 10 | |
| 11 | |
| 12 def RunOnBuildMastersNamed(*build_master_names): | |
| 13 """ | |
| 14 Indicates that the test should only run on a given set of buildbot masters. | |
| 15 """ | |
| 16 assert build_master_names | |
| 17 def wrap(cls): | |
| 18 assert not cls._run_on_build_masters_named # pylint: disable=W0212 | |
| 19 cls._run_on_build_masters_named = build_master_names # pylint: disable=W0212 | |
| 20 return cls | |
| 21 return wrap | |
| 22 | |
| 23 | |
| 24 def AddOptionsForRunDecoratorToParser(parser): | |
| 25 parser.add_option( | |
| 26 '--build-master-name', | |
| 27 help='Only runs tests with @RunOnMastersNamed(build_master_name)') | |
| 28 | |
| 29 | |
| 9 class Test(object): | 30 class Test(object): |
| 10 """Base class for a Telemetry test or benchmark. | 31 """Base class for a Telemetry test or benchmark. |
| 11 | 32 |
| 12 A test packages a PageTest/PageMeasurement and a PageSet together. | 33 A test packages a PageTest/PageMeasurement and a PageSet together. |
| 13 """ | 34 """ |
| 14 options = {} | 35 options = {} |
| 15 enabled = True | 36 _run_on_build_masters_named = [] |
| 37 | |
| 38 @classmethod | |
| 39 def CanRun(cls, options): | |
| 40 if not options.build_master_name: | |
| 41 return True | |
| 42 return options.build_master_name in cls._run_on_build_masters_named | |
| 16 | 43 |
| 17 def Run(self, options): | 44 def Run(self, options): |
| 18 """Run this test with the given options.""" | 45 """Run this test with the given options.""" |
| 19 assert hasattr(self, 'test'), 'This test has no "test" attribute.' | 46 assert hasattr(self, 'test'), 'This test has no "test" attribute.' |
| 20 assert issubclass(self.test, page_test.PageTest), ( | 47 assert issubclass(self.test, page_test.PageTest), ( |
| 21 '"%s" is not a PageTest.' % self.test.__name__) | 48 '"%s" is not a PageTest.' % self.test.__name__) |
| 22 | 49 |
| 23 for key, value in self.options.iteritems(): | 50 for key, value in self.options.iteritems(): |
| 24 setattr(options, key, value) | 51 setattr(options, key, value) |
| 25 | 52 |
| 26 test = self.test() | 53 test = self.test() |
| 27 ps = self.CreatePageSet(options) | 54 ps = self.CreatePageSet(options) |
| 28 results = page_runner.Run(test, ps, options) | 55 results = page_runner.Run(test, ps, options) |
| 29 results.PrintSummary() | 56 results.PrintSummary() |
| 30 return len(results.failures) + len(results.errors) | 57 return len(results.failures) + len(results.errors) |
| 31 | 58 |
| 32 def CreatePageSet(self, options): # pylint: disable=W0613 | 59 def CreatePageSet(self, options): # pylint: disable=W0613 |
| 33 """Get the page set this test will run on. | 60 """Get the page set this test will run on. |
| 34 | 61 |
| 35 By default, it will create a page set from the file at this test's | 62 By default, it will create a page set from the file at this test's |
| 36 page_set attribute. Override to generate a custom page set. | 63 page_set attribute. Override to generate a custom page set. |
| 37 """ | 64 """ |
| 38 assert hasattr(self, 'page_set'), 'This test has no "page_set" attribute.' | 65 assert hasattr(self, 'page_set'), 'This test has no "page_set" attribute.' |
| 39 return page_set.PageSet.FromFile(self.page_set) | 66 return page_set.PageSet.FromFile(self.page_set) |
| OLD | NEW |