arb_framebuffer_object: add missing MSAA alpha-to-coverage and alpha-to-one tests
[piglit.git] / unittests / framework / test / test_opengl.py
blob93254902a11699fd9d26ea7f749db50fac5a9184
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 opengl module."""
24 from unittest import mock
26 import pytest
28 from framework import wflinfo
29 from framework.test import opengl
30 from framework.test.base import TestIsSkip as _TestIsSkip
32 from .. import utils
34 # pylint: disable=no-self-use,attribute-defined-outside-init,protected-access
37 class TestFastSkipMixin(object): # pylint: disable=too-many-public-methods
38 """Tests for the FastSkipMixin class."""
40 @pytest.fixture(autouse=True, scope='class')
41 def patch(self):
42 """Create a Class with FastSkipMixin, but patch various bits."""
43 _mock_wflinfo = mock.Mock(spec=wflinfo.WflInfo)
44 _mock_wflinfo.core.api_version = 3.3
45 _mock_wflinfo.core.shader_version = 3.3
46 _mock_wflinfo.core.extensions = set(['bar'])
47 _mock_wflinfo.es2.api_version = 3.0
48 _mock_wflinfo.es2.shader_version = 2.0
49 _mock_wflinfo.es2.extensions = set(['bar'])
51 with mock.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo):
52 yield
54 class _Test(opengl.FastSkipMixin, utils.Test):
55 pass
57 def test_api(self):
58 """Tests that the api works.
60 Since you're not supposed to be able to pass gl and gles version, this
61 uses two separate constructor calls.
62 """
63 self._Test(['foo'], extensions={'foo'}, api_version=3, shader_version=2)
64 self._Test(['foo'], extensions={'foo'}, api_version=3,
65 shader_version=2)
68 class TestFastSkip(object):
69 """Tests for the FastSkip class."""
71 @pytest.fixture(autouse=True, scope='class')
72 def patch(self):
73 """Create a Class with FastSkipMixin, but patch various bits."""
74 _mock_wflinfo = mock.Mock(spec=wflinfo.WflInfo)
75 _mock_wflinfo.core.api_version = 3.3
76 _mock_wflinfo.core.shader_version = 3.3
77 _mock_wflinfo.core.extensions = set(['bar'])
78 _mock_wflinfo.es2.api_version = 3.0
79 _mock_wflinfo.es2.shader_version = 2.0
80 _mock_wflinfo.es2.extensions = set(['bar'])
82 with mock.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo):
83 yield
85 @pytest.fixture
86 def inst(self):
87 return opengl.FastSkip(api='core')
89 def test_should_skip(self, inst):
90 """test.opengl.FastSkipMixin.test: Skips when requires is missing
91 from extensions.
92 """
93 inst.extensions.add('foobar')
94 with pytest.raises(_TestIsSkip):
95 inst.test()
97 def test_should_not_skip(self, inst):
98 """test.opengl.FastSkipMixin.test: runs when requires is in
99 extensions.
101 inst.extensions.add('bar')
102 inst.test()
104 def test_max_api_version_lt(self, inst):
105 """test.opengl.FastSkipMixin.test: skips if api_version >
106 __max_api_version.
108 inst.api_version = 4.0
109 with pytest.raises(_TestIsSkip):
110 inst.test()
112 def test_max_api_version_gt(self, inst):
113 """test.opengl.FastSkipMixin.test: runs if api_version <
114 __max_api_version.
116 inst.api_version = 1.0
118 def test_max_api_version_set(self, inst):
119 """test.opengl.FastSkipMixin.test: runs if api_version is None"""
120 inst.test()
122 def test_max_api_version_lt(self, inst):
123 """test.opengl.FastSkipMixin.test: skips if api_version >
124 __max_api_version.
126 inst.api_version = 4.0
127 with pytest.raises(_TestIsSkip):
128 inst.test()
130 def test_max_api_version_gt(self, inst):
131 """test.opengl.FastSkipMixin.test: runs if api_version <
132 __max_api_version.
134 inst.api_version = 1.0
136 def test_max_api_version_set(self, inst):
137 """test.opengl.FastSkipMixin.test: runs if api_version is None"""
138 inst.test()
140 def test_max_shader_version_lt(self, inst):
141 """test.opengl.FastSkipMixin.test: skips if shader_version >
142 __max_shader_version.
144 inst.shader_version = 4.0
145 with pytest.raises(_TestIsSkip):
146 inst.test()
148 def test_max_shader_version_gt(self, inst):
149 """test.opengl.FastSkipMixin.test: runs if shader_version <
150 __max_shader_version.
152 inst.shader_version = 1.0
154 def test_max_shader_version_set(self, inst):
155 """test.opengl.FastSkipMixin.test: runs if shader_version is None"""
156 inst.test()
158 def test_max_shader_version_lt(self, inst):
159 """test.opengl.FastSkipMixin.test: skips if shader_version >
160 __max_shader_version.
162 inst.shader_version = 4.0
163 with pytest.raises(_TestIsSkip):
164 inst.test()
166 def test_max_shader_version_gt(self, inst):
167 """test.opengl.FastSkipMixin.test: runs if shader_version <
168 __max_shader_version.
170 inst.shader_version = 1.0
172 def test_max_shader_version_set(self, inst):
173 """test.opengl.FastSkipMixin.test: runs if shader_version is None"""
174 inst.test()
176 class TestEmpty(object):
177 """Tests for the FastSkip class when values are unset."""
179 @pytest.fixture(autouse=True, scope='class')
180 def patch(self):
181 """Create a Class with FastSkipMixin, but patch various bits."""
182 _mock_wflinfo = mock.Mock(spec=wflinfo.WflInfo)
183 _mock_wflinfo.core.api_version = 0.0
184 _mock_wflinfo.core.shader_version = 0.0
185 _mock_wflinfo.core.extensions = set()
186 _mock_wflinfo.es2.api_version = 0.0
187 _mock_wflinfo.es2.shader_version = 0.0
188 _mock_wflinfo.es2.extensions = set()
190 with mock.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo):
191 yield
193 @pytest.fixture
194 def inst(self):
195 return opengl.FastSkip(api='core')
197 def test_extension_empty(self, inst):
198 """test.opengl.FastSkipMixin.test: if extensions are empty test
199 runs.
201 inst.info.core.extensions.add('foobar')
202 inst.test()
204 def test_requires_empty(self, inst):
205 """test.opengl.FastSkipMixin.test: if gl_requires is empty test
206 runs.
208 inst.test()
210 def test_max_shader_version_unset(self, inst):
211 """test.opengl.FastSkipMixin.test: runs if __max_shader_version is
212 None.
214 inst.shader_version = 1.0
215 inst.test()
217 def test_max_api_version_unset(self, inst):
218 """test.opengl.FastSkipMixin.test: runs if __max_api_version is
219 None.
221 inst.api_version = 1.0
222 inst.test()
225 class TestFastSkipMixinDisabled(object):
226 """Tests for the sub version."""
228 @pytest.fixture(autouse=True, scope='class')
229 def patch(self):
230 """Create a Class with FastSkipMixin, but patch various bits."""
231 _mock_wflinfo = mock.Mock(spec=wflinfo.WflInfo)
232 _mock_wflinfo.es2.api_version = 3.3
233 _mock_wflinfo.es2.shader_version = 2.0
234 _mock_wflinfo.es2.extensions = set(['bar'])
235 _mock_wflinfo.core.api_version = 3.0
236 _mock_wflinfo.core.shader_version = 3.3
237 _mock_wflinfo.core.extensions = set(['bar'])
239 with mock.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo):
240 yield
242 class _Test(opengl.FastSkipMixin, utils.Test):
243 pass
245 def test_api(self):
246 """Tests that the api works.
248 Since you're not supposed to be able to pass gl and gles version, this
249 uses two separate constructor calls.
251 self._Test(['foo'], extensions={'foo'}, api_version=3, shader_version=2)
252 self._Test(['foo'], extensions={'foo'}, api_version=3,
253 shader_version=2)