enqueue-fill-buffer: improve array formatting
[piglit.git] / unittests / framework / test_wflinfo.py
blob9b129c7c078018adfff1868bfe26264130ee14e0
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 """Test the wflinfo module."""
24 import subprocess
25 import textwrap
26 from unittest import mock
28 import pytest
30 from framework import wflinfo
32 # pylint: disable=no-self-use,attribute-defined-outside-init,protected-access
35 def _has_wflinfo():
36 """Return True if wflinfo is available in PATH."""
37 try:
38 subprocess.check_call(['wflinfo', '--help'])
39 except subprocess.CalledProcessError:
40 return False
41 except OSError as e:
42 if e.errno != 2:
43 raise
44 return False
45 return True
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)
56 def patch(self):
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'}), \
63 mock.patch(
64 'framework.wflinfo.WflInfo._WflInfo__shared_state',
65 {}):
66 yield
68 def setup(self):
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
74 extensions.
75 """
76 rv = textwrap.dedent("""\
77 foo
78 bar
79 boink
80 OpenGL version string: 1.1
81 OpenGL shading language: 1.1
82 OpenGL extensions: GL_foobar GL_ham_sandwhich
83 """).encode('utf-8')
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("""\
93 Waffle platform: gbm
94 Waffle api: gl
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
101 """).encode('utf-8')
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("""\
112 Waffle platform: gbm
113 Waffle api: gles3
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
119 """).encode('utf-8')
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("""\
127 Waffle platform: gbm
128 Waffle api: gl
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.
135 """).encode('utf-8')
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("""\
143 Waffle platform: gbm
144 Waffle api: gles2
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.
151 """).encode('utf-8')
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("""\
159 Waffle platform: gbm
160 Waffle api: gl
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
167 """).encode('utf-8')
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("""\
175 Waffle platform: gbm
176 Waffle api: gl
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.
183 """).encode('utf-8')
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
192 Waffle platform: gbm
193 Waffle api: gl
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
200 """).encode('utf-8')
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("""\
208 Waffle platform: gbm
209 Waffle api: gl
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
219 """).encode('utf-8')
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)
228 def patch(self):
229 """Setup each instance, patching necissary bits."""
230 rv = textwrap.dedent("""\
231 Waffle platform: glx
232 Waffle api: gles3
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
239 """).encode('utf-8')
241 with mock.patch.dict('framework.wflinfo.OPTIONS.env',
242 {'PIGLIT_PLATFORM': 'foo'}), \
243 mock.patch(
244 'framework.wflinfo.subprocess.check_output',
245 mock.Mock(return_value=rv)):
246 yield
248 @pytest.fixture(scope='class')
249 def inst(self):
250 return wflinfo.WflInfo()
252 def test_gl_version(self, inst):
253 """wflinfo.WflInfo.gl_version: handles WFLINFO_GL_ERROR
254 correctly.
256 assert inst.core.api_version == 0.0
258 def test_glsl_version(self, inst):
259 """wflinfo.WflInfo.glsl_version: handles WFLINFO_GL_ERROR
260 correctly.
262 assert inst.core.shader_version == 0.0
264 def test_gl_extensions(self, inst):
265 """wflinfo.WflInfo.gl_extensions: handles WFLINFO_GL_ERROR
266 correctly.
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')
276 def patch(self):
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'}), \
282 mock.patch(
283 'framework.wflinfo.subprocess.check_output',
284 mock.Mock(side_effect=OSError(2, 'foo'))), \
285 mock.patch(
286 'framework.wflinfo.WflInfo._WflInfo__shared_state',
287 {}):
288 yield
290 @pytest.fixture
291 def inst(self):
292 return wflinfo.WflInfo()
294 def test_gl_extensions(self, inst):
295 """wflinfo.WflInfo.gl_extensions: Handles OSError "no file"
296 gracefully.
298 assert inst.core.extensions == set()
300 def test_gl_version(self, inst):
301 """wflinfo.WflInfo.get_gl_version: Handles OSError "no file"
302 graceful.
304 assert inst.core.api_version == 0.0
306 def test_glsl_version(self, inst):
307 """wflinfo.WflInfo.glsl_version: Handles OSError "no file"
308 gracefully.
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')
318 def patch(self):
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'}), \
324 mock.patch(
325 # pylint: disable=line-too-long
326 'framework.wflinfo.subprocess.check_output',
327 mock.Mock(side_effect=subprocess.CalledProcessError(1, 'foo'))), \
328 mock.patch(
329 'framework.wflinfo.WflInfo._WflInfo__shared_state',
330 {}):
331 yield
333 @pytest.fixture
334 def inst(self):
335 return wflinfo.WflInfo()
337 def test_gl_extensions(self, inst):
338 """wflinfo.WflInfo.gl_extensions: Handles CalledProcessError
339 gracefully.
341 assert inst.core.extensions == set()
343 def test_gl_version(self, inst):
344 """wflinfo.WflInfo.get_gl_version: Handles CalledProcessError
345 gracefully.
347 assert inst.core.api_version == 0.0
349 def test_glsl_version(self, inst):
350 """wflinfo.WflInfo.glsl_version: Handles CalledProcessError
351 gracefully.
353 assert inst.core.shader_version == 0.0