[Piglit] [v8 08/13] tests/spec: EXT_image_dma_buf_import fd ownership transfer

Chad Versace chad.versace at linux.intel.com
Wed Jul 31 15:19:34 PDT 2013


> +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);

EGL_EXT_image_dma_buf_import is allowed to reject any format, including
ARGB8888, in which case it emits EGL_BAD_MATCH. So, if (!img and piglti_check_egl_error(EGL_BAD_MATCH)),
then this test should skip with an explanatory message rather than failing.

> +
> +	/**
> +	 * 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 is allowed to keep the importing file descriptor open until
> +	 * all resources are released. Therefore close the display first.
> +	 */
> +	if (!eglTerminate(eglGetCurrentDisplay()))
> +		return false;

If eglTerminate fails, then the test should print a message stating that. It is
so incredibly rare for eglTerminate to fail, that the test should really tell
the user when it happens.

> +
> +	/* EGL stack should have closed the importing file descriptor by now */
> +	return close(fd) && errno == EBADF;
> +}

Otherwise, the test looks good.



More information about the Piglit mailing list