glx: don't fail test if the X server is inconsistent
[piglit.git] / tests / spec / ext_image_dma_buf_import / invalid_attributes.c
blobd1f34f7eb35e30739e6381a0f22e33e2dae6d74c
1 /*
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
13 * Software.
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 DEALINGS
21 * IN THE SOFTWARE.
24 #include "piglit-framework-gl/piglit_drm_dma_buf.h"
26 #include "image_common.h"
28 /**
29 * @file invalid_attributes.c
31 * From the EXT_image_dma_buf_import spec:
33 * "* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the
34 * error EGL_BAD_PARAMETER is generated."
36 * and
38 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
39 * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
40 * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
41 * attributes are specified.
43 * * If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values
44 * specified for a plane's pitch or offset isn't supported by EGL,
45 * EGL_BAD_ACCESS is generated."
48 PIGLIT_GL_TEST_CONFIG_BEGIN
50 config.supports_gl_es_version = 10;
52 PIGLIT_GL_TEST_CONFIG_END
54 #define DRM_FORMAT_NONEXISTENT fourcc_code('F', 'O', 'O', '0')
56 static bool
57 test_excess_attributes(unsigned w, unsigned h, int fd, unsigned stride,
58 unsigned offset, EGLint attr_id, EGLint attr_val)
60 const EGLint excess_attr[2 * 7 + 1] = {
61 EGL_HEIGHT, w,
62 EGL_WIDTH, h,
63 EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
64 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
65 EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
66 EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
67 attr_id, attr_val,
68 EGL_NONE };
69 EGLImageKHR img = eglCreateImageKHR(eglGetCurrentDisplay(),
70 EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT,
71 (EGLClientBuffer)NULL, excess_attr);
73 if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
74 if (img)
75 eglDestroyImageKHR(eglGetCurrentDisplay(), img);
76 return false;
79 return true;
82 static bool
83 test_buffer_not_null(unsigned w, unsigned h, int fd, unsigned stride,
84 unsigned offset)
86 EGLImageKHR img;
87 EGLint attr[] = {
88 EGL_WIDTH, w,
89 EGL_HEIGHT, h,
90 EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
91 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
92 EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
93 EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
94 EGL_NONE
97 /**
98 * The spec says:
100 * "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid
101 * display, <ctx> must be EGL_NO_CONTEXT, and <buffer> must be
102 * NULL, cast into the type EGLClientBuffer."
104 img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
105 EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)1, attr);
107 if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
108 if (img)
109 eglDestroyImageKHR(eglGetCurrentDisplay(), img);
110 return false;
113 return true;
116 static bool
117 test_invalid_context(unsigned w, unsigned h, int fd, unsigned stride,
118 unsigned offset)
120 EGLImageKHR img;
121 EGLint attr[] = {
122 EGL_WIDTH, w,
123 EGL_HEIGHT, h,
124 EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
125 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
126 EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
127 EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
128 EGL_NONE
132 * The spec says:
134 * "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid
135 * display, <ctx> must be EGL_NO_CONTEXT, and <buffer> must be
136 * NULL, cast into the type EGLClientBuffer."
138 img = eglCreateImageKHR(eglGetCurrentDisplay(), eglGetCurrentContext(),
139 EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attr);
141 if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
142 if (img)
143 eglDestroyImageKHR(eglGetCurrentDisplay(), img);
144 return false;
147 return true;
150 static bool
151 test_invalid_format(unsigned w, unsigned h, int fd, unsigned stride,
152 unsigned offset)
154 EGLImageKHR img;
155 EGLint attr[] = {
156 EGL_WIDTH, w,
157 EGL_HEIGHT, h,
158 EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_NONEXISTENT,
159 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
160 EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
161 EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
162 EGL_NONE
166 * The spec says:
168 * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
169 * attribute is set to a format not supported by the EGL, EGL_BAD_MATCH
170 * is generated."
172 img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
173 EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
175 if (!piglit_check_egl_error(EGL_BAD_MATCH)) {
176 if (img)
177 eglDestroyImageKHR(eglGetCurrentDisplay(), img);
178 return false;
181 return true;
184 static bool
185 test_pitch_zero(unsigned w, unsigned h, int fd, unsigned stride,
186 unsigned offset)
188 EGLImageKHR img;
189 EGLint attr[] = {
190 EGL_WIDTH, w,
191 EGL_HEIGHT, h,
192 EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
193 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
194 EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
195 EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,
196 EGL_NONE
199 img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
200 EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
202 if (!piglit_check_egl_error(EGL_BAD_ACCESS)) {
203 if (img)
204 eglDestroyImageKHR(eglGetCurrentDisplay(), img);
205 return false;
208 return true;
212 * One and same buffer is used for all the tests. Each test is expected to fail
213 * meaning that the ownership is not transferred to the EGL in any point.
215 enum piglit_result
216 piglit_display(void)
218 const unsigned w = 2;
219 const unsigned h = 2;
220 const unsigned cpp = 4;
221 const unsigned fourcc = DRM_FORMAT_ARGB8888;
222 const unsigned char *pixels = alloca(w * h * cpp);
223 struct piglit_dma_buf *buf;
224 enum piglit_result res;
225 bool pass = true;
227 res = piglit_create_dma_buf(w, h, fourcc, pixels, &buf);
228 if (res != PIGLIT_PASS)
229 return res;
231 pass = test_excess_attributes(w, h, buf->fd, buf->stride[0], buf->offset[0],
232 EGL_DMA_BUF_PLANE1_FD_EXT, buf->fd) && pass;
233 pass = test_excess_attributes(w, h, buf->fd, buf->stride[0], buf->offset[0],
234 EGL_DMA_BUF_PLANE1_OFFSET_EXT, 0) && pass;
235 pass = test_excess_attributes(w, h, buf->fd, buf->stride[0], buf->offset[0],
236 EGL_DMA_BUF_PLANE1_PITCH_EXT, buf->stride[0]) && pass;
237 pass = test_excess_attributes(w, h, buf->fd, buf->stride[0], buf->offset[0],
238 EGL_DMA_BUF_PLANE2_FD_EXT, buf->fd) && pass;
239 pass = test_excess_attributes(w, h, buf->fd, buf->stride[0], buf->offset[0],
240 EGL_DMA_BUF_PLANE2_OFFSET_EXT, 0) && pass;
241 pass = test_excess_attributes(w, h, buf->fd, buf->stride[0], buf->offset[0],
242 EGL_DMA_BUF_PLANE2_PITCH_EXT, buf->stride[0]) && pass;
243 pass = test_buffer_not_null(w, h, buf->fd, buf->stride[0], buf->offset[0]) && pass;
244 pass = test_invalid_context(w, h, buf->fd, buf->stride[0], buf->offset[0]) && pass;
245 pass = test_invalid_format(w, h, buf->fd, buf->stride[0], buf->offset[0]) && pass;
246 pass = test_pitch_zero(w, h, buf->fd, buf->stride[0], buf->offset[0]) && pass;
249 * EGL stack can claim the ownership of the file descriptor only when it
250 * succeeds. Close the file descriptor here and check that it really
251 * wasn't closed by EGL.
253 pass = (close(buf->fd) == 0) && pass;
255 piglit_destroy_dma_buf(buf);
257 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
260 void
261 piglit_init(int argc, char **argv)
263 EGLDisplay egl_dpy = eglGetCurrentDisplay();
264 piglit_require_egl_extension(egl_dpy, "EGL_EXT_image_dma_buf_import");