Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import logging | 5 import logging |
| 6 | 6 |
| 7 from telemetry import benchmark as benchmark_module | 7 from telemetry import benchmark as benchmark_module |
| 8 from telemetry.core import exceptions | |
| 8 from telemetry.page import page as page_module | 9 from telemetry.page import page as page_module |
| 9 from telemetry.page import page_test | 10 from telemetry.page import page_test |
| 10 from telemetry.page import shared_page_state as shared_page_state_module | 11 from telemetry.page import shared_page_state as shared_page_state_module |
| 11 from telemetry.testing import fakes | 12 from telemetry.testing import fakes |
| 12 | 13 |
| 13 from gpu_tests import exception_formatter | 14 from gpu_tests import exception_formatter |
| 14 from gpu_tests import gpu_test_expectations | 15 from gpu_tests import gpu_test_expectations |
| 15 | 16 |
| 16 class TestBase(benchmark_module.Benchmark): | 17 class TestBase(benchmark_module.Benchmark): |
| 17 """Base classes for all GPU tests in this directory. Implements | 18 """Base classes for all GPU tests in this directory. Implements |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 def ValidateAndMeasurePage(self, page, tab, result): | 54 def ValidateAndMeasurePage(self, page, tab, result): |
| 54 pass | 55 pass |
| 55 | 56 |
| 56 def _CanRunOnBrowser(browser_info, page): | 57 def _CanRunOnBrowser(browser_info, page): |
| 57 expectations = page.GetExpectations() | 58 expectations = page.GetExpectations() |
| 58 return expectations.GetExpectationForPage( | 59 return expectations.GetExpectationForPage( |
| 59 browser_info.browser, page) != 'skip' | 60 browser_info.browser, page) != 'skip' |
| 60 | 61 |
| 61 def RunStoryWithRetries(cls, shared_page_state, results): | 62 def RunStoryWithRetries(cls, shared_page_state, results): |
| 62 page = shared_page_state.current_page | 63 page = shared_page_state.current_page |
| 64 | |
| 65 # Save this away for use in _DidRunStory, below. | |
| 66 shared_page_state._last_cached_page = page | |
| 67 | |
| 63 expectations = page.GetExpectations() | 68 expectations = page.GetExpectations() |
| 64 expectation = 'pass' | 69 expectation = 'pass' |
| 65 if expectations: | 70 if expectations: |
| 66 expectation = expectations.GetExpectationForPage( | 71 expectation = expectations.GetExpectationForPage( |
| 67 shared_page_state.browser, page) | 72 shared_page_state.browser, page) |
| 68 if expectation == 'skip': | 73 if expectation == 'skip': |
| 69 raise Exception( | 74 raise Exception( |
| 70 'Skip expectations should have been handled in CanRunOnBrowser') | 75 'Skip expectations should have been handled in CanRunOnBrowser') |
| 71 try: | 76 try: |
| 72 super(cls, shared_page_state).RunStory(results) | 77 super(cls, shared_page_state).RunStory(results) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 96 break | 101 break |
| 97 except Exception: | 102 except Exception: |
| 98 # Squelch any exceptions from any but the last retry. | 103 # Squelch any exceptions from any but the last retry. |
| 99 if ii == num_retries - 1: | 104 if ii == num_retries - 1: |
| 100 raise | 105 raise |
| 101 else: | 106 else: |
| 102 if expectation == 'fail': | 107 if expectation == 'fail': |
| 103 logging.warning( | 108 logging.warning( |
| 104 '%s was expected to fail, but passed.\n', page.display_name) | 109 '%s was expected to fail, but passed.\n', page.display_name) |
| 105 | 110 |
| 111 def _DidRunStory(cls, shared_page_state, results, | |
| 112 force_timeout_exception=False): | |
| 113 try: | |
| 114 super(cls, shared_page_state).DidRunStory(results) | |
| 115 if force_timeout_exception: | |
| 116 raise exceptions.TimeoutException('Deliberate timeout') | |
| 117 except Exception: | |
| 118 # See whether we need to squelch this exception because there's | |
| 119 # a failure or flaky expectation. | |
| 120 page = shared_page_state._last_cached_page | |
| 121 expectations = page.GetExpectations() | |
| 122 expectation = 'pass' | |
| 123 if expectations: | |
| 124 expectation = expectations.GetExpectationForPage( | |
| 125 shared_page_state.browser, page) | |
| 126 # Unlike RunStoryWithRetries, it's possible for this entry point | |
| 127 # to see skip expectations, in particular if an exception was | |
| 128 # thrown during the test run. | |
| 129 if expectation != 'pass': | |
|
nednguyen
2016/05/04 17:58:25
I think you may want exercise the code path of tea
| |
| 130 # Expect that RunStory probably also failed, so don't worry | |
| 131 # about counting the number of failures seen in DidRunStory. | |
| 132 # Just squelch the exception and continue. | |
| 133 msg = 'Expected exception in DidRunStory for %s' % page.display_name | |
| 134 exception_formatter.PrintFormattedException(msg=msg) | |
| 135 return | |
| 136 raise | |
| 137 | |
| 106 class GpuSharedPageState(shared_page_state_module.SharedPageState): | 138 class GpuSharedPageState(shared_page_state_module.SharedPageState): |
| 107 def CanRunOnBrowser(self, browser_info, page): | 139 def CanRunOnBrowser(self, browser_info, page): |
| 108 return _CanRunOnBrowser(browser_info, page) | 140 return _CanRunOnBrowser(browser_info, page) |
| 109 | 141 |
| 110 def RunStory(self, results): | 142 def RunStory(self, results): |
| 111 RunStoryWithRetries(GpuSharedPageState, self, results) | 143 RunStoryWithRetries(GpuSharedPageState, self, results) |
| 112 | 144 |
| 145 def DidRunStory(self, results): | |
| 146 _DidRunStory(GpuSharedPageState, self, results) | |
| 147 | |
| 113 | 148 |
| 114 # TODO(kbr): re-evaluate the need for this SharedPageState | 149 # TODO(kbr): re-evaluate the need for this SharedPageState |
| 115 # subclass. It's only used by the WebGL conformance suite. | 150 # subclass. It's only used by the WebGL conformance suite. |
| 116 class DesktopGpuSharedPageState( | 151 class DesktopGpuSharedPageState( |
| 117 shared_page_state_module.SharedDesktopPageState): | 152 shared_page_state_module.SharedDesktopPageState): |
| 118 def CanRunOnBrowser(self, browser_info, page): | 153 def CanRunOnBrowser(self, browser_info, page): |
| 119 return _CanRunOnBrowser(browser_info, page) | 154 return _CanRunOnBrowser(browser_info, page) |
| 120 | 155 |
| 121 def RunStory(self, results): | 156 def RunStory(self, results): |
| 122 RunStoryWithRetries(DesktopGpuSharedPageState, self, results) | 157 RunStoryWithRetries(DesktopGpuSharedPageState, self, results) |
| 123 | 158 |
| 159 def DidRunStory(self, results): | |
| 160 _DidRunStory(DesktopGpuSharedPageState, self, results) | |
| 161 | |
| 124 | 162 |
| 125 class FakeGpuSharedPageState(fakes.FakeSharedPageState): | 163 class FakeGpuSharedPageState(fakes.FakeSharedPageState): |
| 126 def CanRunOnBrowser(self, browser_info, page): | 164 def CanRunOnBrowser(self, browser_info, page): |
| 127 return _CanRunOnBrowser(browser_info, page) | 165 return _CanRunOnBrowser(browser_info, page) |
| 128 | 166 |
| 129 def RunStory(self, results): | 167 def RunStory(self, results): |
| 130 RunStoryWithRetries(FakeGpuSharedPageState, self, results) | 168 RunStoryWithRetries(FakeGpuSharedPageState, self, results) |
| 131 | 169 |
| 170 def DidRunStory(self, results, #pylint: disable=arguments-differ | |
| 171 force_timeout_exception=False): | |
| 172 _DidRunStory(FakeGpuSharedPageState, self, results, | |
| 173 force_timeout_exception=force_timeout_exception) | |
| 174 | |
| 132 | 175 |
| 133 class PageBase(page_module.Page): | 176 class PageBase(page_module.Page): |
| 134 # The convention is that pages subclassing this class must be | 177 # The convention is that pages subclassing this class must be |
| 135 # configured with the test expectations. | 178 # configured with the test expectations. |
| 136 def __init__(self, url, page_set=None, base_dir=None, name='', | 179 def __init__(self, url, page_set=None, base_dir=None, name='', |
| 137 shared_page_state_class=GpuSharedPageState, | 180 shared_page_state_class=GpuSharedPageState, |
| 138 make_javascript_deterministic=True, | 181 make_javascript_deterministic=True, |
| 139 expectations=None): | 182 expectations=None): |
| 140 super(PageBase, self).__init__( | 183 super(PageBase, self).__init__( |
| 141 url=url, page_set=page_set, base_dir=base_dir, name=name, | 184 url=url, page_set=page_set, base_dir=base_dir, name=name, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 156 | 199 |
| 157 | 200 |
| 158 # TODO(kbr): this is fragile -- if someone changes the | 201 # TODO(kbr): this is fragile -- if someone changes the |
| 159 # shared_page_state_class to something that doesn't handle skip | 202 # shared_page_state_class to something that doesn't handle skip |
| 160 # expectations, then they'll hit the exception in | 203 # expectations, then they'll hit the exception in |
| 161 # RunStoryWithRetries, above. Need to rethink. | 204 # RunStoryWithRetries, above. Need to rethink. |
| 162 self._expectations = expectations | 205 self._expectations = expectations |
| 163 | 206 |
| 164 def GetExpectations(self): | 207 def GetExpectations(self): |
| 165 return self._expectations | 208 return self._expectations |
| OLD | NEW |