[Piglit] [v9 09/13] tests/spec: EXT_image_dma_buf_import fd ownership transfer

Topi Pohjolainen topi.pohjolainen at intel.com
Fri Aug 9 03:43:03 PDT 2013


Simple test checking that EGL closes the export file handle and
the creator can in turn drop its reference.

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)
   - try to close the export file descriptor and check that it is
     already closed by the EGL stack (Eric, Chad)
   - fix typo in the description (and commit) (Chad)
   - renamed from "close_buffer" to "ownership_transfer"
   - removed irrelevant quote of the spec (Eric)

v3:
   - use properly linked egl-extension calls (Eric)
   - check for EBADF and not just for close()-failure (Daniel)

v4 (Eric):
   - add to 'all.tests'
   - removed inclusion of standard EGL entrypoints as there is the
     special dispatcher for the test cases to use
   - close the egl-display before checking if the file descriptor
     is closed

v5 (Chad):
   - skip the test if EGL does not support the chosen format
   - report possible failure of 'eglTerminate()' in the console

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/ownership_transfer.c  | 127 +++++++++++++++++++++
 3 files changed, 129 insertions(+)
 create mode 100644 tests/spec/ext_image_dma_buf_import/ownership_transfer.c

diff --git a/tests/all.tests b/tests/all.tests
index 41a8294..aebdb3b 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1763,6 +1763,7 @@ 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')
 add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-missing_attributes')
+add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-ownership_transfer')
 
 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 44ecfa0..6c322d3 100644
--- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
@@ -21,6 +21,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)
 	piglit_add_executable(ext_image_dma_buf_import-missing_attributes missing_attributes.c image_common.c)
+	piglit_add_executable(ext_image_dma_buf_import-ownership_transfer ownership_transfer.c image_common.c)
 endif(LIBDRM_FOUND)
 
 # vim: ft=cmake:
diff --git a/tests/spec/ext_image_dma_buf_import/ownership_transfer.c b/tests/spec/ext_image_dma_buf_import/ownership_transfer.c
new file mode 100644
index 0000000..6e34955
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/ownership_transfer.c
@@ -0,0 +1,127 @@
+/*
+ * 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 <drm_fourcc.h>
+#include <unistd.h>
+#include <errno.h>
+#include "image_common.h"
+
+/**
+ * @file ownership_transfer.c
+ *
+ * From the EXT_image_dma_buf_import spec:
+ *
+ * "3. Does ownership of the file descriptor pass to the EGL library?
+ *
+ *   ANSWER: If eglCreateImageKHR is successful, EGL assumes ownership of the
+ *   file descriptors and is responsible for closing them."
+ *
+ *
+ * Here one checks that the creator of the buffer can drop its reference once
+ * it has given the buffer to EGL, i.e., after calling 'eglCreateImageKHR()'.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 10;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static enum piglit_result
+test_create_and_destroy(unsigned w, unsigned h, void *buf, 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
+	};
+
+	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
+			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
+
+	/* Release the creator side of the buffer. */
+	piglit_destroy_dma_buf(buf);
+
+	/* EGL may not support the format, this is not an error. */
+	if (!img && piglit_check_egl_error(EGL_BAD_MATCH))
+		return PIGLIT_SKIP;
+
+	if (!piglit_check_egl_error(EGL_SUCCESS))
+		return PIGLIT_FAIL;
+
+	if (!img) {
+		fprintf(stderr, "image creation succeed but returned NULL\n");
+		return PIGLIT_FAIL;
+	}
+
+	eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+
+	if (!piglit_check_egl_error(EGL_SUCCESS))
+		return PIGLIT_FAIL;
+
+	/**
+	 * EGL stack is allowed to keep the importing file descriptor open until
+	 * all resources are released. Therefore close the display first.
+	 */
+	if (!eglTerminate(eglGetCurrentDisplay())) {
+		fprintf(stderr, "eglTerminate() failed\n");
+		return PIGLIT_FAIL;
+	}
+
+	/* EGL stack should have closed the importing file descriptor by now */
+	return close(fd) && errno == EBADF ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+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;
+
+	res = piglit_create_dma_buf(w, h, cpp, pixels, w * cpp,
+				&buf, &fd, &stride, &offset);
+	if (res != PIGLIT_PASS)
+		return res;
+
+	return test_create_and_destroy(w, h, buf, fd, stride, offset);
+}
+
+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