[Piglit] [v8 05/13] tests/spec: EXT_image_dma_buf_import invalid hints

Topi Pohjolainen topi.pohjolainen at intel.com
Wed Jul 10 01:24:04 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)
   - check that EGL did not take the ownership and revise the
     explanation for it (Eric)

v3 (Eric):
   - revise the explanation claimed but not done in version two
   - use properly linked egl-extension calls

v4 (Eric):
   - add to 'all.tests'
   - removed inclusion of standard EGL entrypoints as there is the
     special dispatcher for the test cases to use
   - check for 'EGL_KHR_image_base' instead of 'GL_OES_EGL_image'
   - initialised 'pass = true' and used '&& pass'-pattern (Chad, Eric)

Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
---
 tests/all.tests                                    |   3 +
 tests/spec/CMakeLists.txt                          |   1 +
 .../ext_image_dma_buf_import/CMakeLists.gles1.txt  |  24 ++++
 tests/spec/ext_image_dma_buf_import/CMakeLists.txt |   1 +
 tests/spec/ext_image_dma_buf_import/image_common.c |  78 ++++++++++++
 tests/spec/ext_image_dma_buf_import/image_common.h |  44 +++++++
 .../spec/ext_image_dma_buf_import/invalid_hints.c  | 141 +++++++++++++++++++++
 7 files changed, 292 insertions(+)
 create mode 100644 tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
 create mode 100644 tests/spec/ext_image_dma_buf_import/CMakeLists.txt
 create mode 100644 tests/spec/ext_image_dma_buf_import/image_common.c
 create mode 100644 tests/spec/ext_image_dma_buf_import/image_common.h
 create mode 100644 tests/spec/ext_image_dma_buf_import/invalid_hints.c

diff --git a/tests/all.tests b/tests/all.tests
index 2a5fbd0..08d76b7 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1736,6 +1736,9 @@ add_plain_test(ext_framebuffer_object, 'fbo-storage-completeness')
 add_plain_test(ext_framebuffer_object, 'fbo-storage-formats')
 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')
 
 ext_packed_depth_stencil = Group()
 spec['EXT_packed_depth_stencil'] = ext_packed_depth_stencil
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index e6cd6d2..a15dc43 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -72,6 +72,7 @@ add_subdirectory (ext_texture_integer)
 add_subdirectory (arb_draw_buffers)
 add_subdirectory (oes_draw_texture)
 add_subdirectory (oes_fixed_point)
+add_subdirectory (ext_image_dma_buf_import)
 add_subdirectory (arb_blend_func_extended)
 add_subdirectory (ext_unpack_subimage)
 add_subdirectory (arb_vertex_array_object)
diff --git a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
new file mode 100644
index 0000000..d6adb24
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
@@ -0,0 +1,24 @@
+#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/")
+
+include_directories(
+	${OPENGL_INCLUDE_PATH}
+	)
+
+link_libraries(
+	${OPENGL_gles1_LIBRARY}
+	${OPENGL_egl_LIBRARY}
+	piglitutil_gles1
+	)
+
+# These tests rely on drm and are hence compiled only on linux/drm platforms
+if(LIBDRM_FOUND)
+	add_definitions(-DHAVE_LIBDRM)
+
+	include_directories(
+		${LIBDRM_INCLUDE_DIRS}
+	)
+
+	piglit_add_executable(ext_image_dma_buf_import-invalid_hints invalid_hints.c image_common.c)
+endif(LIBDRM_FOUND)
+
+# vim: ft=cmake:
diff --git a/tests/spec/ext_image_dma_buf_import/CMakeLists.txt b/tests/spec/ext_image_dma_buf_import/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/ext_image_dma_buf_import/image_common.c b/tests/spec/ext_image_dma_buf_import/image_common.c
new file mode 100644
index 0000000..d4480d8
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/image_common.c
@@ -0,0 +1,78 @@
+/*
+ * 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 "image_common.h"
+
+static void
+image_common_unsupported(const char *name)
+{
+	printf("Function \"%s\" not supported on this implementation\n", name);
+	piglit_report_result(PIGLIT_SKIP);
+}
+
+static void
+resolve_eglCreateImageKHR()
+{
+        if (piglit_is_egl_extension_supported(eglGetCurrentDisplay(),
+					"EGL_KHR_image_base"))
+                image_common_dispatch_eglCreateImageKHR =
+			(PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress(
+				"eglCreateImageKHR");
+        else
+                image_common_unsupported("CreateImageKHR");
+}
+
+static EGLImageKHR EGLAPIENTRY
+stub_eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
+		EGLClientBuffer buffer, const EGLint *attrib_list)
+{
+        resolve_eglCreateImageKHR();
+	return image_common_dispatch_eglCreateImageKHR(dpy, ctx, target, buffer,
+			 attrib_list);
+}
+
+PFNEGLCREATEIMAGEKHRPROC image_common_dispatch_eglCreateImageKHR =
+				stub_eglCreateImageKHR;
+
+static void
+resolve_eglDestroyImageKHR()
+{
+        if (piglit_is_egl_extension_supported(eglGetCurrentDisplay(),
+					"EGL_KHR_image_base"))
+                image_common_dispatch_eglDestroyImageKHR =
+			(PFNEGLDESTROYIMAGEKHRPROC ) eglGetProcAddress(
+				"eglDestroyImageKHR");
+        else
+                image_common_unsupported("DestroyImageKHR");
+}
+
+static EGLBoolean EGLAPIENTRY
+stub_eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
+{
+        resolve_eglDestroyImageKHR();
+	return image_common_dispatch_eglDestroyImageKHR(dpy, image);
+}
+
+PFNEGLDESTROYIMAGEKHRPROC image_common_dispatch_eglDestroyImageKHR =
+				stub_eglDestroyImageKHR;
diff --git a/tests/spec/ext_image_dma_buf_import/image_common.h b/tests/spec/ext_image_dma_buf_import/image_common.h
new file mode 100644
index 0000000..29338c0
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/image_common.h
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+#ifndef IMAGE_COMMON_H
+#define IMAGE_COMMON_H
+
+/**
+ * Temporary local dispatcer for EGL extensions. This can be replaced with the
+ * proper support once it is in place for EGL in the piglit core.
+ *
+ * A call in the tests is re-directed by the precompiler to a dispatcher that
+ * checks the availability of the real extension and takes care of the linking.
+ */
+
+#include "piglit-util-egl.h"
+#define EGL_EGLEXT_PROTOTYPES 1
+#include <EGL/eglext.h>
+
+extern PFNEGLCREATEIMAGEKHRPROC image_common_dispatch_eglCreateImageKHR;
+#define eglCreateImageKHR image_common_dispatch_eglCreateImageKHR
+
+extern PFNEGLDESTROYIMAGEKHRPROC image_common_dispatch_eglDestroyImageKHR;
+#define eglDestroyImageKHR image_common_dispatch_eglDestroyImageKHR
+
+#endif /* IMAGE_COMMON_H */
diff --git a/tests/spec/ext_image_dma_buf_import/invalid_hints.c b/tests/spec/ext_image_dma_buf_import/invalid_hints.c
new file mode 100644
index 0000000..9984303
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/invalid_hints.c
@@ -0,0 +1,141 @@
+/*
+ * 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_hints.c
+ *
+ * From the EXT_image_dma_buf_import spec:
+ *
+ * "Accepted as the value for the EGL_YUV_COLOR_SPACE_HINT_EXT attribute:
+ *
+ *       EGL_ITU_REC601_EXT   0x327F
+ *       EGL_ITU_REC709_EXT   0x3280
+ *       EGL_ITU_REC2020_EXT  0x3281
+ * 
+ * Accepted as the value for the EGL_SAMPLE_RANGE_HINT_EXT attribute:
+ * 
+ *       EGL_YUV_FULL_RANGE_EXT    0x3282
+ *       EGL_YUV_NARROW_RANGE_EXT  0x3283
+ *
+ * Accepted as the value for the EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT &
+ * EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT attributes:
+ *
+ *       EGL_YUV_CHROMA_SITING_0_EXT    0x3284
+ *       EGL_YUV_CHROMA_SITING_0_5_EXT  0x3285"
+ *
+ *
+ * In order to test these, one needs to have the following in place:
+ * EGL_WIDTH, EGL_HEIGHT, EGL_LINUX_DRM_FOURCC_EXT, EGL_DMA_BUF_PLANE0_FD_EXT,
+ * EGL_DMA_BUF_PLANE0_OFFSET_EXT and EGL_DMA_BUF_PLANE0_PITCH_EXT.
+ *
+ * \see invalid_attributes.c and missing_attributes.c
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 10;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static bool
+test_invalid_hint(unsigned w, unsigned h, int fd, unsigned stride,
+		unsigned offset, int hint, int val)
+{
+	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,
+		hint, val,
+		EGL_NONE
+	};
+
+	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
+			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attr);
+
+	if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
+		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_invalid_hint(w, h, fd, stride, offset,
+			EGL_YUV_COLOR_SPACE_HINT_EXT, 0) && pass;
+	pass = test_invalid_hint(w, h, fd, stride, offset,
+			EGL_SAMPLE_RANGE_HINT_EXT, 0) && pass;
+	pass = test_invalid_hint(w, h, fd, stride, offset,
+			EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT, 0) && pass;
+	pass = test_invalid_hint(w, h, fd, stride, offset,
+			EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT, 0) && pass;
+
+	piglit_destroy_dma_buf(buf);
+
+	/**
+	 * EGL stack can claim the ownership of the file descriptor only when it
+	 * succeeds. Close the descriptor 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