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

Side by Side Diff: content/test/gpu/gpu_tests/gpu_integration_test_unittest.py

Issue 2663813003: Roll out framework change & update gpu tests to conform to the API changes (Closed)
Patch Set: roll DEPS to 28f88ea6031634caa160d6c9ef720c8c1d9a30df 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 import json 5 import json
6 import logging 6 import logging
7 import mock
8 import os 7 import os
8 import sys
9 import tempfile 9 import tempfile
10 import unittest 10 import unittest
11 11
12 from telemetry.testing import fakes 12 from telemetry.testing import fakes
13 from telemetry.testing import browser_test_runner 13 from telemetry.testing import browser_test_runner
14 14
15 import gpu_project_config 15 import gpu_project_config
16 16
17 from gpu_tests import gpu_integration_test 17 from gpu_tests import gpu_integration_test
18 from gpu_tests import gpu_test_expectations 18 from gpu_tests import gpu_test_expectations
19 19
20 class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest): 20 class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest):
21 # Must be class-scoped since instances aren't reused across runs. 21 # Must be class-scoped since instances aren't reused across runs.
22 _num_flaky_runs_to_fail = 2 22 _num_flaky_runs_to_fail = 2
23 23
24 _num_browser_starts = 0 24 _num_browser_starts = 0
25 25
26 @classmethod 26 @classmethod
27 def Name(cls): 27 def Name(cls):
28 return 'simple_integration_unittest' 28 return 'simple_integration_unittest'
29 29
30 def setUp(self): 30 def setUp(self):
31 super(SimpleIntegrationUnittest, self).setUp() 31 super(SimpleIntegrationUnittest, self).setUp()
32 32
33 @classmethod 33 @classmethod
34 def setUpClass(cls): 34 def SetUpProcess(cls):
35 finder_options = fakes.CreateBrowserFinderOptions() 35 finder_options = fakes.CreateBrowserFinderOptions()
36 finder_options.browser_options.platform = fakes.FakeLinuxPlatform() 36 finder_options.browser_options.platform = fakes.FakeLinuxPlatform()
37 finder_options.output_formats = ['none'] 37 finder_options.output_formats = ['none']
38 finder_options.suppress_gtest_report = True 38 finder_options.suppress_gtest_report = True
39 finder_options.output_dir = None 39 finder_options.output_dir = None
40 finder_options.upload_bucket = 'public' 40 finder_options.upload_bucket = 'public'
41 finder_options.upload_results = False 41 finder_options.upload_results = False
42 cls._finder_options = finder_options 42 cls._finder_options = finder_options
43 cls.platform = None 43 cls.platform = None
44 cls.browser = None 44 cls.browser = None
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 raise Exception('Expected exception') 78 raise Exception('Expected exception')
79 79
80 80
81 class BrowserStartFailureIntegrationUnittest( 81 class BrowserStartFailureIntegrationUnittest(
82 gpu_integration_test.GpuIntegrationTest): 82 gpu_integration_test.GpuIntegrationTest):
83 83
84 _num_browser_crashes = 0 84 _num_browser_crashes = 0
85 _num_browser_starts = 0 85 _num_browser_starts = 0
86 86
87 @classmethod 87 @classmethod
88 def setUpClass(cls): 88 def SetUpProcess(cls):
89 cls._fake_browser_options = \ 89 cls._fake_browser_options = \
90 fakes.CreateBrowserFinderOptions(execute_on_startup=cls.CrashOnStart) 90 fakes.CreateBrowserFinderOptions(execute_on_startup=cls.CrashOnStart)
91 cls._fake_browser_options.browser_options.platform = \ 91 cls._fake_browser_options.browser_options.platform = \
92 fakes.FakeLinuxPlatform() 92 fakes.FakeLinuxPlatform()
93 cls._fake_browser_options.output_formats = ['none'] 93 cls._fake_browser_options.output_formats = ['none']
94 cls._fake_browser_options.suppress_gtest_report = True 94 cls._fake_browser_options.suppress_gtest_report = True
95 cls._fake_browser_options.output_dir = None 95 cls._fake_browser_options.output_dir = None
96 cls._fake_browser_options .upload_bucket = 'public' 96 cls._fake_browser_options .upload_bucket = 'public'
97 cls._fake_browser_options .upload_results = False 97 cls._fake_browser_options .upload_results = False
98 cls._finder_options = cls._fake_browser_options 98 cls._finder_options = cls._fake_browser_options
(...skipping 29 matching lines...) Expand all
128 pass 128 pass
129 129
130 130
131 class BrowserCrashAfterStartIntegrationUnittest( 131 class BrowserCrashAfterStartIntegrationUnittest(
132 gpu_integration_test.GpuIntegrationTest): 132 gpu_integration_test.GpuIntegrationTest):
133 133
134 _num_browser_crashes = 0 134 _num_browser_crashes = 0
135 _num_browser_starts = 0 135 _num_browser_starts = 0
136 136
137 @classmethod 137 @classmethod
138 def setUpClass(cls): 138 def SetUpProcess(cls):
139 cls._fake_browser_options = fakes.CreateBrowserFinderOptions( 139 cls._fake_browser_options = fakes.CreateBrowserFinderOptions(
140 execute_after_browser_creation=cls.CrashAfterStart) 140 execute_after_browser_creation=cls.CrashAfterStart)
141 cls._fake_browser_options.browser_options.platform = \ 141 cls._fake_browser_options.browser_options.platform = \
142 fakes.FakeLinuxPlatform() 142 fakes.FakeLinuxPlatform()
143 cls._fake_browser_options.output_formats = ['none'] 143 cls._fake_browser_options.output_formats = ['none']
144 cls._fake_browser_options.suppress_gtest_report = True 144 cls._fake_browser_options.suppress_gtest_report = True
145 cls._fake_browser_options.output_dir = None 145 cls._fake_browser_options.output_dir = None
146 cls._fake_browser_options .upload_bucket = 'public' 146 cls._fake_browser_options .upload_bucket = 'public'
147 cls._fake_browser_options .upload_results = False 147 cls._fake_browser_options .upload_results = False
148 cls._finder_options = cls._fake_browser_options 148 cls._finder_options = cls._fake_browser_options
(...skipping 29 matching lines...) Expand all
178 yield ('restart', 'restart.html', ()) 178 yield ('restart', 'restart.html', ())
179 179
180 def RunActualGpuTest(self, file_path, *args): 180 def RunActualGpuTest(self, file_path, *args):
181 # The logic of this test is run when the browser starts, it fails twice 181 # 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 182 # and then succeeds on the third time so we are just testing that this
183 # is successful based on the parameters. 183 # is successful based on the parameters.
184 pass 184 pass
185 185
186 186
187 class GpuIntegrationTestUnittest(unittest.TestCase): 187 class GpuIntegrationTestUnittest(unittest.TestCase):
188 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') 188 def testSimpleIntegrationUnittest(self):
189 def testSimpleIntegrationUnittest(self, mockInitDependencyManager):
190 self._RunIntegrationTest( 189 self._RunIntegrationTest(
191 'simple_integration_unittest', [ 190 'simple_integration_unittest', [
192 'unexpected_error', 191 'unexpected_error',
193 'unexpected_failure' 192 'unexpected_failure'
194 ], [ 193 ], [
195 'expected_failure', 194 'expected_failure',
196 'expected_flaky', 195 'expected_flaky',
197 ]) 196 ])
198 # It might be nice to be more precise about the order of operations 197 # 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. 198 # with these browser restarts, but this is at least a start.
200 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6) 199 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6)
201 200
202 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') 201 def testIntegrationUnittestWithBrowserFailure(self):
203 def testIntegrationUnittestWithBrowserFailure(
204 self, mockInitDependencyManager):
205 self._RunIntegrationTest( 202 self._RunIntegrationTest(
206 'browser_start_failure_integration_unittest', [], ['restart']) 203 'browser_start_failure_integration_unittest', [], ['restart'])
207 self.assertEquals( \ 204 self.assertEquals( \
208 BrowserStartFailureIntegrationUnittest._num_browser_crashes, 2) 205 BrowserStartFailureIntegrationUnittest._num_browser_crashes, 2)
209 self.assertEquals( \ 206 self.assertEquals( \
210 BrowserStartFailureIntegrationUnittest._num_browser_starts, 3) 207 BrowserStartFailureIntegrationUnittest._num_browser_starts, 3)
211 208
212 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') 209 def testIntegrationUnittestWithBrowserCrashUponStart(self):
213 def testIntegrationUnittestWithBrowserCrashUponStart(
214 self, mockInitDependencyManager):
215 self._RunIntegrationTest( 210 self._RunIntegrationTest(
216 'browser_crash_after_start_integration_unittest', [], ['restart']) 211 'browser_crash_after_start_integration_unittest', [], ['restart'])
217 self.assertEquals( \ 212 self.assertEquals( \
218 BrowserCrashAfterStartIntegrationUnittest._num_browser_crashes, 2) 213 BrowserCrashAfterStartIntegrationUnittest._num_browser_crashes, 2)
219 self.assertEquals( \ 214 self.assertEquals( \
220 BrowserCrashAfterStartIntegrationUnittest._num_browser_starts, 3) 215 BrowserCrashAfterStartIntegrationUnittest._num_browser_starts, 3)
221 216
222 def _RunIntegrationTest(self, test_name, failures, successes): 217 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 218 config = gpu_project_config.CONFIG
227 temp_file = tempfile.NamedTemporaryFile(delete=False) 219 temp_file = tempfile.NamedTemporaryFile(delete=False)
228 temp_file.close() 220 temp_file.close()
229 temp_file_name = temp_file.name 221 temp_file_name = temp_file.name
230 try: 222 try:
231 browser_test_runner.Run( 223 browser_test_runner.Run(
232 config, options, 224 config,
233 [test_name, 225 [test_name,
234 '--write-abbreviated-json-results-to=%s' % temp_file_name]) 226 '--write-full-results-to=%s' % temp_file_name])
235 with open(temp_file_name) as f: 227 with open(temp_file_name) as f:
236 test_result = json.load(f) 228 test_result = json.load(f)
237 self.assertEquals(test_result['failures'], failures) 229 actual_successes, actual_failures = self._ExtracTestResults(test_result)
238 self.assertEquals(test_result['successes'], successes) 230 self.assertEquals(actual_failures, failures)
239 self.assertEquals(test_result['valid'], True) 231 self.assertEquals(actual_successes, successes)
240 232
241 finally: 233 finally:
242 os.remove(temp_file_name) 234 os.remove(temp_file_name)
235
236 def _ExtracTestResults(self, test_result):
237 delimiter = test_result['path_delimiter']
238 failures = []
239 successes = []
240 def _IsLeafNode(node):
241 test_dict = node[1]
242 return ('expected' in test_dict and
243 isinstance(test_dict['expected'], basestring))
244 node_queues = []
245 for t in test_result['tests']:
246 node_queues.append((t, test_result['tests'][t]))
247 while node_queues:
248 node = node_queues.pop()
249 full_test_name, test_dict = node
250 if _IsLeafNode(node):
251 if all(res not in test_dict['expected'].split() for res in
252 test_dict['actual'].split()):
253 failures.append(full_test_name)
254 else:
255 successes.append(full_test_name)
256 else:
257 for k in test_dict:
258 node_queues.append(
259 ('%s%s%s' % (full_test_name, delimiter, k),
260 test_dict[k]))
261 return successes, failures
262
263
264 def load_tests(loader, tests, pattern):
Ken Russell (switch to Gerrit) 2017/02/22 00:41:45 Hmm. Does this test run correctly as part of gpu_u
nednguyen 2017/02/22 00:46:06 Yes it does. In the typ change, I have logic that
Ken Russell (switch to Gerrit) 2017/02/22 00:57:20 It looks like something's wrong. See this dry run
265 del loader, tests, pattern # Unused.
266 return gpu_integration_test.LoadAllTestsInModule(
267 sys.modules[__name__])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698