Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: content/test/gpu/unittest_data/integration_tests.py

Issue 2663813003: Roll out framework change & update gpu tests to conform to the API changes (Closed)
Patch Set: Roll DEPS to 42d9cffaa797712c58d7b5fb59820f0aa3e82138 Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 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 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
5 import json 6 import json
6 import logging 7 import logging
7 import mock 8 import mock
8 import os 9 import os
10 import sys
9 import tempfile 11 import tempfile
10 import unittest 12 import unittest
11 13
12 from telemetry.testing import fakes 14 from telemetry.testing import fakes
13 from telemetry.testing import browser_test_runner 15 from telemetry.testing import browser_test_runner
16 from telemetry.testing import browser_test_context
14 17
15 import gpu_project_config 18 import gpu_project_config
16 19
17 from gpu_tests import gpu_integration_test 20 from gpu_tests import gpu_integration_test
18 from gpu_tests import gpu_test_expectations 21 from gpu_tests import gpu_test_expectations
19 22
20 class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest):
21 # Must be class-scoped since instances aren't reused across runs.
22 _num_flaky_runs_to_fail = 2
23 23
24 _num_browser_starts = 0 24 class _BaseSampleIntegrationTest(gpu_integration_test.GpuIntegrationTest):
25 _test_state = {}
26 @classmethod
27 def AddCommandlineArgs(cls, parser):
28 parser.add_option('--test-state-json-path',
29 help=('Where to dump the test state json (this is used by '
30 'gpu_integration_test_unittest)'))
31
32 @classmethod
33 def TearDownProcess(cls):
34 actual_finder_options = browser_test_context.GetCopy().finder_options
35 test_state_json_path = actual_finder_options.test_state_json_path
36 with open(test_state_json_path, 'w') as f:
37 json.dump(cls._test_state, f)
38 super(_BaseSampleIntegrationTest, cls).TearDownProcess()
39
40
41 class SimpleTest(_BaseSampleIntegrationTest):
42 _test_state = {
43 'num_flaky_runs_to_fail': 2,
44 'num_browser_starts': 0
45 }
46
25 47
26 @classmethod 48 @classmethod
27 def Name(cls): 49 def Name(cls):
28 return 'simple_integration_unittest' 50 return 'simple_integration_unittest'
29 51
30 def setUp(self): 52 def setUp(self):
31 super(SimpleIntegrationUnittest, self).setUp() 53 super(SimpleTest, self).setUp()
32 54
33 @classmethod 55 @classmethod
34 def setUpClass(cls): 56 def SetUpProcess(cls):
35 finder_options = fakes.CreateBrowserFinderOptions() 57 finder_options = fakes.CreateBrowserFinderOptions()
36 finder_options.browser_options.platform = fakes.FakeLinuxPlatform() 58 finder_options.browser_options.platform = fakes.FakeLinuxPlatform()
37 finder_options.output_formats = ['none'] 59 finder_options.output_formats = ['none']
38 finder_options.suppress_gtest_report = True 60 finder_options.suppress_gtest_report = True
39 finder_options.output_dir = None 61 finder_options.output_dir = None
40 finder_options.upload_bucket = 'public' 62 finder_options.upload_bucket = 'public'
41 finder_options.upload_results = False 63 finder_options.upload_results = False
42 cls._finder_options = finder_options 64 cls._finder_options = finder_options
43 cls.platform = None 65 cls.platform = None
44 cls.browser = None 66 cls.browser = None
(...skipping 11 matching lines...) Expand all
56 @classmethod 78 @classmethod
57 def _CreateExpectations(cls): 79 def _CreateExpectations(cls):
58 expectations = gpu_test_expectations.GpuTestExpectations() 80 expectations = gpu_test_expectations.GpuTestExpectations()
59 expectations.Fail('expected_failure') 81 expectations.Fail('expected_failure')
60 expectations.Flaky('expected_flaky', max_num_retries=3) 82 expectations.Flaky('expected_flaky', max_num_retries=3)
61 expectations.Skip('expected_skip') 83 expectations.Skip('expected_skip')
62 return expectations 84 return expectations
63 85
64 @classmethod 86 @classmethod
65 def StartBrowser(cls): 87 def StartBrowser(cls):
66 super(SimpleIntegrationUnittest, cls).StartBrowser() 88 super(SimpleTest, cls).StartBrowser()
67 cls._num_browser_starts += 1 89 cls._test_state['num_browser_starts'] += 1
68 90
69 def RunActualGpuTest(self, file_path, *args): 91 def RunActualGpuTest(self, file_path, *args):
70 logging.warn('Running ' + file_path) 92 logging.warn('Running ' + file_path)
71 if file_path == 'failure.html': 93 if file_path == 'failure.html':
72 self.fail('Expected failure') 94 self.fail('Expected failure')
73 elif file_path == 'flaky.html': 95 elif file_path == 'flaky.html':
74 if self.__class__._num_flaky_runs_to_fail > 0: 96 if self._test_state['num_flaky_runs_to_fail'] > 0:
75 self.__class__._num_flaky_runs_to_fail -= 1 97 self._test_state['num_flaky_runs_to_fail'] -= 1
76 self.fail('Expected flaky failure') 98 self.fail('Expected flaky failure')
77 elif file_path == 'error.html': 99 elif file_path == 'error.html':
78 raise Exception('Expected exception') 100 raise Exception('Expected exception')
79 101
80 102
81 class BrowserStartFailureIntegrationUnittest( 103 class BrowserStartFailureTest(_BaseSampleIntegrationTest):
82 gpu_integration_test.GpuIntegrationTest):
83 104
84 _num_browser_crashes = 0 105 _test_state = {
85 _num_browser_starts = 0 106 'num_browser_crashes': 0,
107 'num_browser_starts': 0
108 }
86 109
87 @classmethod 110 @classmethod
88 def setUpClass(cls): 111 def SetUpProcess(cls):
89 cls._fake_browser_options = \ 112 cls._fake_browser_options = \
90 fakes.CreateBrowserFinderOptions(execute_on_startup=cls.CrashOnStart) 113 fakes.CreateBrowserFinderOptions(execute_on_startup=cls.CrashOnStart)
91 cls._fake_browser_options.browser_options.platform = \ 114 cls._fake_browser_options.browser_options.platform = \
92 fakes.FakeLinuxPlatform() 115 fakes.FakeLinuxPlatform()
93 cls._fake_browser_options.output_formats = ['none'] 116 cls._fake_browser_options.output_formats = ['none']
94 cls._fake_browser_options.suppress_gtest_report = True 117 cls._fake_browser_options.suppress_gtest_report = True
95 cls._fake_browser_options.output_dir = None 118 cls._fake_browser_options.output_dir = None
96 cls._fake_browser_options .upload_bucket = 'public' 119 cls._fake_browser_options .upload_bucket = 'public'
97 cls._fake_browser_options .upload_results = False 120 cls._fake_browser_options .upload_results = False
98 cls._finder_options = cls._fake_browser_options 121 cls._finder_options = cls._fake_browser_options
99 cls.platform = None 122 cls.platform = None
100 cls.browser = None 123 cls.browser = None
101 cls.SetBrowserOptions(cls._finder_options) 124 cls.SetBrowserOptions(cls._finder_options)
102 cls.StartBrowser() 125 cls.StartBrowser()
103 126
104 @classmethod 127 @classmethod
105 def _CreateExpectations(cls): 128 def _CreateExpectations(cls):
106 return gpu_test_expectations.GpuTestExpectations() 129 return gpu_test_expectations.GpuTestExpectations()
107 130
108 @classmethod 131 @classmethod
109 def CrashOnStart(cls): 132 def CrashOnStart(cls):
110 cls._num_browser_starts += 1 133 cls._test_state['num_browser_starts'] += 1
111 if cls._num_browser_crashes < 2: 134 if cls._test_state['num_browser_crashes'] < 2:
112 cls._num_browser_crashes += 1 135 cls._test_state['num_browser_crashes'] += 1
113 raise 136 raise
114 137
115 @classmethod 138 @classmethod
116 def Name(cls): 139 def Name(cls):
117 return 'browser_start_failure_integration_unittest' 140 return 'browser_start_failure_integration_unittest'
118 141
119 @classmethod 142 @classmethod
120 def GenerateGpuTests(cls, options): 143 def GenerateGpuTests(cls, options):
121 # This test causes the browser to try and restart the browser 3 times. 144 # This test causes the browser to try and restart the browser 3 times.
122 yield ('restart', 'restart.html', ()) 145 yield ('restart', 'restart.html', ())
123 146
124 def RunActualGpuTest(self, file_path, *args): 147 def RunActualGpuTest(self, file_path, *args):
125 # The logic of this test is run when the browser starts, it fails twice 148 # The logic of this test is run when the browser starts, it fails twice
126 # and then succeeds on the third time so we are just testing that this 149 # and then succeeds on the third time so we are just testing that this
127 # is successful based on the parameters. 150 # is successful based on the parameters.
128 pass 151 pass
129 152
130 153
131 class BrowserCrashAfterStartIntegrationUnittest( 154 class BrowserCrashAfterStartTest(_BaseSampleIntegrationTest):
132 gpu_integration_test.GpuIntegrationTest):
133 155
134 _num_browser_crashes = 0 156 _test_state = {
135 _num_browser_starts = 0 157 'num_browser_crashes': 0,
158 'num_browser_starts': 0,
159 }
136 160
137 @classmethod 161 @classmethod
138 def setUpClass(cls): 162 def SetUpProcess(cls):
139 cls._fake_browser_options = fakes.CreateBrowserFinderOptions( 163 cls._fake_browser_options = fakes.CreateBrowserFinderOptions(
140 execute_after_browser_creation=cls.CrashAfterStart) 164 execute_after_browser_creation=cls.CrashAfterStart)
141 cls._fake_browser_options.browser_options.platform = \ 165 cls._fake_browser_options.browser_options.platform = \
142 fakes.FakeLinuxPlatform() 166 fakes.FakeLinuxPlatform()
143 cls._fake_browser_options.output_formats = ['none'] 167 cls._fake_browser_options.output_formats = ['none']
144 cls._fake_browser_options.suppress_gtest_report = True 168 cls._fake_browser_options.suppress_gtest_report = True
145 cls._fake_browser_options.output_dir = None 169 cls._fake_browser_options.output_dir = None
146 cls._fake_browser_options .upload_bucket = 'public' 170 cls._fake_browser_options .upload_bucket = 'public'
147 cls._fake_browser_options .upload_results = False 171 cls._fake_browser_options .upload_results = False
148 cls._finder_options = cls._fake_browser_options 172 cls._finder_options = cls._fake_browser_options
149 cls.platform = None 173 cls.platform = None
150 cls.browser = None 174 cls.browser = None
151 cls.SetBrowserOptions(cls._finder_options) 175 cls.SetBrowserOptions(cls._finder_options)
152 cls.StartBrowser() 176 cls.StartBrowser()
153 177
154 @classmethod 178 @classmethod
155 def _CreateExpectations(cls): 179 def _CreateExpectations(cls):
156 return gpu_test_expectations.GpuTestExpectations() 180 return gpu_test_expectations.GpuTestExpectations()
157 181
158 @classmethod 182 @classmethod
159 def CrashAfterStart(cls, browser): 183 def CrashAfterStart(cls, browser):
160 cls._num_browser_starts += 1 184 cls._test_state['num_browser_starts'] += 1
161 if cls._num_browser_crashes < 2: 185 if cls._test_state['num_browser_crashes'] < 2:
162 cls._num_browser_crashes += 1 186 cls._test_state['num_browser_crashes'] += 1
163 # This simulates the first tab's renderer process crashing upon 187 # This simulates the first tab's renderer process crashing upon
164 # startup. The try/catch forces the GpuIntegrationTest's first 188 # startup. The try/catch forces the GpuIntegrationTest's first
165 # fetch of this tab to fail. crbug.com/682819 189 # fetch of this tab to fail. crbug.com/682819
166 try: 190 try:
167 browser.tabs[0].Navigate('chrome://crash') 191 browser.tabs[0].Navigate('chrome://crash')
168 except Exception: 192 except Exception:
169 pass 193 pass
170 194
171 @classmethod 195 @classmethod
172 def Name(cls): 196 def Name(cls):
173 return 'browser_crash_after_start_integration_unittest' 197 return 'browser_crash_after_start_integration_unittest'
174 198
175 @classmethod 199 @classmethod
176 def GenerateGpuTests(cls, options): 200 def GenerateGpuTests(cls, options):
177 # This test causes the browser to try and restart the browser 3 times. 201 # This test causes the browser to try and restart the browser 3 times.
178 yield ('restart', 'restart.html', ()) 202 yield ('restart', 'restart.html', ())
179 203
180 def RunActualGpuTest(self, file_path, *args): 204 def RunActualGpuTest(self, file_path, *args):
181 # The logic of this test is run when the browser starts, it fails twice 205 # The logic of this test is run when the browser starts, it fails twice
182 # and then succeeds on the third time so we are just testing that this 206 # and then succeeds on the third time so we are just testing that this
183 # is successful based on the parameters. 207 # is successful based on the parameters.
184 pass 208 pass
185 209
186 210
187 class GpuIntegrationTestUnittest(unittest.TestCase): 211 def load_tests(loader, tests, pattern):
188 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') 212 del loader, tests, pattern # Unused.
189 def testSimpleIntegrationUnittest(self, mockInitDependencyManager): 213 return gpu_integration_test.LoadAllTestsInModule(sys.modules[__name__])
190 self._RunIntegrationTest(
191 'simple_integration_unittest', [
192 'unexpected_error',
193 'unexpected_failure'
194 ], [
195 'expected_failure',
196 'expected_flaky',
197 ])
198 # It might be nice to be more precise about the order of operations
199 # with these browser restarts, but this is at least a start.
200 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6)
201
202 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
203 def testIntegrationUnittestWithBrowserFailure(
204 self, mockInitDependencyManager):
205 self._RunIntegrationTest(
206 'browser_start_failure_integration_unittest', [], ['restart'])
207 self.assertEquals( \
208 BrowserStartFailureIntegrationUnittest._num_browser_crashes, 2)
209 self.assertEquals( \
210 BrowserStartFailureIntegrationUnittest._num_browser_starts, 3)
211
212 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
213 def testIntegrationUnittestWithBrowserCrashUponStart(
214 self, mockInitDependencyManager):
215 self._RunIntegrationTest(
216 'browser_crash_after_start_integration_unittest', [], ['restart'])
217 self.assertEquals( \
218 BrowserCrashAfterStartIntegrationUnittest._num_browser_crashes, 2)
219 self.assertEquals( \
220 BrowserCrashAfterStartIntegrationUnittest._num_browser_starts, 3)
221
222 def _RunIntegrationTest(self, test_name, failures, successes):
223 options = browser_test_runner.TestRunOptions()
224 # Suppress printing out information for passing tests.
225 options.verbosity = 0
226 config = gpu_project_config.CONFIG
227 temp_file = tempfile.NamedTemporaryFile(delete=False)
228 temp_file.close()
229 temp_file_name = temp_file.name
230 try:
231 browser_test_runner.Run(
232 config, options,
233 [test_name,
234 '--write-abbreviated-json-results-to=%s' % temp_file_name])
235 with open(temp_file_name) as f:
236 test_result = json.load(f)
237 self.assertEquals(test_result['failures'], failures)
238 self.assertEquals(test_result['successes'], successes)
239 self.assertEquals(test_result['valid'], True)
240
241 finally:
242 os.remove(temp_file_name)
OLDNEW
« no previous file with comments | « content/test/gpu/unittest_data/__init__.py ('k') | testing/scripts/run_gpu_integration_test_as_googletest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698