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
22 """Test the wflinfo module."""
27 from unittest
import mock
33 from framework
import wflinfo
35 # pylint: disable=no-self-use,attribute-defined-outside-init,protected-access
39 """Return True if wflinfo is available in PATH."""
41 subprocess
.check_call(['wflinfo', '--help'])
42 except subprocess
.CalledProcessError
:
51 @pytest.mark
.skipif(not _has_wflinfo(), reason
="Tests require wflinfo binary.")
52 class TestWflInfo(object):
53 """Tests for the WflInfo class."""
55 class TestAttributes(object):
56 """test for attribute assignments."""
58 @pytest.fixture(autouse
=True)
60 """Mock a few things for testing purposes."""
61 # This is pretty ugly, but as a Borb with a private shared state,
62 # the only way to test this module is to actually replace the
63 # shared_state with a mock value so it's reset after each test
64 with mock
.patch
.dict('framework.wflinfo.OPTIONS.env',
65 {'PIGLIT_PLATFORM': 'foo'}), \
67 'framework.wflinfo.WflInfo._WflInfo__shared_state',
72 """Setup each instance, patching necissary bits."""
73 self
._test
= wflinfo
.WflInfo()
75 def test_extension(self
):
76 """wflinfo.WflInfo.<api>.extensions: Provides list of gl
79 rv
= textwrap
.dedent("""\
83 OpenGL version string: 1.1
84 OpenGL shading language: 1.1
85 OpenGL extensions: GL_foobar GL_ham_sandwhich
87 expected
= set(['GL_foobar', 'GL_ham_sandwhich'])
89 with mock
.patch('framework.wflinfo.subprocess.check_output',
90 mock
.Mock(return_value
=rv
)):
91 assert self
._test
.compat
.extensions
== expected
93 def test_api_version(self
):
94 """wflinfo.WflInfo.<api>.api_version: Provides a version number."""
95 rv
= textwrap
.dedent("""\
98 OpenGL vendor string: Intel Open Source Technology Center
99 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
100 OpenGL context flags: 0x0
101 OpenGL shading language: 1.1
102 OpenGL extensions: GL_foobar GL_ham_sandwhich
103 OpenGL version string: 18 (Compat Profile) Mesa 11.0.4
105 with mock
.patch('framework.wflinfo.subprocess.check_output',
106 mock
.Mock(return_value
=rv
)):
107 assert self
._test
.compat
.api_version
== 18.0
109 def test_api_version_gles(self
):
110 """wflinfo.WflInfo.<es>.api_version: Provides a version number.
112 The format for GLES is different than for Desktop GL.
114 rv
= textwrap
.dedent("""\
117 OpenGL vendor string: Intel Open Source Technology Center
118 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
119 OpenGL version string: OpenGL ES 7.1 Mesa 11.0.4
120 OpenGL shading language: 1.1
121 OpenGL extensions: GL_foobar GL_ham_sandwhich
123 with mock
.patch('framework.wflinfo.subprocess.check_output',
124 mock
.Mock(return_value
=rv
)):
125 assert self
._test
.es2
.api_version
== 7.1
127 def test_glsl_version(self
):
128 """wflinfo.WflInfo.<api>.shader_version: Provides a version number."""
129 rv
= textwrap
.dedent("""\
132 OpenGL vendor string: Intel Open Source Technology Center
133 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
134 OpenGL version string: 1.1 (Core Profile) Mesa 11.0.4
135 OpenGL context flags: 0x0
136 OpenGL shading language version string: 9.30
137 OpenGL extensions: this is some extension strings.
139 with mock
.patch('framework.wflinfo.subprocess.check_output',
140 mock
.Mock(return_value
=rv
)):
141 assert self
._test
.core
.shader_version
== 9.3
143 def test_glsl_es_version(self
):
144 """wflinfo.WflInfo.<es>.shader_version: works with gles2."""
145 rv
= textwrap
.dedent("""\
148 Wflinfo vendor string: Intel Open Source Technology Center
149 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
150 OpenGL version string: OpenGL ES 3.0 Mesa 11.0.4
151 OpenGL shading language version string: OpenGL ES GLSL ES 1.0.17
152 OpenGL version string: 1.1 (Core Profile) Mesa 11.0.4
153 OpenGL extensions: this is some extension strings.
155 with mock
.patch('framework.wflinfo.subprocess.check_output',
156 mock
.Mock(return_value
=rv
)):
157 assert self
._test
.es2
.shader_version
== 1.0
159 def test_gl_version_patch(self
):
160 """wflinfo.WflInfo.*.api_version: Works with patch versions."""
161 rv
= textwrap
.dedent("""\
164 OpenGL vendor string: Intel Open Source Technology Center
165 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
166 OpenGL version string: 18.0.1 (Core Profile) Mesa 11.0.4
167 OpenGL shading language version string: OpenGL ES GLSL ES 5.00
168 OpenGL extensions: this is some extension strings.
169 OpenGL context flags: 0x0
171 with mock
.patch('framework.wflinfo.subprocess.check_output',
172 mock
.Mock(return_value
=rv
)):
173 assert self
._test
.core
.api_version
== 18.0
175 def test_glsl_version_patch(self
):
176 """wflinfo.WflInfo.*.shader_version: Works with patch versions."""
177 rv
= textwrap
.dedent("""\
180 OpenGL vendor string: Intel Open Source Technology Center
181 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
182 OpenGL version string: 1.1 (Core Profile) Mesa 11.0.4
183 OpenGL context flags: 0x0
184 OpenGL shading language version string: 9.30.7
185 OpenGL extensions: this is some extension strings.
187 with mock
.patch('framework.wflinfo.subprocess.check_output',
188 mock
.Mock(return_value
=rv
)):
189 assert self
._test
.core
.shader_version
== 9.3
191 def test_leading_junk(self
):
192 """wflinfo.WflInfo.*.api_version: Handles leading junk."""
193 rv
= textwrap
.dedent("""\
194 Warning: I'm a big fat warnngs
197 OpenGL vendor string: Intel Open Source Technology Center
198 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
199 OpenGL version string: 18.0.1 (Core Profile) Mesa 11.0.4
200 OpenGL context flags: 0x0
201 OpenGL shading language version string: 9.30.7
202 OpenGL extensions: ARB_ham_sandwich
204 with mock
.patch('framework.wflinfo.subprocess.check_output',
205 mock
.Mock(return_value
=rv
)):
206 assert self
._test
.core
.api_version
== 18.0
208 def test_mixed_junk(self
):
209 """wflinfo.WflInfo.*.api_version: Handles mixed junk."""
210 rv
= textwrap
.dedent("""\
213 Warning: I'm a big fat warnngs
214 OpenGL vendor string: Intel Open Source Technology Center
215 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
216 Warning: I'm a big fat warnngs
217 Warning: I'm a big fat warnngs
218 OpenGL version string: 18.0.1 (Core Profile) Mesa 11.0.4
219 OpenGL context flags: 0x0
220 OpenGL shading language version string: 9.30.7
221 OpenGL extensions: ARB_ham_sandwich
223 with mock
.patch('framework.wflinfo.subprocess.check_output',
224 mock
.Mock(return_value
=rv
)):
225 assert self
._test
.core
.api_version
== 18.0
227 class TestWAFFLEINFO_GL_ERROR(object):
228 """Test class for WflInfo when "WFLINFO_GL_ERROR" is returned."""
230 @pytest.fixture(autouse
=True)
232 """Setup each instance, patching necissary bits."""
233 rv
= textwrap
.dedent("""\
236 OpenGL vendor string: WFLINFO_GL_ERROR
237 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
238 OpenGL version string: WFLINFO_GL_ERROR
239 OpenGL context flags: 0x0\n
240 OpenGL shading language version string: WFLINFO_GL_ERROR
241 OpenGL extensions: WFLINFO_GL_ERROR
244 with mock
.patch
.dict('framework.wflinfo.OPTIONS.env',
245 {'PIGLIT_PLATFORM': 'foo'}), \
247 'framework.wflinfo.subprocess.check_output',
248 mock
.Mock(return_value
=rv
)):
251 @pytest.fixture(scope
='class')
253 return wflinfo
.WflInfo()
255 def test_gl_version(self
, inst
):
256 """wflinfo.WflInfo.gl_version: handles WFLINFO_GL_ERROR
259 assert inst
.core
.api_version
== 0.0
261 def test_glsl_version(self
, inst
):
262 """wflinfo.WflInfo.glsl_version: handles WFLINFO_GL_ERROR
265 assert inst
.core
.shader_version
== 0.0
267 def test_gl_extensions(self
, inst
):
268 """wflinfo.WflInfo.gl_extensions: handles WFLINFO_GL_ERROR
271 assert inst
.core
.extensions
== set()
273 class TestOSError(object):
274 """Tests for the Wflinfo functions to handle OSErrors."""
276 # pylint: disable=pointless-statement
278 @pytest.fixture(autouse
=True, scope
='class')
280 """Setup the class, patching as necessary."""
281 # pylint: disable=bad-continuation
282 with mock
.patch
.dict(
283 'framework.wflinfo.OPTIONS.env',
284 {'PIGLIT_PLATFORM': 'foo'}), \
286 'framework.wflinfo.subprocess.check_output',
287 mock
.Mock(side_effect
=OSError(2, 'foo'))), \
289 'framework.wflinfo.WflInfo._WflInfo__shared_state',
295 return wflinfo
.WflInfo()
297 def test_gl_extensions(self
, inst
):
298 """wflinfo.WflInfo.gl_extensions: Handles OSError "no file"
301 assert inst
.core
.extensions
== set()
303 def test_gl_version(self
, inst
):
304 """wflinfo.WflInfo.get_gl_version: Handles OSError "no file"
307 assert inst
.core
.api_version
== 0.0
309 def test_glsl_version(self
, inst
):
310 """wflinfo.WflInfo.glsl_version: Handles OSError "no file"
313 assert inst
.core
.shader_version
== 0.0
315 class TestCalledProcessError(object):
316 """Tests for the WflInfo functions to handle OSErrors."""
318 # pylint: disable=pointless-statement
320 @pytest.fixture(autouse
=True, scope
='class')
322 """Setup the class, patching as necessary."""
323 # pylint: disable=bad-continuation
324 with mock
.patch
.dict(
325 'framework.wflinfo.OPTIONS.env',
326 {'PIGLIT_PLATFORM': 'foo'}), \
328 # pylint: disable=line-too-long
329 'framework.wflinfo.subprocess.check_output',
330 mock
.Mock(side_effect
=subprocess
.CalledProcessError(1, 'foo'))), \
332 'framework.wflinfo.WflInfo._WflInfo__shared_state',
338 return wflinfo
.WflInfo()
340 def test_gl_extensions(self
, inst
):
341 """wflinfo.WflInfo.gl_extensions: Handles CalledProcessError
344 assert inst
.core
.extensions
== set()
346 def test_gl_version(self
, inst
):
347 """wflinfo.WflInfo.get_gl_version: Handles CalledProcessError
350 assert inst
.core
.api_version
== 0.0
352 def test_glsl_version(self
, inst
):
353 """wflinfo.WflInfo.glsl_version: Handles CalledProcessError
356 assert inst
.core
.shader_version
== 0.0