ovr_multiview: add some basic glsl tests
[piglit.git] / unittests / generators / test_glsl.py
blob4ec1f1f08e1d6423afc1109c31773ecda793d1b9
1 # encoding=utf-8
2 # Copyright © 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 """Tests for generated_tests/modules/glsl.py."""
24 import itertools
25 import operator
27 import pytest
29 # pylint can't figure out the sys.path manipulation.
30 from generated_tests.modules import glsl # pylint: disable=import-error
32 # pylint: disable=no-self-use,invalid-name
34 _GLSL = [
35 '110',
36 '120',
37 '130',
38 '140',
39 '150',
40 '330',
41 '400',
42 '410',
43 '420',
44 '430',
45 '440',
46 '450',
49 _GLSLES = [
50 '100',
51 '300 es',
52 '310 es',
53 '320 es',
56 _OPERATORS = [
57 operator.lt,
58 operator.le,
59 operator.eq,
60 operator.ne,
61 operator.ge,
62 operator.gt,
66 def test_factory_glsl():
67 """generated_tests.modules.glsl.Version: provides a GLSLVersion."""
68 test = glsl.Version('110')
69 assert isinstance(test, glsl.GLSLVersion)
72 def test_factory_glsles():
73 """generated_tests.modules.glsl.Version: provides a GLSLESVersion."""
74 test = glsl.Version('100')
75 assert isinstance(test, glsl.GLSLESVersion)
78 def test_factory_cache():
79 """generated_tests.modules.glsl.Version: caches objects."""
80 test1 = glsl.Version('100')
81 test2 = glsl.Version('100')
82 assert test1 is test2
85 @pytest.mark.parametrize("op,first,second",
86 itertools.product(_OPERATORS, _GLSL, _GLSL))
87 def test_compare_glsl_to_glsl(op, first, second):
88 """Test GLSLVersion <cmp> GLSLVersion."""
89 actual = op(glsl.Version(first), glsl.Version(second))
90 assert actual == op(int(first), int(second))
93 @pytest.mark.parametrize("op,first,second",
94 itertools.product(_OPERATORS, _GLSLES, _GLSLES))
95 def test_compare_glsles_to_glsles(op, first, second):
96 """Test GLSLESVersion <cmp> GLSLESVersion."""
97 actual = op(glsl.Version(first), glsl.Version(second))
98 assert actual == op(int(first[:3]), int(second[:3]))
101 @pytest.mark.raises(exception=TypeError)
102 def test_glsl_glsles_exception():
103 """generated_tests.modules.glsl: GLSLVersion <cmp> GLSLESVersion."""
104 return glsl.Version('110') < glsl.Version('100')
107 @pytest.mark.raises(exception=TypeError)
108 def test_glsles_glsl_exception():
109 """generated_tests.modules.glsl: GLSLESVersion <cmp> GLSLVersion."""
110 return glsl.Version('100') < glsl.Version('110')
113 @pytest.mark.parametrize("op,first,second",
114 itertools.product(_OPERATORS, _GLSL, _GLSL))
115 def test_compare_glsl_to_int(op, first, second):
116 """Test GLSLVersion <cmp> GLSLVersion."""
117 actual = op(glsl.Version(first), int(second))
118 assert actual == op(int(first), int(second))
121 @pytest.mark.parametrize("op,first,second",
122 itertools.product(_OPERATORS, _GLSLES, _GLSLES))
123 def test_compare_glsles_to_int(op, first, second):
124 """Test GLSLESVersion <cmp> GLSLESVersion."""
125 actual = op(glsl.Version(first), int(second[:3]))
126 assert actual == op(int(first[:3]), int(second[:3]))
129 @pytest.mark.parametrize("op,first,second",
130 itertools.product(_OPERATORS, _GLSL, _GLSL))
131 def test_compare_glsl_to_float(op, first, second):
132 """Test GLSLVersion <cmp> GLSLVersion."""
133 actual = op(glsl.Version(first), float(second) / 100)
134 expected = op(float(first), float(second))
135 assert actual == expected
138 @pytest.mark.parametrize("op,first,second",
139 itertools.product(_OPERATORS, _GLSLES, _GLSLES))
140 def test_compare_glsles_to_float(op, first, second):
141 """Test GLSLESVersion <cmp> GLSLESVersion."""
142 actual = op(glsl.Version(first), float(second[:3]) / 100)
143 assert actual == op(float(first[:3]), float(second[:3]))
148 def test_GLSLVersion_str():
149 """generated_tests.modules.glsl.GLSLVersion: str()"""
150 assert str(glsl.Version('110')) == '110'
153 def test_GLSLESVersion_str():
154 """generated_tests.modules.glsl.GLSLESVersion: str()"""
155 assert str(glsl.Version('100')) == '100'
158 def test_GLSLVersion_int():
159 """generated_tests.modules.glsl.GLSLVersion: int()"""
160 assert int(glsl.Version('110')) == 110
163 def test_GLSLESVersion_int():
164 """generated_tests.modules.glsl.GLSLESVersion: int()"""
165 assert int(glsl.Version('100')) == 100
168 def test_GLSLVersion_float():
169 """generated_tests.modules.glsl.GLSLVersion: float()"""
170 assert float(glsl.Version('110')) == 1.10
173 def test_GLSLESVersion_float():
174 """generated_tests.modules.glsl.GLSLESVersion: float()"""
175 assert float(glsl.Version('100')) == 1.00
178 def test_GLSLVersion_print_float():
179 """generated_tests.modules.glsl.GLSLVersion: print_float()"""
180 assert glsl.Version('110').print_float() == '1.10'
183 def test_GLSLESVersion_print_float():
184 """generated_tests.modules.glsl.GLSLESVersion: print_float()"""
185 assert glsl.Version('100').print_float() == '1.00'
188 def test_GLSLESVersion_print_float_es():
189 """generated_tests.modules.glsl.GLSLESVersion: print_float() (es version)"""
190 assert glsl.Version('300 es').print_float() == '3.00 es'
193 class TestMinVersion_for_stage(object):
194 """Tests for generated_tests.modules.glsl.MinVersion.for_stage.
196 Each test covers the requested < required and requested == required. If
197 it's possible it also covers requested > required.
200 def _test(self, stage, version, expected):
201 assert glsl.MinVersion.for_stage(stage, version) == expected
203 def test_opengl_frag(self):
204 """generated_tests.modules.glsl.MinVersion.for_stage: FS (OpenGL)"""
205 self._test('frag', glsl.Version('150'), glsl.Version('150'))
206 self._test('frag', glsl.Version('110'), glsl.Version('110'))
208 def test_opengl_vert(self):
209 """generated_tests.modules.glsl.MinVersion.for_stage: VS (OpenGL)"""
210 self._test('vert', glsl.Version('150'), glsl.Version('150'))
211 self._test('vert', glsl.Version('110'), glsl.Version('110'))
213 def test_opengl_geom(self):
214 """generated_tests.modules.glsl.MinVersion.for_stage: GS (OpenGL)"""
215 self._test('geom', glsl.Version('330'), glsl.Version('330'))
216 self._test('geom', glsl.Version('110'), glsl.Version('150'))
217 self._test('geom', glsl.Version('150'), glsl.Version('150'))
219 def test_opengl_tesc(self):
220 """generated_tests.modules.glsl.MinVersion.for_stage: TCS (OpenGL)"""
221 self._test('tesc', glsl.Version('410'), glsl.Version('410'))
222 self._test('tesc', glsl.Version('400'), glsl.Version('400'))
223 self._test('tesc', glsl.Version('140'), glsl.Version('400'))
225 def test_opengl_tese(self):
226 """generated_tests.modules.glsl.MinVersion.for_stage: TES (OpenGL)"""
227 self._test('tese', glsl.Version('410'), glsl.Version('410'))
228 self._test('tese', glsl.Version('400'), glsl.Version('400'))
229 self._test('tese', glsl.Version('140'), glsl.Version('400'))
231 def test_opengl_comp(self):
232 """generated_tests.modules.glsl.MinVersion.for_stage: CS (OpenGL)"""
233 self._test('comp', glsl.Version('440'), glsl.Version('440'))
234 self._test('comp', glsl.Version('430'), glsl.Version('430'))
235 self._test('comp', glsl.Version('140'), glsl.Version('430'))
237 def test_opengles_frag(self):
238 """generated_tests.modules.glsl.MinVersion.for_stage: FS (OpenGL ES)"""
239 self._test('frag', glsl.Version('300 es'), glsl.Version('300 es'))
240 self._test('frag', glsl.Version('100'), glsl.Version('100'))
242 def test_opengles_vert(self):
243 """generated_tests.modules.glsl.MinVersion.for_stage: VS (OpenGL ES)"""
244 self._test('vert', glsl.Version('320 es'), glsl.Version('320 es'))
245 self._test('vert', glsl.Version('100'), glsl.Version('100'))
247 def test_opengles_geom(self):
248 """generated_tests.modules.glsl.MinVersion.for_stage: GS (OpenGL ES)"""
249 self._test('geom', glsl.Version('100'), glsl.Version('320 es'))
250 self._test('geom', glsl.Version('320 es'), glsl.Version('320 es'))
252 def test_opengles_tesc(self):
253 """generated_tests.modules.glsl.MinVersion.for_stage: TCS (OpenGL ES)"""
254 self._test('tesc', glsl.Version('320 es'), glsl.Version('320 es'))
255 self._test('tesc', glsl.Version('100'), glsl.Version('320 es'))
257 def test_opengles_tese(self):
258 """generated_tests.modules.glsl.MinVersion.for_stage: TES (OpenGL ES)"""
259 self._test('tese', glsl.Version('320 es'), glsl.Version('320 es'))
260 self._test('tese', glsl.Version('100'), glsl.Version('320 es'))
262 def test_opengles_comp(self):
263 """generated_tests.modules.glsl.MinVersion.for_stage: TES (OpenGL ES)"""
264 self._test('comp', glsl.Version('320 es'), glsl.Version('320 es'))
265 self._test('comp', glsl.Version('100'), glsl.Version('310 es'))
266 self._test('comp', glsl.Version('310 es'), glsl.Version('310 es'))
269 class TestMinVersion_for_stage_with_ext(object):
270 """Tests for generated_tests.modules.glsl.MinVersion.for_stage_with_ext."""
271 def _test(self, stage, version, expected):
272 ver, ext = glsl.MinVersion.for_stage_with_ext(stage, version)
273 assert (ver, ext) == expected
275 def test_opengl_frag(self):
276 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
277 FS (OpenGL)"""
278 self._test('frag', glsl.Version('150'), (glsl.Version('150'), None))
279 self._test('frag', glsl.Version('110'), (glsl.Version('110'), None))
281 def test_opengl_vert(self):
282 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
283 VS (OpenGL)"""
284 self._test('vert', glsl.Version('150'), (glsl.Version('150'), None))
285 self._test('vert', glsl.Version('110'), (glsl.Version('110'), None))
287 def test_opengl_geom(self):
288 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
289 GS (OpenGL)"""
290 self._test('geom', glsl.Version('330'), (glsl.Version('330'), None))
291 self._test('geom', glsl.Version('110'), (glsl.Version('150'), None))
292 self._test('geom', glsl.Version('150'), (glsl.Version('150'), None))
294 def test_opengl_tesc(self):
295 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
296 TCS (OpenGL)"""
297 self._test('tesc', glsl.Version('410'), (glsl.Version('410'), None))
298 self._test('tesc', glsl.Version('140'),
299 (glsl.Version('140'), 'GL_ARB_tessellation_shader'))
300 self._test('tesc', glsl.Version('110'),
301 (glsl.Version('140'), 'GL_ARB_tessellation_shader'))
303 def test_opengl_tese(self):
304 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
305 TES (OpenGL)"""
306 self._test('tese', glsl.Version('410'), (glsl.Version('410'), None))
307 self._test('tese', glsl.Version('140'),
308 (glsl.Version('140'), 'GL_ARB_tessellation_shader'))
309 self._test('tese', glsl.Version('110'),
310 (glsl.Version('140'), 'GL_ARB_tessellation_shader'))
312 def test_opengl_comp(self):
313 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
314 CS (OpenGL)"""
315 self._test('comp', glsl.Version('430'), (glsl.Version('430'), None))
316 self._test('comp', glsl.Version('140'),
317 (glsl.Version('140'), 'GL_ARB_compute_shader'))
318 self._test('comp', glsl.Version('110'),
319 (glsl.Version('140'), 'GL_ARB_compute_shader'))
321 def test_opengles_frag(self):
322 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
323 FS (OpenGL ES)"""
324 self._test('frag', glsl.Version('300 es'),
325 (glsl.Version('300 es'), None))
326 self._test('frag', glsl.Version('100'), (glsl.Version('100'), None))
328 def test_opengles_vert(self):
329 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
330 VS (OpenGL ES)"""
331 self._test('vert', glsl.Version('300 es'),
332 (glsl.Version('300 es'), None))
333 self._test('vert', glsl.Version('100'), (glsl.Version('100'), None))
335 def test_opengles_geom(self):
336 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
337 GS (OpenGL ES)"""
338 self._test('geom', glsl.Version('100'),
339 (glsl.Version('310 es'), 'GL_OES_geometry_shader'))
340 self._test('geom', glsl.Version('310 es'),
341 (glsl.Version('310 es'), 'GL_OES_geometry_shader'))
342 self._test('geom', glsl.Version('320 es'),
343 (glsl.Version('320 es'), None))
345 def test_opengles_tesc(self):
346 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
347 TCS (OpenGL ES)"""
348 self._test('tesc', glsl.Version('320 es'),
349 (glsl.Version('320 es'), None))
350 self._test('tesc', glsl.Version('310 es'),
351 (glsl.Version('310 es'), 'GL_OES_tessellation_shader'))
352 self._test('tesc', glsl.Version('100'),
353 (glsl.Version('310 es'), 'GL_OES_tessellation_shader'))
355 def test_opengles_tese(self):
356 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
357 TES (OpenGL ES)"""
358 self._test('tese', glsl.Version('320 es'),
359 (glsl.Version('320 es'), None))
360 self._test('tese', glsl.Version('310 es'),
361 (glsl.Version('310 es'), 'GL_OES_tessellation_shader'))
362 self._test('tese', glsl.Version('100'),
363 (glsl.Version('310 es'), 'GL_OES_tessellation_shader'))
365 def test_opengles_comp(self):
366 """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
367 TES (OpenGL ES)"""
368 self._test('comp', glsl.Version('320 es'),
369 (glsl.Version('320 es'), None))
370 self._test('comp', glsl.Version('100'), (glsl.Version('310 es'), None))
371 self._test('comp', glsl.Version('310 es'),
372 (glsl.Version('310 es'), None))