1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
# Copyright (c) 2014, 2016 Intel Corporation
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
""" Provides tests for the shader_test module """
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
import os
import textwrap
try:
import mock
except ImportError:
from unittest import mock
import pytest
import six
from framework.test import shader_test
# pylint: disable=invalid-name,no-self-use,protected-access
class _Setup(object):
def __init__(self):
self.__patchers = []
self.__patchers.append(mock.patch.dict(
'framework.test.base.OPTIONS.env',
{'PIGLIT_PLATFORM': 'foo'}))
def setup(self, _):
for patcher in self.__patchers:
patcher.start()
def teardown(self, _):
for patcher in self.__patchers:
patcher.stop()
_setup = _Setup()
setup_module = _setup.setup
teardown_module = _setup.teardown
class TestConfigParsing(object):
"""Tests for ShaderRunner config parsing."""
@pytest.mark.parametrize('gles,operator,expected', [
# pylint: disable=bad-whitespace
('2.0', '>=', 'shader_runner_gles2'),
('2.0', '<=', 'shader_runner_gles2'),
('2.0', '=', 'shader_runner_gles2'),
('2.0', '>', 'shader_runner_gles3'),
('3.0', '>=', 'shader_runner_gles3'),
('3.0', '<=', 'shader_runner_gles2'),
('3.0', '=', 'shader_runner_gles3'),
('3.0', '>', 'shader_runner_gles3'),
('3.0', '<', 'shader_runner_gles2'),
('3.1', '>=', 'shader_runner_gles3'),
('3.1', '<=', 'shader_runner_gles2'),
('3.1', '=', 'shader_runner_gles3'),
('3.1', '>', 'shader_runner_gles3'),
('3.1', '<', 'shader_runner_gles2'),
('3.2', '>=', 'shader_runner_gles3'),
('3.2', '<=', 'shader_runner_gles2'),
('3.2', '=', 'shader_runner_gles3'),
('3.2', '<', 'shader_runner_gles2'),
])
def test_bin(self, gles, operator, expected, tmpdir):
"""Test that the shader_runner parse picks the correct binary."""
p = tmpdir.join('test.shader_test')
p.write(textwrap.dedent("""\
[require]
GL ES {} {}
GLSL ES >= 1.00
[next section]
""".format(operator, gles)))
test = shader_test.ShaderTest(six.text_type(p))
assert os.path.basename(test.command[0]) == expected
def test_gles3_bin(self, tmpdir):
"""test.shader_test.ShaderTest: Identifies GLES3 tests successfully."""
p = tmpdir.join('test.shader_test')
p.write(textwrap.dedent("""\
[require]
GL ES >= 3.0
GLSL ES >= 3.00 es
"""))
test = shader_test.ShaderTest(six.text_type(p))
assert os.path.basename(test.command[0]) == "shader_runner_gles3"
def test_skip_gl_required(self, tmpdir):
"""test.shader_test.ShaderTest: populates gl_requirements properly"""
p = tmpdir.join('test.shader_test')
p.write(textwrap.dedent("""\
[require]
GL >= 3.0
GL_ARB_ham_sandwhich
"""))
test = shader_test.ShaderTest(six.text_type(p))
assert test.gl_required == {'GL_ARB_ham_sandwhich'}
def test_skip_gl_version(self, tmpdir):
"""test.shader_test.ShaderTest: finds gl_version."""
p = tmpdir.join('test.shader_test')
p.write(textwrap.dedent("""\
[require]
GL >= 2.0
GL_ARB_ham_sandwhich
"""))
test = shader_test.ShaderTest(six.text_type(p))
assert test.gl_version == 2.0
def test_skip_gles_version(self, tmpdir):
"""test.shader_test.ShaderTest: finds gles_version."""
p = tmpdir.join('test.shader_test')
p.write(textwrap.dedent("""\
[require]
GL ES >= 2.0
GL_ARB_ham_sandwhich
"""))
test = shader_test.ShaderTest(six.text_type(p))
assert test.gles_version == 2.0
def test_skip_glsl_version(self, tmpdir):
"""test.shader_test.ShaderTest: finds glsl_version."""
p = tmpdir.join('test.shader_test')
p.write(textwrap.dedent("""\
[require]
GL >= 2.1
GLSL >= 1.20
"""))
test = shader_test.ShaderTest(six.text_type(p))
assert test.glsl_version == 1.2
def test_skip_glsl_es_version(self, tmpdir):
"""test.shader_test.ShaderTest: finds glsl_es_version."""
p = tmpdir.join('test.shader_test')
p.write(textwrap.dedent("""\
[require]
GL ES >= 2.0
GLSL ES >= 1.00
"""))
test = shader_test.ShaderTest(six.text_type(p))
assert test.glsl_es_version == 1.0
def test_ignore_directives(self, tmpdir):
"""There are some directives for shader_runner that are not interpreted
by the python layer, they are only for the C layer. These should be
ignored by the python layer.
"""
p = tmpdir.join('test.shader_test')
p.write(textwrap.dedent("""\
[require]
GL >= 3.3
GLSL >= 1.50
GL_MAX_VERTEX_OUTPUT_COMPONENTS
GL_MAX_FRAGMENT_UNIFORM_COMPONENTS
GL_MAX_VERTEX_UNIFORM_COMPONENTS
GL_MAX_VARYING_COMPONENTS
GL_ARB_foobar
"""))
test = shader_test.ShaderTest(six.text_type(p))
assert test.gl_version == 3.3
assert test.glsl_version == 1.50
assert test.gl_required == {'GL_ARB_foobar'}
class TestCommand(object):
"""Tests for the command property."""
@pytest.fixture(scope='class')
def test_file(self, tmpdir_factory):
p = tmpdir_factory.mktemp('shader-test-command').join('test.shader_test')
p.write(textwrap.dedent("""\
[require]
GL ES >= 3.0
GLSL ES >= 3.00 es
"""))
return six.text_type(p)
def test_getter_adds_auto_and_fbo(self, test_file):
"""test.shader_test.ShaderTest: -auto and -fbo is added to the command.
"""
test = shader_test.ShaderTest(test_file)
assert '-auto' in test.command
assert '-fbo' in test.command
def test_setter_doesnt_add_auto_and_fbo(self, test_file):
"""Don't add -fbo or -auto to self._command when using the setter."""
test = shader_test.ShaderTest(test_file)
test.command += ['-newarg']
assert '-auto' not in test._command
assert '-fbo' not in test._command
class TestMultiShaderTest(object):
"""Tests for the MultiShaderTest class."""
class TestConstructor(object):
"""Tests for the constructor object."""
@pytest.fixture
def inst(self, tmpdir):
"""A fixture that creates an instance to test."""
one = tmpdir.join('foo.shader_test')
one.write(textwrap.dedent("""\
[require]
GLSL >= 3.0
[vertex shader]"""))
two = tmpdir.join('bar.shader_test')
two.write(textwrap.dedent("""\
[require]
GLSL >= 4.0
[vertex shader]"""))
return shader_test.MultiShaderTest(
[six.text_type(one), six.text_type(two)])
def test_prog(self, inst):
assert os.path.basename(inst.command[0]) == 'shader_runner'
def test_filenames(self, inst):
assert os.path.basename(inst.command[1]) == 'foo.shader_test'
assert os.path.basename(inst.command[2]) == 'bar.shader_test'
def test_extra(self, inst):
assert inst.command[3] == '-auto'
@pytest.fixture
def inst(self, tmpdir):
"""A fixture that creates an instance to test."""
one = tmpdir.join('foo.shader_test')
one.write(textwrap.dedent("""\
[require]
GLSL >= 3.0
[vertex shader]"""))
two = tmpdir.join('bar.shader_test')
two.write(textwrap.dedent("""\
[require]
GLSL >= 4.0
[vertex shader]"""))
return shader_test.MultiShaderTest(
[six.text_type(one), six.text_type(two)])
def test_resume(self, inst):
actual = inst._resume(1) # pylint: disable=protected-access
assert os.path.basename(actual[0]) == 'shader_runner'
assert os.path.basename(actual[1]) == 'bar.shader_test'
assert os.path.basename(actual[2]) == '-auto'
|