[Piglit] [v8 06/13] tests/spec: EXT_image_dma_buf_import invalid attributes
Topi Pohjolainen
topi.pohjolainen at intel.com
Wed Jul 10 01:24:05 PDT 2013
v2:
- compile only on platforms that have drm (Eric)
- use standard drm definitions for fourcc instead of duplicated
local (Daniel, Eric)
- use helper variables for width, height and cpp instead of
repeating the magic numbers over and over again (Eric)
- use the stride and offset provided by the framework instead of
hardcoded assumed values (Eric)
- rewritten excess attribute test vector using only one set of
attributes with a re-writable slot for one excess attribute
(Eric)
- check that EGL stack does not take the ownersip of the buffer
and revise the explanation for it (Eric)
- check also for EGL_DMA_BUF_PLANE2_* as excess attributes (Eric)
- removed irrelevant quotes of the spec (Eric)
- changed the error expected for non-NULL context from
'EGL_BAD_CONTEXT' to 'EGL_BAD_PARAMETER' (Eric)
v3:
- use properly linked egl-extension calls (Eric)
- make a distinction between invalid and unsupported formats.
The former is signified by 'EGL_BAD_ATTRIBUTE' while the latter
generates 'EGL_BAD_MATCH'. There is test only for the former
as the latter is driver dependent.
v4:
- add to 'all.tests' (Eric)
- removed inclusion of standard EGL entrypoints as there is the
special dispatcher for the test cases to use (Eric)
- removed irrelevant quote of the spec (Chad)
- initialised 'pass = true' and used '&& pass'-pattern (Chad, Eric)
Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
tests/all.tests | 1 +
.../ext_image_dma_buf_import/CMakeLists.gles1.txt | 1 +
.../ext_image_dma_buf_import/invalid_attributes.c | 261 +++++++++++++++++++++
3 files changed, 263 insertions(+)
create mode 100644 tests/spec/ext_image_dma_buf_import/invalid_attributes.c
diff --git a/tests/all.tests b/tests/all.tests
index 08d76b7..35bd23a 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1739,6 +1739,7 @@ add_plain_test(ext_framebuffer_object, 'getteximage-formats init-by-rendering')
ext_image_dma_buf_import = Group()
spec['EXT_image_dma_buf_import'] = ext_image_dma_buf_import
add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-invalid_hints')
+add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-invalid_attributes')
ext_packed_depth_stencil = Group()
spec['EXT_packed_depth_stencil'] = ext_packed_depth_stencil
diff --git a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
index d6adb24..b55acb8 100644
--- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
@@ -19,6 +19,7 @@ if(LIBDRM_FOUND)
)
piglit_add_executable(ext_image_dma_buf_import-invalid_hints invalid_hints.c image_common.c)
+ piglit_add_executable(ext_image_dma_buf_import-invalid_attributes invalid_attributes.c image_common.c)
endif(LIBDRM_FOUND)
# vim: ft=cmake:
diff --git a/tests/spec/ext_image_dma_buf_import/invalid_attributes.c b/tests/spec/ext_image_dma_buf_import/invalid_attributes.c
new file mode 100644
index 0000000..26e23b4
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/invalid_attributes.c
@@ -0,0 +1,261 @@
+/*
+ * Copyright © 2013 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 (including the next
+ * paragraph) 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.
+ */
+
+#include "piglit-util-egl.h"
+#include <unistd.h>
+#include <drm_fourcc.h>
+#include "image_common.h"
+
+/**
+ * @file invalid_attributes.c
+ *
+ * From the EXT_image_dma_buf_import spec:
+ *
+ * "* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the
+ * error EGL_BAD_PARAMETER is generated."
+ *
+ * and
+ *
+ * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
+ * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
+ * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
+ * attributes are specified.
+ *
+ * * If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values
+ * specified for a plane's pitch or offset isn't supported by EGL,
+ * EGL_BAD_ACCESS is generated."
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_es_version = 10;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+#define DRM_FORMAT_INVALID fourcc_code('F', 'O', 'O', '0')
+
+static bool
+test_excess_attributes(unsigned w, unsigned h, int fd, unsigned stride,
+ unsigned offset, EGLint attr_id, EGLint attr_val)
+{
+ const EGLint excess_attr[2 * 7 + 1] = {
+ EGL_HEIGHT, w,
+ EGL_WIDTH, h,
+ EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
+ EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
+ attr_id, attr_val,
+ EGL_NONE };
+ EGLImageKHR img = eglCreateImageKHR(eglGetCurrentDisplay(),
+ EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT,
+ (EGLClientBuffer)NULL, excess_attr);
+
+ if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
+ if (img)
+ eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+ return false;
+ }
+
+ return true;
+}
+
+static bool
+test_buffer_not_null(unsigned w, unsigned h, int fd, unsigned stride,
+ unsigned offset)
+{
+ EGLImageKHR img;
+ EGLint attr[] = {
+ EGL_WIDTH, w,
+ EGL_HEIGHT, h,
+ EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
+ EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
+ EGL_NONE
+ };
+
+ /**
+ * The spec says:
+ *
+ * "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid
+ * display, <ctx> must be EGL_NO_CONTEXT, and <buffer> must be
+ * NULL, cast into the type EGLClientBuffer."
+ */
+ img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
+ EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)1, attr);
+
+ if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
+ if (img)
+ eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+ return false;
+ }
+
+ return true;
+}
+
+static bool
+test_invalid_context(unsigned w, unsigned h, int fd, unsigned stride,
+ unsigned offset)
+{
+ EGLImageKHR img;
+ EGLint attr[] = {
+ EGL_WIDTH, w,
+ EGL_HEIGHT, h,
+ EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
+ EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
+ EGL_NONE
+ };
+
+ /**
+ * The spec says:
+ *
+ * "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid
+ * display, <ctx> must be EGL_NO_CONTEXT, and <buffer> must be
+ * NULL, cast into the type EGLClientBuffer."
+ */
+ img = eglCreateImageKHR(eglGetCurrentDisplay(), eglGetCurrentContext(),
+ EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attr);
+
+ if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
+ if (img)
+ eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+ return false;
+ }
+
+ return true;
+}
+
+static bool
+test_invalid_format(unsigned w, unsigned h, int fd, unsigned stride,
+ unsigned offset)
+{
+ EGLImageKHR img;
+ EGLint attr[] = {
+ EGL_WIDTH, w,
+ EGL_HEIGHT, h,
+ EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_INVALID,
+ EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
+ EGL_NONE
+ };
+
+ img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
+ EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
+
+ if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
+ if (img)
+ eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+ return false;
+ }
+
+ return true;
+}
+
+static bool
+test_pitch_zero(unsigned w, unsigned h, int fd, unsigned stride,
+ unsigned offset)
+{
+ EGLImageKHR img;
+ EGLint attr[] = {
+ EGL_WIDTH, w,
+ EGL_HEIGHT, h,
+ EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
+ EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,
+ EGL_NONE
+ };
+
+ img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
+ EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
+
+ if (!piglit_check_egl_error(EGL_BAD_ACCESS)) {
+ if (img)
+ eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * One and same buffer is used for all the tests. Each test is expected to fail
+ * meaning that the ownership is not transferred to the EGL in any point.
+ */
+enum piglit_result
+piglit_display(void)
+{
+ const unsigned w = 2;
+ const unsigned h = 2;
+ const unsigned cpp = 4;
+ const unsigned char pixels[w * h * cpp];
+ struct piglit_dma_buf *buf;
+ unsigned stride;
+ unsigned offset;
+ int fd;
+ enum piglit_result res;
+ bool pass = true;
+
+ res = piglit_create_dma_buf(w, h, cpp, pixels, w * cpp,
+ &buf, &fd, &stride, &offset);
+ if (res != PIGLIT_PASS)
+ return res;
+
+ pass = test_excess_attributes(w, h, fd, stride, offset,
+ EGL_DMA_BUF_PLANE1_FD_EXT, fd) && pass;
+ pass = test_excess_attributes(w, h, fd, stride, offset,
+ EGL_DMA_BUF_PLANE1_OFFSET_EXT, 0) && pass;
+ pass = test_excess_attributes(w, h, fd, stride, offset,
+ EGL_DMA_BUF_PLANE1_PITCH_EXT, stride) && pass;
+ pass = test_excess_attributes(w, h, fd, stride, offset,
+ EGL_DMA_BUF_PLANE2_FD_EXT, fd) && pass;
+ pass = test_excess_attributes(w, h, fd, stride, offset,
+ EGL_DMA_BUF_PLANE2_OFFSET_EXT, 0) && pass;
+ pass = test_excess_attributes(w, h, fd, stride, offset,
+ EGL_DMA_BUF_PLANE2_PITCH_EXT, stride) && pass;
+ pass = test_buffer_not_null(w, h, fd, stride, offset) && pass;
+ pass = test_invalid_context(w, h, fd, stride, offset) && pass;
+ pass = test_invalid_format(w, h, fd, stride, offset) && pass;
+ pass = test_pitch_zero(w, h, fd, stride, offset) && pass;
+
+ piglit_destroy_dma_buf(buf);
+
+ /**
+ * EGL stack can claim the ownership of the file descriptor only when it
+ * succeeds. Close the file descriptor here and check that it really
+ * wasn't closed by EGL.
+ */
+ pass = (close(fd) == 0) && pass;
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ piglit_require_egl_extension("EGL_EXT_image_dma_buf_import");
+}
--
1.8.1.2
More information about the Piglit
mailing list