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,
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.
27 amd, arm, broadcom, hisilicon, intel, imagination, nvidia,
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)
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]))
46 raise ValueError('Unknown expectation condition: "%s"' % c0
)
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
)
54 # Delegate to superclass.
55 super(GpuExpectation
, self
).ParseCondition(condition
)
58 class GpuTestExpectations(test_expectations
.TestExpectations
):
59 def CreateExpectation(self
, expectation
, pattern
, conditions
=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
)
71 return e
.max_num_retries
74 def ExpectationAppliesToPage(self
, expectation
, browser
, page
):
75 if not super(GpuTestExpectations
, self
).ExpectationAppliesToPage(
76 expectation
, browser
, page
):
79 # We'll only get here if the OS and browser type matched the expectation.
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
)
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
):
100 primary_gpu
= gpu_info
.devices
[0]
102 vendor_string
= primary_gpu
.vendor_string
.lower()
103 vendor_id
= primary_gpu
.vendor_id
105 return vendor_string
.split(' ')[0]
106 elif vendor_id
== 0x10DE:
108 elif vendor_id
== 0x1002:
110 elif vendor_id
== 0x8086:
114 def _GetGpuDeviceId(self
, gpu_info
):
116 primary_gpu
= gpu_info
.devices
[0]
118 return primary_gpu
.device_id
or primary_gpu
.device_string
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')
125 if 'Direct3D11' in gl_renderer
:
127 elif 'Direct3D9' in gl_renderer
:
129 elif 'OpenGL' in gl_renderer
: