1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
# Copyright 2016 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import json
import logging
import os
import sys
from telemetry.testing import fakes
from telemetry.testing import browser_test_context
from gpu_tests import gpu_integration_test
# pylint: disable=abstract-method
class _BaseSampleIntegrationTest(gpu_integration_test.GpuIntegrationTest):
_test_state = {}
@classmethod
def SetUpProcess(cls):
finder_options = fakes.CreateBrowserFinderOptions()
finder_options.browser_options.platform = fakes.FakeLinuxPlatform()
finder_options.output_formats = ['none']
finder_options.suppress_gtest_report = True
finder_options.output_dir = None
finder_options.upload_bucket = 'public'
finder_options.upload_results = False
cls._finder_options = finder_options
cls.platform = None
cls.browser = None
cls.SetBrowserOptions(cls._finder_options)
cls.StartBrowser()
@classmethod
def AddCommandlineArgs(cls, parser):
super(_BaseSampleIntegrationTest, cls).AddCommandlineArgs(parser)
parser.add_argument(
'--test-state-json-path',
help=('Where to dump the test state json (this is used by '
'gpu_integration_test_unittest)'))
@classmethod
def TearDownProcess(cls):
actual_finder_options = browser_test_context.GetCopy().finder_options
test_state_json_path = actual_finder_options.test_state_json_path
with open(test_state_json_path, 'w', encoding='utf-8') as f:
json.dump(cls._test_state, f)
super(_BaseSampleIntegrationTest, cls).TearDownProcess()
# pylint: enable=abstract-method
class SimpleTest(_BaseSampleIntegrationTest):
_test_state = {'num_flaky_runs_to_fail': 2, 'num_browser_starts': 0}
@classmethod
def Name(cls):
return 'simple_integration_unittest'
@classmethod
def GenerateGpuTests(cls, options):
yield ('expected_failure', 'failure.html', ())
yield ('expected_flaky', 'flaky.html', ())
yield ('expected_skip', 'failure.html', ())
yield ('unexpected_failure', 'failure.html', ())
yield ('unexpected_error', 'error.html', ())
@classmethod
def StartBrowser(cls):
super(SimpleTest, cls).StartBrowser()
cls._test_state['num_browser_starts'] += 1
def RunActualGpuTest(self, test_path, *args):
logging.warning('Running %s', test_path)
if test_path == 'failure.html':
self.fail('Expected failure')
elif test_path == 'flaky.html':
if self._test_state['num_flaky_runs_to_fail'] > 0:
self._test_state['num_flaky_runs_to_fail'] -= 1
self.fail('Expected flaky failure')
elif test_path == 'error.html':
raise Exception('Expected exception')
@classmethod
def ExpectationsFiles(cls):
return [
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
('test_expectations/'
'simple_integration_unittest_expectations.txt'))
]
class BrowserStartFailureTest(_BaseSampleIntegrationTest):
_test_state = {'num_browser_crashes': 0, 'num_browser_starts': 0}
@classmethod
def SetUpProcess(cls):
cls._fake_browser_options = \
fakes.CreateBrowserFinderOptions(execute_on_startup=cls.CrashOnStart)
cls._fake_browser_options.browser_options.platform = \
fakes.FakeLinuxPlatform()
cls._fake_browser_options.output_formats = ['none']
cls._fake_browser_options.suppress_gtest_report = True
cls._fake_browser_options.output_dir = None
cls._fake_browser_options.upload_bucket = 'public'
cls._fake_browser_options.upload_results = False
cls._finder_options = cls._fake_browser_options
cls.platform = None
cls.browser = None
cls.SetBrowserOptions(cls._finder_options)
cls.StartBrowser()
@classmethod
def CrashOnStart(cls):
cls._test_state['num_browser_starts'] += 1
if cls._test_state['num_browser_crashes'] < 2:
cls._test_state['num_browser_crashes'] += 1
raise Exception('Fake browser crash')
@classmethod
def Name(cls):
return 'browser_start_failure_integration_unittest'
@classmethod
def GenerateGpuTests(cls, options):
# This test causes the browser to try and restart the browser 3 times.
yield ('restart', 'restart.html', ())
def RunActualGpuTest(self, test_path, *args):
# The logic of this test is run when the browser starts, it fails twice
# and then succeeds on the third time so we are just testing that this
# is successful based on the parameters.
pass
class BrowserCrashAfterStartTest(_BaseSampleIntegrationTest):
_test_state = {
'num_browser_crashes': 0,
'num_browser_starts': 0,
}
@classmethod
def SetUpProcess(cls):
cls._fake_browser_options = fakes.CreateBrowserFinderOptions(
execute_after_browser_creation=cls.CrashAfterStart)
cls._fake_browser_options.browser_options.platform = \
fakes.FakeLinuxPlatform()
cls._fake_browser_options.output_formats = ['none']
cls._fake_browser_options.suppress_gtest_report = True
cls._fake_browser_options.output_dir = None
cls._fake_browser_options.upload_bucket = 'public'
cls._fake_browser_options.upload_results = False
cls._finder_options = cls._fake_browser_options
cls.platform = None
cls.browser = None
cls.SetBrowserOptions(cls._finder_options)
cls.StartBrowser()
@classmethod
def CrashAfterStart(cls, browser):
cls._test_state['num_browser_starts'] += 1
if cls._test_state['num_browser_crashes'] < 2:
cls._test_state['num_browser_crashes'] += 1
# This simulates the first tab's renderer process crashing upon
# startup. The try/catch forces the GpuIntegrationTest's first
# fetch of this tab to fail. crbug.com/682819
try:
browser.tabs[0].Navigate('chrome://crash')
except Exception: # pylint: disable=broad-except
pass
@classmethod
def Name(cls):
return 'browser_crash_after_start_integration_unittest'
@classmethod
def GenerateGpuTests(cls, options):
# This test causes the browser to try and restart the browser 3 times.
yield ('restart', 'restart.html', ())
def RunActualGpuTest(self, test_path, *args):
# The logic of this test is run when the browser starts, it fails twice
# and then succeeds on the third time so we are just testing that this
# is successful based on the parameters.
pass
class RunTestsWithExpectationsFiles(_BaseSampleIntegrationTest):
def __init__(self, methodName):
super().__init__(methodName)
self._flaky_test_run = 0
@classmethod
def GetPlatformTags(cls, browser):
assert isinstance(browser, fakes.FakeBrowser)
return ['foo']
@classmethod
def Name(cls):
return 'run_tests_with_expectations_files'
@classmethod
def GenerateGpuTests(cls, options):
tests = [('a/b/unexpected-fail.html', 'failure.html', ()),
('a/b/expected-fail.html', 'failure.html', ()),
('a/b/expected-flaky.html', 'flaky.html', ()),
('should_skip', 'skip.html', ())]
yield from tests
def RunActualGpuTest(self, test_path, *args):
if test_path == 'failure.html' or self._flaky_test_run < 3:
self._flaky_test_run += test_path == 'flaky.html'
self.fail()
@classmethod
def ExpectationsFiles(cls):
return [
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
('test_expectations/'
'run_tests_with_expectations_files_expectations.txt'))
]
class TestRetryLimit(_BaseSampleIntegrationTest):
_test_state = {
'num_test_runs': 0,
}
@classmethod
def Name(cls):
return 'test_retry_limit'
@classmethod
def GenerateGpuTests(cls, options):
yield ('unexpected_failure', 'failure.html', ())
def RunActualGpuTest(self, test_path, *args):
self._test_state['num_test_runs'] += 1
if test_path == 'failure.html':
self.fail('Expected failure')
else:
raise Exception('Unexpected test name ' + test_path)
class TestRepeat(_BaseSampleIntegrationTest):
_test_state = {
'num_test_runs': 0,
}
@classmethod
def Name(cls):
return 'test_repeat'
@classmethod
def GenerateGpuTests(cls, options):
yield ('success', 'success.html', ())
def RunActualGpuTest(self, test_path, *args):
self._test_state['num_test_runs'] += 1
if test_path != 'success.html':
raise Exception('Unexpected test name ' + test_path)
class TestAlsoRunDisabledTests(_BaseSampleIntegrationTest):
_test_state = {'num_flaky_test_runs': 0, 'num_test_runs': 0}
@classmethod
def Name(cls):
return 'test_also_run_disabled_tests'
@classmethod
def GenerateGpuTests(cls, options):
tests = [('skip', 'skip.html', ()), ('expected_failure', 'fail.html', ()),
('flaky', 'flaky.html', ())]
yield from tests
def RunActualGpuTest(self, test_path, *args):
self._test_state['num_test_runs'] += 1
self._test_state['num_flaky_test_runs'] += test_path == 'flaky.html'
raise Exception('Everything fails')
@classmethod
def ExpectationsFiles(cls):
return [
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
('test_expectations/'
'tests_also_run_disabled_tests_expectations.txt'))
]
def load_tests(loader, tests, pattern):
del loader, tests, pattern # Unused.
return gpu_integration_test.LoadAllTestsInModule(sys.modules[__name__])
|