2 * Copyright © 2013 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 #include <gtest/gtest.h>
27 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
29 #include "glxclient.h"
30 #include "glx_error.h"
32 #include "GL/internal/dri_interface.h"
33 #include "dri2_priv.h"
36 struct attribute_test_vector
{
37 const char *glx_string
;
38 const char *dri_string
;
44 #define E(g, d) { # g, # d, g, d }
46 static bool got_sigsegv
;
50 sigsegv_handler(int sig
)
57 class dri2_query_renderer_string_test
: public ::testing::Test
{
60 virtual void TearDown();
63 struct sigaction old_sa
;
66 class dri2_query_renderer_integer_test
:
67 public dri2_query_renderer_string_test
{
70 static bool queryString_called
= false;
71 static int queryString_attribute
= -1;
73 static bool queryInteger_called
= false;
74 static int queryInteger_attribute
= -1;
77 fake_queryInteger(__DRIscreen
*screen
, int attribute
, unsigned int *val
)
81 queryInteger_attribute
= attribute
;
82 queryInteger_called
= true;
85 case __DRI2_RENDERER_VENDOR_ID
:
86 *val
= ~__DRI2_RENDERER_VENDOR_ID
;
88 case __DRI2_RENDERER_DEVICE_ID
:
89 *val
= ~__DRI2_RENDERER_DEVICE_ID
;
91 case __DRI2_RENDERER_VERSION
:
92 *val
= ~__DRI2_RENDERER_VERSION
;
94 case __DRI2_RENDERER_ACCELERATED
:
95 *val
= ~__DRI2_RENDERER_ACCELERATED
;
97 case __DRI2_RENDERER_VIDEO_MEMORY
:
98 *val
= ~__DRI2_RENDERER_VIDEO_MEMORY
;
100 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
:
101 *val
= ~__DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
;
103 case __DRI2_RENDERER_PREFERRED_PROFILE
:
104 *val
= ~__DRI2_RENDERER_PREFERRED_PROFILE
;
106 case __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION
:
107 *val
= ~__DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION
;
109 case __DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION
:
110 *val
= ~__DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION
;
112 case __DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION
:
113 *val
= ~__DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION
;
115 case __DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION
:
116 *val
= ~__DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION
;
124 fake_queryString(__DRIscreen
*screen
, int attribute
, const char **val
)
128 queryString_attribute
= attribute
;
129 queryString_called
= true;
132 case __DRI2_RENDERER_VENDOR_ID
:
133 *val
= "__DRI2_RENDERER_VENDOR_ID";
135 case __DRI2_RENDERER_DEVICE_ID
:
136 *val
= "__DRI2_RENDERER_DEVICE_ID";
143 static const __DRI2rendererQueryExtension rendererQueryExt
= {
144 { __DRI2_RENDERER_QUERY
, 1 },
150 void dri2_query_renderer_string_test::SetUp()
154 sa
.sa_handler
= sigsegv_handler
;
155 sigemptyset(&sa
.sa_mask
);
157 sigaction(SIGSEGV
, &sa
, &old_sa
);
160 void dri2_query_renderer_string_test::TearDown()
162 sigaction(SIGSEGV
, &old_sa
, NULL
);
166 * dri2_query_renderer_string will return an error if the rendererQuery
167 * extension is not present. It will also not segfault.
169 TEST_F(dri2_query_renderer_string_test
, DRI2_RENDERER_QUERY_not_supported
)
171 struct dri2_screen dsc
;
173 memset(&dsc
, 0, sizeof(dsc
));
175 if (setjmp(jmp
) == 0) {
176 static const char original_value
[] = "0xDEADBEEF";
177 const char *value
= original_value
;
179 dri2_query_renderer_string(&dsc
.base
,
180 GLX_RENDERER_VENDOR_ID_MESA
, &value
);
182 EXPECT_EQ(-1, success
);
183 EXPECT_EQ(original_value
, value
);
185 EXPECT_FALSE(got_sigsegv
);
190 * dri2_query_renderer_string will call queryString with the correct DRI2 enum
191 * for each GLX attribute value.
194 * This test does \b not perform any checking for invalid GLX attribte values.
195 * Other unit tests verify that invalid values are filtered before
196 * dri2_query_renderer_string is called.
198 TEST_F(dri2_query_renderer_string_test
, valid_attribute_mapping
)
200 struct dri2_screen dsc
;
201 struct attribute_test_vector valid_attributes
[] = {
202 E(GLX_RENDERER_VENDOR_ID_MESA
,
203 __DRI2_RENDERER_VENDOR_ID
),
204 E(GLX_RENDERER_DEVICE_ID_MESA
,
205 __DRI2_RENDERER_DEVICE_ID
),
208 memset(&dsc
, 0, sizeof(dsc
));
209 dsc
.rendererQuery
= &rendererQueryExt
;
211 if (setjmp(jmp
) == 0) {
212 for (unsigned i
= 0; i
< ARRAY_SIZE(valid_attributes
); i
++) {
213 static const char original_value
[] = "original value";
214 const char *value
= original_value
;
216 dri2_query_renderer_string(&dsc
.base
,
217 valid_attributes
[i
].glx_attribute
,
220 EXPECT_EQ(0, success
);
221 EXPECT_EQ(valid_attributes
[i
].dri_attribute
, queryString_attribute
)
222 << valid_attributes
[i
].glx_string
;
223 EXPECT_STREQ(valid_attributes
[i
].dri_string
, value
)
224 << valid_attributes
[i
].glx_string
;
227 EXPECT_FALSE(got_sigsegv
);
232 * dri2_query_renderer_integer will return an error if the rendererQuery
233 * extension is not present. It will also not segfault.
235 TEST_F(dri2_query_renderer_integer_test
, DRI2_RENDERER_QUERY_not_supported
)
237 struct dri2_screen dsc
;
239 memset(&dsc
, 0, sizeof(dsc
));
241 if (setjmp(jmp
) == 0) {
242 unsigned int value
= 0xDEADBEEF;
244 dri2_query_renderer_integer(&dsc
.base
,
245 GLX_RENDERER_VENDOR_ID_MESA
, &value
);
247 EXPECT_EQ(-1, success
);
248 EXPECT_EQ(0xDEADBEEF, value
);
250 EXPECT_FALSE(got_sigsegv
);
255 * dri2_query_renderer_integer will call queryInteger with the correct DRI2 enum
256 * for each GLX attribute value.
259 * This test does \b not perform any checking for invalid GLX attribte values.
260 * Other unit tests verify that invalid values are filtered before
261 * dri2_query_renderer_integer is called.
263 TEST_F(dri2_query_renderer_integer_test
, valid_attribute_mapping
)
265 struct dri2_screen dsc
;
266 struct attribute_test_vector valid_attributes
[] = {
267 E(GLX_RENDERER_VENDOR_ID_MESA
,
268 __DRI2_RENDERER_VENDOR_ID
),
269 E(GLX_RENDERER_DEVICE_ID_MESA
,
270 __DRI2_RENDERER_DEVICE_ID
),
271 E(GLX_RENDERER_VERSION_MESA
,
272 __DRI2_RENDERER_VERSION
),
273 E(GLX_RENDERER_ACCELERATED_MESA
,
274 __DRI2_RENDERER_ACCELERATED
),
275 E(GLX_RENDERER_VIDEO_MEMORY_MESA
,
276 __DRI2_RENDERER_VIDEO_MEMORY
),
277 E(GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA
,
278 __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
),
279 E(GLX_RENDERER_PREFERRED_PROFILE_MESA
,
280 __DRI2_RENDERER_PREFERRED_PROFILE
),
281 E(GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA
,
282 __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION
),
283 E(GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA
,
284 __DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION
),
285 E(GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA
,
286 __DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION
),
287 E(GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA
,
288 __DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION
),
291 memset(&dsc
, 0, sizeof(dsc
));
292 dsc
.rendererQuery
= &rendererQueryExt
;
294 if (setjmp(jmp
) == 0) {
295 for (unsigned i
= 0; i
< ARRAY_SIZE(valid_attributes
); i
++) {
296 unsigned int value
= 0xDEADBEEF;
298 dri2_query_renderer_integer(&dsc
.base
,
299 valid_attributes
[i
].glx_attribute
,
302 EXPECT_EQ(0, success
);
303 EXPECT_EQ(valid_attributes
[i
].dri_attribute
, queryInteger_attribute
)
304 << valid_attributes
[i
].glx_string
;
305 EXPECT_EQ((unsigned int) ~valid_attributes
[i
].dri_attribute
, value
)
306 << valid_attributes
[i
].glx_string
;
309 EXPECT_FALSE(got_sigsegv
);
313 #endif /* GLX_DIRECT_RENDERING */