framework: fix run with valgrind option
[piglit.git] / framework / test / opengl.py
blob2f1c5e157b1bca9adc0470635736f27353016bb1
1 # coding=utf-8
2 # Copyright (c) 2015-2016, 2019 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
22 """Mixins for OpenGL derived tests."""
24 import os
25 import warnings
27 from framework import wflinfo
28 from .base import TestIsSkip
30 # pylint: disable=too-few-public-methods
32 __all__ = [
33 'FastSkip',
34 'FastSkipMixin',
38 class FastSkip(object):
39 """A class for testing OpenGL requirements.
41 This class provides a mechanism for testing OpenGL requirements, and
42 skipping tests that have unmet requirements
44 This requires wflinfo to be installed and accessible to provide its
45 functionality, however, it will no-op if wflinfo is not accessible.
47 The design of this function is conservative. The design goal is that it
48 it is better to run a few tests that could have been skipped, than to skip
49 all the tests that could have, but also a few that should have run.
51 Keyword Arguments:
52 api -- The API required.
53 One of [gles1, gles2, gles3, core, compat]
54 extensions -- A set of extensions required
55 api_version -- The version of the API required
56 shader_version -- The versoin of the shader language required
57 """
58 __slots__ = ['api', 'extensions', 'api_version', 'shader_version']
60 info = wflinfo.WflInfo()
62 def __init__(self, api=None, extensions=None, api_version=None,
63 shader_version=None):
64 self.extensions = extensions or set()
65 self.api = api
66 self.api_version = api_version
67 self.shader_version = shader_version
69 def test(self):
70 """Skip this test if any of its feature requirements are unmet.
72 If no extensions were calculated (if wflinfo isn't installed) then run
73 all tests.
75 Raises:
76 TestIsSkip -- if any of the conditions passed to self are false
77 """
78 if not self.api:
79 check = self.info.compat
80 elif self.api in ['gles2', 'gles3']:
81 check = self.info.es2
82 elif self.api == 'gles1':
83 check = self.info.es1
84 else:
85 check = getattr(self.info, self.api)
87 if check.extensions:
88 for extension in self.extensions:
89 if extension not in check.extensions:
90 raise TestIsSkip(
91 'Test requires extension {} '
92 'which is not available'.format(extension))
94 # TODO: Be able to handle any operator
95 if (check.api_version is not None
96 and self.api_version is not None
97 and self.api_version > check.api_version):
98 raise TestIsSkip(
99 'Test requires OpenGL {} version {}, '
100 'but only {} is available'.format(
101 self.api, self.api_version, check.api_version))
103 # TODO: Be able to handle any operator
104 if (check.shader_version is not None
105 and self.shader_version is not None
106 and self.shader_version > check.shader_version):
107 raise TestIsSkip(
108 'Test requires OpenGL {} Shader Language version {}, '
109 'but only {} is available'.format(
110 self.api, self.shader_version, check.shader_version))
113 class FastSkipMixin(object):
114 """Fast test skipping for OpenGL based suites.
116 This provides an is_skip() method which will skip the test if any of its
117 requirements are not met.
119 This is a wrapper around the FastSkip object which makes it easier to
120 integrate into existing classes (and maintains API compatibility). It thus
121 has all of the same requirements as that class.
123 It also provides new attributes:
124 require_extensions -- A set of extensions that are requuired for running
125 this test.
126 require_shader -- The shader language version required.
127 reqiure_version -- The API version required.
128 require_api -- The API required.
131 def __init__(self, command, api=None, extensions=None, api_version=None,
132 shader_version=None, **kwargs):
133 super(FastSkipMixin, self).__init__(command, **kwargs)
134 self.__skiper = FastSkip(api=api,
135 extensions=extensions,
136 api_version=api_version,
137 shader_version=shader_version)
139 @property
140 def require_extensions(self):
141 return self.__skiper.extensions
143 @property
144 def require_api(self):
145 return self.__skiper.api
147 @property
148 def require_shader(self):
149 return self.__skiper.shader_version
151 @property
152 def require_version(self):
153 return self.__skiper.api_version
155 def is_skip(self):
156 """Skip this test if any of its feature requirements are unmet.
158 If no extensions were calculated (if wflinfo isn't installed) then run
159 all tests.
161 self.__skiper.test()
163 super(FastSkipMixin, self).is_skip()
166 class FastSkipDisabled(object):
167 """A no-op version of FastSkip."""
169 __slots__ = ['api', 'extensions', 'api_version', 'shader_version']
171 info = wflinfo.WflInfo()
173 def __init__(self, api=None, extensions=None, api_version=None,
174 shader_version=None):
175 self.extensions = set()
176 self.api = api
177 self.api_version = api_version
178 self.shader_version = shader_version
180 def test(self):
181 pass
184 class FastSkipMixinDisabled(object):
185 def __init__(self, command, api=None, extensions=None, api_version=None,
186 shader_version=None, **kwargs):
187 # Tests that implement the FastSkipMixin expect to have these values
188 # set, so just fill them in with the default values.
189 self.require_extensions = set()
190 self.require_shader = None
191 self.reqiure_version = None
192 self.require_api = None
194 super(FastSkipMixinDisabled, self).__init__(command, **kwargs)
197 # Shadow the real FastSkipMixin with the Disabled version if
198 # PIGLIT_NO_FAST_SKIP is truthy
199 if bool(os.environ.get('PIGLIT_NO_FAST_SKIP', False)):
200 warnings.warn('Fast Skipping Disabled')
201 # TODO: we can probably get rid of the FastSkipMixinDisabled and just rely
202 # on the FastSkipDisabled
203 # pylint: disable=invalid-name
204 FastSkipMixin = FastSkipMixinDisabled
205 FastSkip = FastSkipDisabled