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 # Valid expectation conditions are:
10 # win, xp, vista, win7, mac, leopard, snowleopard, lion, mountainlion,
11 # mavericks, yosemite, linux, chromeos, android
14 # amd, arm, broadcom, hisilicon, intel, imagination, nvidia, qualcomm,
18 # android-webview-shell, android-content-shell, debug
23 # Specific GPUs can be listed as a tuple with vendor name and device ID.
24 # Examples: ('nvidia', 0x1234), ('arm', 'Mali-T604')
25 # Device IDs must be paired with a GPU vendor.
27 # Sample usage in SetExpectations in subclasses:
28 # self.Fail('gl-enable-vertex-attrib.html',
29 # ['mac', 'amd', ('nvidia', 0x1234)], bug=123)
31 ANGLE_MODIFIERS
= ['d3d9', 'd3d11', 'opengl']
33 BROWSER_TYPE_MODIFIERS
= [
34 'android-webview-shell', 'android-content-shell', 'debug' ]
36 class _FlakyExpectation(object):
37 def __init__(self
, expectation
, max_num_retries
):
38 self
.expectation
= expectation
39 self
.max_num_retries
= max_num_retries
41 class GpuTestExpectations(test_expectations
.TestExpectations
):
43 self
._flaky
_expectations
= []
44 super(GpuTestExpectations
, self
).__init
__()
46 def Flaky(self
, url_pattern
, conditions
=None, bug
=None, max_num_retries
=2):
47 expectation
= _FlakyExpectation(self
.CreateExpectation(
48 'pass', url_pattern
, conditions
, bug
), max_num_retries
)
49 self
._flaky
_expectations
.append(expectation
)
51 def GetFlakyRetriesForPage(self
, page
, browser
):
52 for fe
in self
._flaky
_expectations
:
54 if self
.ExpectationAppliesToPage(e
, browser
, page
):
55 return fe
.max_num_retries
58 def IsValidUserDefinedCondition(self
, condition
):
59 # Add support for d3d9, d3d11 and opengl-specific expectations.
60 if condition
in ANGLE_MODIFIERS
:
62 # Add support for browser-type-specific expectations.
63 if condition
in BROWSER_TYPE_MODIFIERS
:
65 return super(GpuTestExpectations
,
66 self
).IsValidUserDefinedCondition(condition
)
68 def ModifiersApply(self
, browser
, expectation
):
69 if not super(GpuTestExpectations
, self
).ModifiersApply(
70 browser
, expectation
):
73 # We'll only get here if the OS and GPU matched the expectation.
75 # TODO(kbr): refactor _Expectation to be a public class so that
76 # the GPU-specific properties can be moved into a subclass, and
77 # run the unit tests from this directory on the CQ and the bots.
78 # crbug.com/495868 crbug.com/495870
80 # Check for presence of Android WebView.
81 browser_expectations
= [x
for x
in expectation
.user_defined_conditions
82 if x
in BROWSER_TYPE_MODIFIERS
]
83 browser_matches
= ((not browser_expectations
) or
84 browser
.browser_type
in browser_expectations
)
85 if not browser_matches
:
89 if browser
.supports_system_info
:
90 gpu_info
= browser
.GetSystemInfo().gpu
91 if gpu_info
and gpu_info
.aux_attributes
:
92 gl_renderer
= gpu_info
.aux_attributes
.get('gl_renderer')
94 if 'Direct3D11' in gl_renderer
:
95 angle_renderer
= 'd3d11'
96 elif 'Direct3D9' in gl_renderer
:
97 angle_renderer
= 'd3d9'
98 elif 'OpenGL' in gl_renderer
:
99 angle_renderer
= 'opengl'
100 angle_expectations
= [x
for x
in expectation
.user_defined_conditions
101 if x
in ANGLE_MODIFIERS
]
102 angle_matches
= ((not angle_expectations
) or
103 angle_renderer
in angle_expectations
)