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

Chad Versace chad.versace at linux.intel.com
Tue May 7 14:56:12 PDT 2013


On 05/03/2013 04:26 AM, Topi Pohjolainen wrote:
> Simple test checking that EGL can close the export file handle
> and the creator can in turn can its reference.

Without a verb, the second phrase above is a bit too elliptical. How about
"can in turn $VERB its reference"?

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



> diff --git a/tests/spec/ext_image_dma_buf_import/close_buffer.c b/tests/spec/ext_image_dma_buf_import/close_buffer.c
> new file mode 100644
> index 0000000..fb03d1b
> --- /dev/null
> +++ b/tests/spec/ext_image_dma_buf_import/close_buffer.c
> @@ -0,0 +1,117 @@



> +/**
> + * @file close_buffer.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 on checks that the creator of the buffer can drop its reference once
            ^^^ one
> + * it has given the buffer to EGL, i.e., after calling 'eglCreateImageKHR()'.


I don't see how this test verifies the above spec quote. I think you need,
as Eric suggested previously, to call close(fd) after eglDestroyImageKHR
and check that it returns EBADF.


> + */
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_es_version = 10;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static bool
> +test_create_and_destroy(void *buf, int fd, unsigned w, unsigned h,
> +			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)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);
> +
> +	return piglit_check_egl_error(EGL_SUCCESS);
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	const unsigned char pixels[2 * 2 * 4];
> +	struct piglit_dma_buf *buf;
> +	unsigned stride;
> +	unsigned offset;
> +	int fd;
> +	enum piglit_result res;
> +
> +	res = piglit_create_dma_buf(2, 2, 4, pixels, 2 * 4, &buf, &fd, &stride,
> +				&offset);
> +	if (res != PIGLIT_PASS)
> +		return res;
> +
> +	return test_create_and_destroy(buf, fd, 2, 2, stride, offset) ?
> +			PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	piglit_require_egl_extension("EGL_EXT_image_dma_buf_import");
> +}
>


More information about the Piglit mailing list