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."""
26 from unittest
import mock
30 from framework
import wflinfo
32 # pylint: disable=no-self-use,attribute-defined-outside-init,protected-access
36 """Return True if wflinfo is available in PATH."""
38 subprocess
.check_call(['wflinfo', '--help'])
39 except subprocess
.CalledProcessError
:
48 @pytest.mark
.skipif(not _has_wflinfo(), reason
="Tests require wflinfo binary.")
49 class TestWflInfo(object):
50 """Tests for the WflInfo class."""
52 class TestAttributes(object):
53 """test for attribute assignments."""
55 @pytest.fixture(autouse
=True)
57 """Mock a few things for testing purposes."""
58 # This is pretty ugly, but as a Borb with a private shared state,
59 # the only way to test this module is to actually replace the
60 # shared_state with a mock value so it's reset after each test
61 with mock
.patch
.dict('framework.wflinfo.OPTIONS.env',
62 {'PIGLIT_PLATFORM': 'foo'}), \
64 'framework.wflinfo.WflInfo._WflInfo__shared_state',
69 """Setup each instance, patching necissary bits."""
70 self
._test
= wflinfo
.WflInfo()
72 def test_extension(self
):
73 """wflinfo.WflInfo.<api>.extensions: Provides list of gl
76 rv
= textwrap
.dedent("""\
80 OpenGL version string: 1.1
81 OpenGL shading language: 1.1
82 OpenGL extensions: GL_foobar GL_ham_sandwhich
84 expected
= set(['GL_foobar', 'GL_ham_sandwhich'])
86 with mock
.patch('framework.wflinfo.subprocess.check_output',
87 mock
.Mock(return_value
=rv
)):
88 assert self
._test
.compat
.extensions
== expected
90 def test_api_version(self
):
91 """wflinfo.WflInfo.<api>.api_version: Provides a version number."""
92 rv
= textwrap
.dedent("""\
95 OpenGL vendor string: Intel Open Source Technology Center
96 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
97 OpenGL context flags: 0x0
98 OpenGL shading language: 1.1
99 OpenGL extensions: GL_foobar GL_ham_sandwhich
100 OpenGL version string: 18 (Compat Profile) Mesa 11.0.4
102 with mock
.patch('framework.wflinfo.subprocess.check_output',
103 mock
.Mock(return_value
=rv
)):
104 assert self
._test
.compat
.api_version
== 18.0
106 def test_api_version_gles(self
):
107 """wflinfo.WflInfo.<es>.api_version: Provides a version number.
109 The format for GLES is different than for Desktop GL.
111 rv
= textwrap
.dedent("""\
114 OpenGL vendor string: Intel Open Source Technology Center
115 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
116 OpenGL version string: OpenGL ES 7.1 Mesa 11.0.4
117 OpenGL shading language: 1.1
118 OpenGL extensions: GL_foobar GL_ham_sandwhich
120 with mock
.patch('framework.wflinfo.subprocess.check_output',
121 mock
.Mock(return_value
=rv
)):
122 assert self
._test
.es2
.api_version
== 7.1
124 def test_glsl_version(self
):
125 """wflinfo.WflInfo.<api>.shader_version: Provides a version number."""
126 rv
= textwrap
.dedent("""\
129 OpenGL vendor string: Intel Open Source Technology Center
130 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
131 OpenGL version string: 1.1 (Core Profile) Mesa 11.0.4
132 OpenGL context flags: 0x0
133 OpenGL shading language version string: 9.30
134 OpenGL extensions: this is some extension strings.
136 with mock
.patch('framework.wflinfo.subprocess.check_output',
137 mock
.Mock(return_value
=rv
)):
138 assert self
._test
.core
.shader_version
== 9.3
140 def test_glsl_es_version(self
):
141 """wflinfo.WflInfo.<es>.shader_version: works with gles2."""
142 rv
= textwrap
.dedent("""\
145 Wflinfo vendor string: Intel Open Source Technology Center
146 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
147 OpenGL version string: OpenGL ES 3.0 Mesa 11.0.4
148 OpenGL shading language version string: OpenGL ES GLSL ES 1.0.17
149 OpenGL version string: 1.1 (Core Profile) Mesa 11.0.4
150 OpenGL extensions: this is some extension strings.
152 with mock
.patch('framework.wflinfo.subprocess.check_output',
153 mock
.Mock(return_value
=rv
)):
154 assert self
._test
.es2
.shader_version
== 1.0
156 def test_gl_version_patch(self
):
157 """wflinfo.WflInfo.*.api_version: Works with patch versions."""
158 rv
= textwrap
.dedent("""\
161 OpenGL vendor string: Intel Open Source Technology Center
162 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
163 OpenGL version string: 18.0.1 (Core Profile) Mesa 11.0.4
164 OpenGL shading language version string: OpenGL ES GLSL ES 5.00
165 OpenGL extensions: this is some extension strings.
166 OpenGL context flags: 0x0
168 with mock
.patch('framework.wflinfo.subprocess.check_output',
169 mock
.Mock(return_value
=rv
)):
170 assert self
._test
.core
.api_version
== 18.0
172 def test_glsl_version_patch(self
):
173 """wflinfo.WflInfo.*.shader_version: Works with patch versions."""
174 rv
= textwrap
.dedent("""\
177 OpenGL vendor string: Intel Open Source Technology Center
178 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
179 OpenGL version string: 1.1 (Core Profile) Mesa 11.0.4
180 OpenGL context flags: 0x0
181 OpenGL shading language version string: 9.30.7
182 OpenGL extensions: this is some extension strings.
184 with mock
.patch('framework.wflinfo.subprocess.check_output',
185 mock
.Mock(return_value
=rv
)):
186 assert self
._test
.core
.shader_version
== 9.3
188 def test_leading_junk(self
):
189 """wflinfo.WflInfo.*.api_version: Handles leading junk."""
190 rv
= textwrap
.dedent("""\
191 Warning: I'm a big fat warnngs
194 OpenGL vendor string: Intel Open Source Technology Center
195 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
196 OpenGL version string: 18.0.1 (Core Profile) Mesa 11.0.4
197 OpenGL context flags: 0x0
198 OpenGL shading language version string: 9.30.7
199 OpenGL extensions: ARB_ham_sandwich
201 with mock
.patch('framework.wflinfo.subprocess.check_output',
202 mock
.Mock(return_value
=rv
)):
203 assert self
._test
.core
.api_version
== 18.0
205 def test_mixed_junk(self
):
206 """wflinfo.WflInfo.*.api_version: Handles mixed junk."""
207 rv
= textwrap
.dedent("""\
210 Warning: I'm a big fat warnngs
211 OpenGL vendor string: Intel Open Source Technology Center
212 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
213 Warning: I'm a big fat warnngs
214 Warning: I'm a big fat warnngs
215 OpenGL version string: 18.0.1 (Core Profile) Mesa 11.0.4
216 OpenGL context flags: 0x0
217 OpenGL shading language version string: 9.30.7
218 OpenGL extensions: ARB_ham_sandwich
220 with mock
.patch('framework.wflinfo.subprocess.check_output',
221 mock
.Mock(return_value
=rv
)):
222 assert self
._test
.core
.api_version
== 18.0
224 class TestWAFFLEINFO_GL_ERROR(object):
225 """Test class for WflInfo when "WFLINFO_GL_ERROR" is returned."""
227 @pytest.fixture(autouse
=True)
229 """Setup each instance, patching necissary bits."""
230 rv
= textwrap
.dedent("""\
233 OpenGL vendor string: WFLINFO_GL_ERROR
234 OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
235 OpenGL version string: WFLINFO_GL_ERROR
236 OpenGL context flags: 0x0\n
237 OpenGL shading language version string: WFLINFO_GL_ERROR
238 OpenGL extensions: WFLINFO_GL_ERROR
241 with mock
.patch
.dict('framework.wflinfo.OPTIONS.env',
242 {'PIGLIT_PLATFORM': 'foo'}), \
244 'framework.wflinfo.subprocess.check_output',
245 mock
.Mock(return_value
=rv
)):
248 @pytest.fixture(scope
='class')
250 return wflinfo
.WflInfo()
252 def test_gl_version(self
, inst
):
253 """wflinfo.WflInfo.gl_version: handles WFLINFO_GL_ERROR
256 assert inst
.core
.api_version
== 0.0
258 def test_glsl_version(self
, inst
):
259 """wflinfo.WflInfo.glsl_version: handles WFLINFO_GL_ERROR
262 assert inst
.core
.shader_version
== 0.0
264 def test_gl_extensions(self
, inst
):
265 """wflinfo.WflInfo.gl_extensions: handles WFLINFO_GL_ERROR
268 assert inst
.core
.extensions
== set()
270 class TestOSError(object):
271 """Tests for the Wflinfo functions to handle OSErrors."""
273 # pylint: disable=pointless-statement
275 @pytest.fixture(autouse
=True, scope
='class')
277 """Setup the class, patching as necessary."""
278 # pylint: disable=bad-continuation
279 with mock
.patch
.dict(
280 'framework.wflinfo.OPTIONS.env',
281 {'PIGLIT_PLATFORM': 'foo'}), \
283 'framework.wflinfo.subprocess.check_output',
284 mock
.Mock(side_effect
=OSError(2, 'foo'))), \
286 'framework.wflinfo.WflInfo._WflInfo__shared_state',
292 return wflinfo
.WflInfo()
294 def test_gl_extensions(self
, inst
):
295 """wflinfo.WflInfo.gl_extensions: Handles OSError "no file"
298 assert inst
.core
.extensions
== set()
300 def test_gl_version(self
, inst
):
301 """wflinfo.WflInfo.get_gl_version: Handles OSError "no file"
304 assert inst
.core
.api_version
== 0.0
306 def test_glsl_version(self
, inst
):
307 """wflinfo.WflInfo.glsl_version: Handles OSError "no file"
310 assert inst
.core
.shader_version
== 0.0
312 class TestCalledProcessError(object):
313 """Tests for the WflInfo functions to handle OSErrors."""
315 # pylint: disable=pointless-statement
317 @pytest.fixture(autouse
=True, scope
='class')
319 """Setup the class, patching as necessary."""
320 # pylint: disable=bad-continuation
321 with mock
.patch
.dict(
322 'framework.wflinfo.OPTIONS.env',
323 {'PIGLIT_PLATFORM': 'foo'}), \
325 # pylint: disable=line-too-long
326 'framework.wflinfo.subprocess.check_output',
327 mock
.Mock(side_effect
=subprocess
.CalledProcessError(1, 'foo'))), \
329 'framework.wflinfo.WflInfo._WflInfo__shared_state',
335 return wflinfo
.WflInfo()
337 def test_gl_extensions(self
, inst
):
338 """wflinfo.WflInfo.gl_extensions: Handles CalledProcessError
341 assert inst
.core
.extensions
== set()
343 def test_gl_version(self
, inst
):
344 """wflinfo.WflInfo.get_gl_version: Handles CalledProcessError
347 assert inst
.core
.api_version
== 0.0
349 def test_glsl_version(self
, inst
):
350 """wflinfo.WflInfo.glsl_version: Handles CalledProcessError
353 assert inst
.core
.shader_version
== 0.0