Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / content / test / gpu / gpu_tests / gpu_test_expectations.py
blob196c7b68c1bae3c1a4168c6070475fb5756f83a9
1 # Copyright 2014 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.
5 import test_expectations
7 ANGLE_CONDITIONS = ['d3d9', 'd3d11', 'opengl']
9 GPU_CONDITIONS = ['amd', 'arm', 'broadcom', 'hisilicon', 'intel', 'imagination',
10 'nvidia', 'qualcomm', 'vivante']
12 class GpuExpectation(test_expectations.Expectation):
13 def __init__(self, expectation, pattern, conditions=None, bug=None,
14 max_num_retries=0):
15 self.gpu_conditions = []
16 self.device_id_conditions = []
17 self.angle_conditions = []
18 self.max_num_retries = max_num_retries
19 assert self.max_num_retries == 0 or expectation == 'flaky'
20 super(GpuExpectation, self).__init__(
21 expectation, pattern, conditions=conditions, bug=bug)
23 def ParseCondition(self, condition):
24 """Adds support for GPU, device ID, and ANGLE conditions.
26 GPU vendors:
27 amd, arm, broadcom, hisilicon, intel, imagination, nvidia,
28 qualcomm, vivante
30 ANGLE renderer:
31 d3d9, d3d11, opengl
33 Specific GPUs can be listed as a tuple with vendor name and device ID.
34 Examples: ('nvidia', 0x1234), ('arm', 'Mali-T604')
35 Device IDs must be paired with a GPU vendor.
37 Sample usage in SetExpectations in subclasses:
38 self.Fail('gl-enable-vertex-attrib.html',
39 ['mac', 'amd', ('nvidia', 0x1234)], bug=123)
40 """
41 if isinstance(condition, tuple):
42 c0 = condition[0].lower()
43 if c0 in GPU_CONDITIONS:
44 self.device_id_conditions.append((c0, condition[1]))
45 else:
46 raise ValueError('Unknown expectation condition: "%s"' % c0)
47 else:
48 cl = condition.lower()
49 if cl in GPU_CONDITIONS:
50 self.gpu_conditions.append(cl)
51 elif cl in ANGLE_CONDITIONS:
52 self.angle_conditions.append(cl)
53 else:
54 # Delegate to superclass.
55 super(GpuExpectation, self).ParseCondition(condition)
58 class GpuTestExpectations(test_expectations.TestExpectations):
59 def CreateExpectation(self, expectation, pattern, conditions=None,
60 bug=None):
61 return GpuExpectation(expectation, pattern, conditions, bug)
63 def Flaky(self, pattern, conditions=None, bug=None, max_num_retries=2):
64 self._AddExpectation(GpuExpectation(
65 'flaky', pattern, conditions=conditions, bug=bug,
66 max_num_retries=max_num_retries))
68 def GetFlakyRetriesForPage(self, browser, page):
69 e = self._GetExpectationObjectForPage(browser, page)
70 if e:
71 return e.max_num_retries
72 return 0
74 def ExpectationAppliesToPage(self, expectation, browser, page):
75 if not super(GpuTestExpectations, self).ExpectationAppliesToPage(
76 expectation, browser, page):
77 return False
79 # We'll only get here if the OS and browser type matched the expectation.
80 gpu_matches = True
81 angle_renderer = ''
83 if browser.supports_system_info:
84 gpu_info = browser.GetSystemInfo().gpu
85 gpu_vendor = self._GetGpuVendorString(gpu_info)
86 gpu_device_id = self._GetGpuDeviceId(gpu_info)
87 gpu_matches = ((not expectation.gpu_conditions and
88 not expectation.device_id_conditions) or
89 gpu_vendor in expectation.gpu_conditions or
90 (gpu_vendor, gpu_device_id) in expectation.device_id_conditions)
91 angle_renderer = self._GetANGLERenderer(gpu_info)
92 angle_matches = (
93 (not expectation.angle_conditions) or
94 angle_renderer in expectation.angle_conditions)
96 return gpu_matches and angle_matches
98 def _GetGpuVendorString(self, gpu_info):
99 if gpu_info:
100 primary_gpu = gpu_info.devices[0]
101 if primary_gpu:
102 vendor_string = primary_gpu.vendor_string.lower()
103 vendor_id = primary_gpu.vendor_id
104 if vendor_string:
105 return vendor_string.split(' ')[0]
106 elif vendor_id == 0x10DE:
107 return 'nvidia'
108 elif vendor_id == 0x1002:
109 return 'amd'
110 elif vendor_id == 0x8086:
111 return 'intel'
112 return 'unknown_gpu'
114 def _GetGpuDeviceId(self, gpu_info):
115 if gpu_info:
116 primary_gpu = gpu_info.devices[0]
117 if primary_gpu:
118 return primary_gpu.device_id or primary_gpu.device_string
119 return 0
121 def _GetANGLERenderer(self, gpu_info):
122 if gpu_info and gpu_info.aux_attributes:
123 gl_renderer = gpu_info.aux_attributes.get('gl_renderer')
124 if gl_renderer:
125 if 'Direct3D11' in gl_renderer:
126 return 'd3d11'
127 elif 'Direct3D9' in gl_renderer:
128 return 'd3d9'
129 elif 'OpenGL' in gl_renderer:
130 return 'opengl'
131 return ''