Added more detailed result codes for CreateViewCommandBuffer.
[chromium-blink-merge.git] / content / test / gpu / gpu_tests / context_lost.py
blob731fffbfd4c7485f106b472f0dd4427a673db6b9
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
3 # found in the LICENSE file.
4 import os
6 from telemetry import benchmark as benchmark_module
7 from telemetry.core import exceptions
8 from telemetry.core import util
9 from telemetry.page import page
10 from telemetry.page import page_set
11 from telemetry.page import page_test
13 data_path = os.path.join(
14 util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu')
16 wait_timeout = 20 # seconds
18 harness_script = r"""
19 var domAutomationController = {};
21 domAutomationController._loaded = false;
22 domAutomationController._succeeded = false;
23 domAutomationController._finished = false;
25 domAutomationController.setAutomationId = function(id) {}
27 domAutomationController.send = function(msg) {
28 msg = msg.toLowerCase()
29 if (msg == "loaded") {
30 domAutomationController._loaded = true;
31 } else if (msg == "success") {
32 domAutomationController._succeeded = true;
33 domAutomationController._finished = true;
34 } else {
35 domAutomationController._succeeded = false;
36 domAutomationController._finished = true;
40 window.domAutomationController = domAutomationController;
41 console.log("Harness injected.");
42 """
44 class _ContextLostValidator(page_test.PageTest):
45 def __init__(self):
46 # Strictly speaking this test doesn't yet need a browser restart
47 # after each run, but if more tests are added which crash the GPU
48 # process, then it will.
49 super(_ContextLostValidator, self).__init__(
50 needs_browser_restart_after_each_page=True)
52 def CustomizeBrowserOptions(self, options):
53 options.AppendExtraBrowserArgs(
54 '--disable-domain-blocking-for-3d-apis')
55 options.AppendExtraBrowserArgs(
56 '--disable-gpu-process-crash-limit')
57 # Required for about:gpucrash handling from Telemetry.
58 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
60 def ValidatePage(self, page, tab, results):
61 if page.kill_gpu_process:
62 # Doing the GPU process kill operation cooperatively -- in the
63 # same page's context -- is much more stressful than restarting
64 # the browser every time.
65 for x in range(page.number_of_gpu_process_kills):
66 if not tab.browser.supports_tab_control:
67 raise page_test.Failure('Browser must support tab control')
68 # Reset the test's state.
69 tab.EvaluateJavaScript(
70 'window.domAutomationController._succeeded = false');
71 tab.EvaluateJavaScript(
72 'window.domAutomationController._finished = false');
73 # Crash the GPU process.
74 new_tab = tab.browser.tabs.New()
75 # To access these debug URLs from Telemetry, they have to be
76 # written using the chrome:// scheme.
77 # The try/except is a workaround for crbug.com/368107.
78 try:
79 new_tab.Navigate('chrome://gpucrash')
80 except (exceptions.TabCrashException, Exception):
81 print 'Tab crashed while navigating to chrome://gpucrash'
82 # Activate the original tab and wait for completion.
83 tab.Activate()
84 completed = False
85 try:
86 util.WaitFor(lambda: tab.EvaluateJavaScript(
87 'window.domAutomationController._finished'), wait_timeout)
88 completed = True
89 except util.TimeoutException:
90 pass
91 # The try/except is a workaround for crbug.com/368107.
92 try:
93 new_tab.Close()
94 except (exceptions.TabCrashException, Exception):
95 print 'Tab crashed while closing chrome://gpucrash'
96 if not completed:
97 raise page_test.Failure(
98 'Test didn\'t complete (no context lost event?)')
99 if not tab.EvaluateJavaScript(
100 'window.domAutomationController._succeeded'):
101 raise page_test.Failure(
102 'Test failed (context not restored properly?)')
103 elif page.force_garbage_collection:
104 # Try to corce GC to clean up any contexts not attached to the page.
105 # This method seem unreliable, so the page will also attempt to force
106 # GC through excessive allocations.
107 tab.CollectGarbage()
108 completed = False
109 try:
110 print "Waiting for page to finish."
111 util.WaitFor(lambda: tab.EvaluateJavaScript(
112 'window.domAutomationController._finished'), wait_timeout)
113 completed = True
114 except util.TimeoutException:
115 pass
117 if not completed:
118 raise page_test.Failure(
119 'Test didn\'t complete (no context restored event?)')
120 if not tab.EvaluateJavaScript(
121 'window.domAutomationController._succeeded'):
122 raise page_test.Failure(
123 'Test failed (context not restored properly?)')
124 else:
125 completed = False
126 try:
127 print "Waiting for page to finish."
128 util.WaitFor(lambda: tab.EvaluateJavaScript(
129 'window.domAutomationController._finished'), wait_timeout)
130 completed = True
131 except util.TimeoutException:
132 pass
134 if not completed:
135 raise page_test.Failure('Test didn\'t complete')
136 if not tab.EvaluateJavaScript(
137 'window.domAutomationController._succeeded'):
138 raise page_test.Failure('Test failed')
140 class WebGLContextLostFromGPUProcessExitPage(page.Page):
141 def __init__(self, page_set, base_dir):
142 super(WebGLContextLostFromGPUProcessExitPage, self).__init__(
143 url='file://webgl.html?query=kill_after_notification',
144 page_set=page_set,
145 base_dir=base_dir,
146 name='ContextLost.WebGLContextLostFromGPUProcessExit')
147 self.script_to_evaluate_on_commit = harness_script
148 self.kill_gpu_process = True
149 self.number_of_gpu_process_kills = 1
150 self.force_garbage_collection = False
152 def RunNavigateSteps(self, action_runner):
153 action_runner.NavigateToPage(self)
154 action_runner.WaitForJavaScriptCondition(
155 'window.domAutomationController._loaded')
158 class WebGLContextLostFromLoseContextExtensionPage(page.Page):
159 def __init__(self, page_set, base_dir):
160 super(WebGLContextLostFromLoseContextExtensionPage, self).__init__(
161 url='file://webgl.html?query=WEBGL_lose_context',
162 page_set=page_set,
163 base_dir=base_dir,
164 name='ContextLost.WebGLContextLostFromLoseContextExtension')
165 self.script_to_evaluate_on_commit = harness_script
166 self.kill_gpu_process = False
167 self.force_garbage_collection = False
169 def RunNavigateSteps(self, action_runner):
170 action_runner.NavigateToPage(self)
171 action_runner.WaitForJavaScriptCondition(
172 'window.domAutomationController._finished')
174 class WebGLContextLostFromQuantityPage(page.Page):
175 def __init__(self, page_set, base_dir):
176 super(WebGLContextLostFromQuantityPage, self).__init__(
177 url='file://webgl.html?query=forced_quantity_loss',
178 page_set=page_set,
179 base_dir=base_dir,
180 name='ContextLost.WebGLContextLostFromQuantity')
181 self.script_to_evaluate_on_commit = harness_script
182 self.kill_gpu_process = False
183 self.force_garbage_collection = True
185 def RunNavigateSteps(self, action_runner):
186 action_runner.NavigateToPage(self)
187 action_runner.WaitForJavaScriptCondition(
188 'window.domAutomationController._loaded')
190 class WebGLContextLostFromSelectElementPage(page.Page):
191 def __init__(self, page_set, base_dir):
192 super(WebGLContextLostFromSelectElementPage, self).__init__(
193 url='file://webgl_with_select_element.html',
194 page_set=page_set,
195 base_dir=base_dir,
196 name='ContextLost.WebGLContextLostFromSelectElement')
197 self.script_to_evaluate_on_commit = harness_script
198 self.kill_gpu_process = False
199 self.force_garbage_collection = False
201 def RunNavigateSteps(self, action_runner):
202 action_runner.NavigateToPage(self)
203 action_runner.WaitForJavaScriptCondition(
204 'window.domAutomationController._loaded')
206 class ContextLost(benchmark_module.Benchmark):
207 enabled = True
208 test = _ContextLostValidator
209 # For the record, this would have been another way to get the pages
210 # to repeat. pageset_repeat would be another option.
211 # options = {'page_repeat': 5}
212 def CreatePageSet(self, options):
213 ps = page_set.PageSet(
214 file_path=data_path,
215 user_agent_type='desktop',
216 serving_dirs=set(['']))
217 ps.AddPage(WebGLContextLostFromGPUProcessExitPage(ps, ps.base_dir))
218 ps.AddPage(WebGLContextLostFromLoseContextExtensionPage(ps, ps.base_dir))
219 ps.AddPage(WebGLContextLostFromQuantityPage(ps, ps.base_dir))
220 ps.AddPage(WebGLContextLostFromSelectElementPage(ps, ps.base_dir))
221 return ps