[Piglit] [v7 07/12] tests: spec: EXT_image_dma_buf_import fd ownership transfer

Topi Pohjolainen topi.pohjolainen at intel.com
Tue May 28 02:51:43 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)

Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 .../ext_image_dma_buf_import/CMakeLists.gles1.txt  |   1 +
 .../ext_image_dma_buf_import/ownership_transfer.c  | 120 +++++++++++++++++++++
 2 files changed, 121 insertions(+)
 create mode 100644 tests/spec/ext_image_dma_buf_import/ownership_transfer.c

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..6716ae3
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/ownership_transfer.c
@@ -0,0 +1,120 @@
+/*
+ * 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"
+#define EGL_EGLEXT_PROTOTYPES 1
+#include <EGL/eglext.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 bool
+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, EGL should have the
+	 * ownership now.
+	 */
+	piglit_destroy_dma_buf(buf);
+
+	if (!piglit_check_egl_error(EGL_SUCCESS))
+		return false;
+
+	if (!img) {
+		fprintf(stderr, "image creation succeed but returned NULL\n");
+		return false;
+	}
+
+	eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+
+	if (!piglit_check_egl_error(EGL_SUCCESS))
+		return false;
+
+	/* EGL stack should have closed the importing file descriptor */
+	return close(fd) && errno == EBADF;
+}
+
+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) ?
+			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