2 # Copyright (c) 2014, 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 """ Provides tests for the shader_test module """
26 from unittest
import mock
30 from framework
import status
31 from framework
.test
import shader_test
33 # pylint: disable=invalid-name,no-self-use,protected-access
39 self
.__patchers
.append(mock
.patch
.dict(
40 'framework.test.base.OPTIONS.env',
41 {'PIGLIT_PLATFORM': 'foo'}))
44 for patcher
in self
.__patchers
:
47 def teardown(self
, _
):
48 for patcher
in self
.__patchers
:
53 setup_module
= _setup
.setup
54 teardown_module
= _setup
.teardown
57 class TestConfigParsing(object):
58 """Tests for ShaderRunner config parsing."""
60 @pytest.mark
.parametrize('gles,operator,expected', [
61 # pylint: disable=bad-whitespace
62 ('2.0', '>=', 'shader_runner_gles2'),
63 ('2.0', '<=', 'shader_runner_gles2'),
64 ('2.0', '=', 'shader_runner_gles2'),
65 ('2.0', '>', 'shader_runner_gles3'),
66 ('3.0', '>=', 'shader_runner_gles3'),
67 ('3.0', '<=', 'shader_runner_gles2'),
68 ('3.0', '=', 'shader_runner_gles3'),
69 ('3.0', '>', 'shader_runner_gles3'),
70 ('3.0', '<', 'shader_runner_gles2'),
71 ('3.1', '>=', 'shader_runner_gles3'),
72 ('3.1', '<=', 'shader_runner_gles2'),
73 ('3.1', '=', 'shader_runner_gles3'),
74 ('3.1', '>', 'shader_runner_gles3'),
75 ('3.1', '<', 'shader_runner_gles2'),
76 ('3.2', '>=', 'shader_runner_gles3'),
77 ('3.2', '<=', 'shader_runner_gles2'),
78 ('3.2', '=', 'shader_runner_gles3'),
79 ('3.2', '<', 'shader_runner_gles2'),
81 def test_bin(self
, gles
, operator
, expected
, tmpdir
):
82 """Test that the shader_runner parse picks the correct binary."""
83 p
= tmpdir
.join('test.shader_test')
84 p
.write(textwrap
.dedent("""\
90 """.format(operator
, gles
)))
91 test
= shader_test
.ShaderTest
.new(str(p
))
93 assert os
.path
.basename(test
.command
[0]) == expected
95 def test_gles3_bin(self
, tmpdir
):
96 """test.shader_test.ShaderTest: Identifies GLES3 tests successfully."""
97 p
= tmpdir
.join('test.shader_test')
98 p
.write(textwrap
.dedent("""\
103 test
= shader_test
.ShaderTest
.new(str(p
))
105 assert os
.path
.basename(test
.command
[0]) == "shader_runner_gles3"
107 def test_skip_gl_required(self
, tmpdir
):
108 """test.shader_test.ShaderTest: populates gl_requirements properly"""
109 p
= tmpdir
.join('test.shader_test')
110 p
.write(textwrap
.dedent("""\
115 test
= shader_test
.ShaderTest
.new(str(p
))
117 assert test
.require_extensions
== {'GL_ARB_ham_sandwhich'}
119 def test_skip_gl_version(self
, tmpdir
):
120 """test.shader_test.ShaderTest: finds gl_version."""
121 p
= tmpdir
.join('test.shader_test')
122 p
.write(textwrap
.dedent("""\
127 test
= shader_test
.ShaderTest
.new(str(p
))
129 assert test
.require_version
== 2.0
131 def test_skip_gles_version(self
, tmpdir
):
132 """test.shader_test.ShaderTest: finds gles_version."""
133 p
= tmpdir
.join('test.shader_test')
134 p
.write(textwrap
.dedent("""\
139 test
= shader_test
.ShaderTest
.new(str(p
))
141 assert test
.require_version
== 2.0
143 def test_skip_glsl_version(self
, tmpdir
):
144 """test.shader_test.ShaderTest: finds glsl_version."""
145 p
= tmpdir
.join('test.shader_test')
146 p
.write(textwrap
.dedent("""\
151 test
= shader_test
.ShaderTest
.new(str(p
))
153 assert test
.require_shader
== 1.2
155 def test_skip_glsl_es_version(self
, tmpdir
):
156 """test.shader_test.ShaderTest: finds glsl_es_version."""
157 p
= tmpdir
.join('test.shader_test')
158 p
.write(textwrap
.dedent("""\
163 test
= shader_test
.ShaderTest
.new(str(p
))
165 assert test
.require_shader
== 1.0
167 def test_ignore_directives(self
, tmpdir
):
168 """There are some directives for shader_runner that are not interpreted
169 by the python layer, they are only for the C layer. These should be
170 ignored by the python layer.
172 p
= tmpdir
.join('test.shader_test')
173 p
.write(textwrap
.dedent("""\
177 GL_MAX_VERTEX_OUTPUT_COMPONENTS
178 GL_MAX_FRAGMENT_UNIFORM_COMPONENTS
179 GL_MAX_VERTEX_UNIFORM_COMPONENTS
180 GL_MAX_VARYING_COMPONENTS
183 test
= shader_test
.ShaderTest
.new(str(p
))
185 assert test
.require_version
== 3.3
186 assert test
.require_shader
== 1.50
187 assert test
.require_extensions
== {'GL_ARB_foobar'}
190 class TestCommand(object):
191 """Tests for the command property."""
193 @pytest.fixture(scope
='class')
194 def test_file(self
, tmpdir_factory
):
195 p
= tmpdir_factory
.mktemp('shader-test-command').join('test.shader_test')
196 p
.write(textwrap
.dedent("""\
203 def test_getter_adds_auto_and_fbo(self
, test_file
):
204 """test.shader_test.ShaderTest: -auto and -fbo is added to the command.
206 test
= shader_test
.ShaderTest
.new(test_file
)
207 assert '-auto' in test
.command
208 assert '-fbo' in test
.command
210 def test_setter_doesnt_add_auto_and_fbo(self
, test_file
):
211 """Don't add -fbo or -auto to self._command when using the setter."""
212 test
= shader_test
.ShaderTest
.new(test_file
)
213 test
.command
+= ['-newarg']
214 assert '-auto' not in test
._command
215 assert '-fbo' not in test
._command
218 class TestMultiShaderTest(object):
219 """Tests for the MultiShaderTest class."""
221 class TestConstructor(object):
222 """Tests for the constructor object."""
225 def inst(self
, tmpdir
):
226 """A fixture that creates an instance to test."""
227 one
= tmpdir
.join('foo.shader_test')
228 one
.write(textwrap
.dedent("""\
233 two
= tmpdir
.join('bar.shader_test')
234 two
.write(textwrap
.dedent("""\
240 return shader_test
.MultiShaderTest
.new(
241 [str(one
), str(two
)])
243 def test_prog(self
, inst
):
244 assert os
.path
.basename(inst
.command
[0]) == 'shader_runner'
246 def test_filenames(self
, inst
):
247 assert os
.path
.basename(inst
.command
[1]) == 'foo.shader_test'
248 assert os
.path
.basename(inst
.command
[2]) == 'bar.shader_test'
250 def test_extra(self
, inst
):
251 assert inst
.command
[3] == '-auto'
254 def inst(self
, tmpdir
):
255 """A fixture that creates an instance to test."""
256 one
= tmpdir
.join('foo.shader_test')
257 one
.write(textwrap
.dedent("""\
262 two
= tmpdir
.join('bar.shader_test')
263 two
.write(textwrap
.dedent("""\
270 return shader_test
.MultiShaderTest
.new(
271 [str(one
), str(two
)])
273 def test_resume(self
, inst
):
274 actual
= inst
._resume
(1) # pylint: disable=protected-access
275 assert os
.path
.basename(actual
[0]) == 'shader_runner'
276 assert os
.path
.basename(actual
[1]) == 'bar.shader_test'
277 assert os
.path
.basename(actual
[2]) == '-auto'
279 def test_skips_set(self
, inst
):
280 assert inst
.skips
[0].shader_version
== 3.0
281 assert inst
.skips
[1].shader_version
== 4.0
282 assert inst
.skips
[1].extensions
== {'GL_ARB_ham_sandwhich'}
284 def test_process_skips(self
, inst
):
285 expected
= {'bar': status
.SKIP
, 'foo': status
.NOTRUN
}
286 with mock
.patch
.object(inst
.skips
[0].info
.core
, 'shader_version', 3.0):
287 inst
._process
_skips
()
288 assert dict(inst
.result
.subtests
) == expected