ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_image_dma_buf_import / missing_attributes.c
blob3cfaca38f3779f337cc9cf77c18959f20d4d4b9b
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 missing_attributes.c
31 * Tests that EGL detects missing attributes correctly.
33 * From the EXT_image_dma_buf_import spec:
35 * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
36 * incomplete, EGL_BAD_PARAMETER is generated."
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config.supports_gl_es_version = 10;
43 PIGLIT_GL_TEST_CONFIG_END
45 #define NUM_MANDATORY_ATTRS 6
47 static bool
48 test_missing(int fd, const EGLint *attr)
50 EGLImageKHR img;
52 img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
53 EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attr);
55 if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
56 if (img)
57 eglDestroyImageKHR(eglGetCurrentDisplay(), img);
58 return false;
61 return true;
64 static void
65 fill_full_set(unsigned w, unsigned h, EGLint fd, EGLint offset, EGLint stride,
66 EGLint *out)
68 /* Reference set containing all the mandatory attributes. */
69 const EGLint all[2 * NUM_MANDATORY_ATTRS] = {
70 EGL_WIDTH, w,
71 EGL_HEIGHT, h,
72 EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
73 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
74 EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
75 EGL_DMA_BUF_PLANE0_PITCH_EXT, stride
78 memcpy(out, all, sizeof(all));
81 static void
82 fill_one_missing(const EGLint *all, EGLint *out, EGLint missing)
84 unsigned i, j;
86 for (i = j = 0; i < NUM_MANDATORY_ATTRS; ++i) {
87 if (all[2 * i] != missing) {
88 out[2 * j + 0] = all[2 * i + 0];
89 out[2 * j + 1] = all[2 * i + 1];
90 ++j;
94 out[2 * j] = EGL_NONE;
97 /**
98 * Here one tries to create an image with six different attribute sets each
99 * missing one of the mandatory attribute.
101 * One and same buffer is used for all the tests. Each test is expected to fail
102 * meaning that the ownership is not transferred to the EGL in any point.
104 enum piglit_result
105 piglit_display(void)
107 const unsigned w = 2;
108 const unsigned h = 2;
109 const unsigned cpp = 4;
110 const unsigned fourcc = DRM_FORMAT_ARGB8888;
111 const unsigned char *pixels = alloca(w * h * cpp);
112 EGLint all[2 * NUM_MANDATORY_ATTRS];
113 EGLint missing[2 * (NUM_MANDATORY_ATTRS - 1) + 1];
114 struct piglit_dma_buf *buf;
115 enum piglit_result res;
116 bool pass = true;
118 res = piglit_create_dma_buf(w, h, fourcc, pixels, &buf);
119 if (res != PIGLIT_PASS)
120 return res;
122 fill_full_set(w, h, buf->fd, buf->offset[0], buf->stride[0], all);
124 fill_one_missing(all, missing, EGL_HEIGHT);
125 pass = test_missing(buf->fd, missing) && pass;
127 fill_one_missing(all, missing, EGL_WIDTH);
128 pass = test_missing(buf->fd, missing) && pass;
130 fill_one_missing(all, missing, EGL_LINUX_DRM_FOURCC_EXT);
131 pass = test_missing(buf->fd, missing) && pass;
133 fill_one_missing(all, missing, EGL_DMA_BUF_PLANE0_FD_EXT);
134 pass = test_missing(buf->fd, missing) && pass;
136 fill_one_missing(all, missing, EGL_DMA_BUF_PLANE0_OFFSET_EXT);
137 pass = test_missing(buf->fd, missing) && pass;
139 fill_one_missing(all, missing, EGL_DMA_BUF_PLANE0_PITCH_EXT);
140 pass = test_missing(buf->fd, missing) && pass;
143 * EGL stack can claim the ownership of the file descriptor only when it
144 * succeeds. Close the file descriptor here and check that it really
145 * wasn't closed by EGL.
147 pass = (close(buf->fd) == 0) && pass;
149 piglit_destroy_dma_buf(buf);
151 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
154 void
155 piglit_init(int argc, char **argv)
157 EGLDisplay egl_dpy = eglGetCurrentDisplay();
158 piglit_require_egl_extension(egl_dpy, "EGL_EXT_image_dma_buf_import");