[Piglit] [PATCH v2 03/17] egl_khr_create_context: Add common test infrastructure

Matt Turner mattst88 at gmail.com
Thu Aug 16 10:48:19 PDT 2012


v2: - Require EGL_KHR_surfaceless_context instead of other surfaceless
      extensions.
    - Fix for-loop typo.
    - Make EGL_KHR_create_context_setup take a renderable_type_mask argument.
    - Make EGL_KHR_create_context_setup return whether it succeeded.
    - PIGLIT_SKIP if eglChooseConfig fails (in the case of requesting an
      ES 1.x context when 1.x isn't supported).
    - Add version_is_valid_for_context helper function.
---
 tests/all_egl.tests                                |    3 +
 tests/egl/CMakeLists.gl.txt                        |    2 +
 tests/egl/spec/CMakeLists.txt                      |    1 +
 .../spec/egl_khr_create_context/CMakeLists.gl.txt  |   14 ++
 .../egl/spec/egl_khr_create_context/CMakeLists.txt |    1 +
 tests/egl/spec/egl_khr_create_context/common.c     |  134 ++++++++++++++++++++
 tests/egl/spec/egl_khr_create_context/common.h     |   52 ++++++++
 7 files changed, 207 insertions(+), 0 deletions(-)
 create mode 100644 tests/egl/spec/CMakeLists.txt
 create mode 100644 tests/egl/spec/egl_khr_create_context/CMakeLists.gl.txt
 create mode 100644 tests/egl/spec/egl_khr_create_context/CMakeLists.txt
 create mode 100644 tests/egl/spec/egl_khr_create_context/common.c
 create mode 100644 tests/egl/spec/egl_khr_create_context/common.h

diff --git a/tests/all_egl.tests b/tests/all_egl.tests
index c2d097a..93faef6 100644
--- a/tests/all_egl.tests
+++ b/tests/all_egl.tests
@@ -17,3 +17,6 @@ egl['egl-query-surface-EGL_BAD_ATTRIBUTE'] = plain_test('egl-query-surface --bad
 egl['egl-query-surface-EGL_BAD_SURFACE'] = plain_test('egl-query-surface --bad-surface')
 egl['egl-query-surface-EGL_HEIGHT'] = plain_test('egl-query-surface --attr=EGL_HEIGHT')
 egl['egl-query-surface-EGL_WIDTH'] = plain_test('egl-query-surface --attr=EGL_WIDTH')
+
+create_context = Group();
+egl['EGL_KHR_create_context'] = create_context
diff --git a/tests/egl/CMakeLists.gl.txt b/tests/egl/CMakeLists.gl.txt
index fb73248..03b2ae0 100644
--- a/tests/egl/CMakeLists.gl.txt
+++ b/tests/egl/CMakeLists.gl.txt
@@ -20,6 +20,8 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 	target_link_libraries(egl-create-surface pthread ${X11_X11_LIB})
 	piglit_add_executable (egl-query-surface egl-util.c egl-query-surface.c)
 	target_link_libraries(egl-query-surface pthread ${X11_X11_LIB})
+
+	add_subdirectory(spec)
 ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 
 # vim: ft=cmake:
diff --git a/tests/egl/spec/CMakeLists.txt b/tests/egl/spec/CMakeLists.txt
new file mode 100644
index 0000000..de4de3f
--- /dev/null
+++ b/tests/egl/spec/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory (egl_khr_create_context)
diff --git a/tests/egl/spec/egl_khr_create_context/CMakeLists.gl.txt b/tests/egl/spec/egl_khr_create_context/CMakeLists.gl.txt
new file mode 100644
index 0000000..a25f747
--- /dev/null
+++ b/tests/egl/spec/egl_khr_create_context/CMakeLists.gl.txt
@@ -0,0 +1,14 @@
+
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+	${GLPROTO_INCLUDE_DIRS}
+)
+
+link_libraries (
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+	${X11_X11_LIB}
+)
+
+# vim: ft=cmake:
diff --git a/tests/egl/spec/egl_khr_create_context/CMakeLists.txt b/tests/egl/spec/egl_khr_create_context/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/egl/spec/egl_khr_create_context/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/egl/spec/egl_khr_create_context/common.c b/tests/egl/spec/egl_khr_create_context/common.c
new file mode 100644
index 0000000..00fa6d0
--- /dev/null
+++ b/tests/egl/spec/egl_khr_create_context/common.c
@@ -0,0 +1,134 @@
+/* Copyright © 2012 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 <ctype.h>
+#include <errno.h>
+#include "common.h"
+
+static Display *dpy = NULL;
+EGLDisplay egl_dpy;
+EGLConfig cfg;
+EGLContext ctx;
+
+bool
+parse_version_string(const char *string, int *major, int *minor)
+{
+	char *next;
+	int ma;
+	int mi;
+
+	if (string == NULL)
+		return false;
+
+	next = (char *)string;
+	while (!isdigit(*next) && *next != '\0')
+		next++;
+
+	if (next[0] == '\0')
+		return false;
+
+	errno = 0;
+	ma = strtol(next, &next, 10);
+	if (next == NULL || errno != 0)
+		return false;
+
+	while (!isdigit(*next) && *next != '\0')
+		next++;
+
+	if (next[0] == '\0')
+		return false;
+
+	mi = strtol(next, &next, 10);
+	if (errno != 0)
+		return false;
+
+	*major = ma;
+	*minor = mi;
+	return true;
+}
+
+static void
+check_extensions(void)
+{
+	static const char *extensions[] = {
+		"EGL_KHR_create_context",
+		"EGL_KHR_surfaceless_context"
+	};
+	int i;
+
+	const char *extension_string = eglQueryString(egl_dpy, EGL_EXTENSIONS);
+	for (i = 0; i < ARRAY_SIZE(extensions); i++) {
+		if (!strstr(extension_string, extensions[i])) {
+			fprintf(stderr, "missing extension %s\n",
+				extensions[i]);
+			piglit_report_result(PIGLIT_SKIP);
+		}
+	}
+}
+
+bool
+EGL_KHR_create_context_setup(EGLint renderable_type_mask)
+{
+	EGLint config_attribs[] = {
+		EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT,
+		EGL_RED_SIZE, 1,
+		EGL_GREEN_SIZE, 1,
+		EGL_BLUE_SIZE, 1,
+		EGL_DEPTH_SIZE, 1,
+		EGL_RENDERABLE_TYPE, renderable_type_mask,
+		EGL_NONE
+	};
+	EGLint count;
+	EGLint major, minor;
+
+	dpy = XOpenDisplay(NULL);
+	if (dpy == NULL) {
+		fprintf(stderr, "couldn't open display\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	egl_dpy = eglGetDisplay(dpy);
+	if (egl_dpy == EGL_NO_DISPLAY) {
+		fprintf(stderr, "eglGetDisplay() failed\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	if (!eglInitialize(egl_dpy, &major, &minor)) {
+		fprintf(stderr, "eglInitialize() failed\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	if (!eglChooseConfig(egl_dpy, config_attribs, &cfg, 1, &count) ||
+	    count == 0) {
+		fprintf(stderr, "eglChooseConfig() failed\n");
+		return false;
+	}
+
+	check_extensions();
+	return true;
+}
+
+void
+EGL_KHR_create_context_teardown(void)
+{
+	eglTerminate(egl_dpy);
+}
diff --git a/tests/egl/spec/egl_khr_create_context/common.h b/tests/egl/spec/egl_khr_create_context/common.h
new file mode 100644
index 0000000..a31aa53
--- /dev/null
+++ b/tests/egl/spec/egl_khr_create_context/common.h
@@ -0,0 +1,52 @@
+/* Copyright © 2012 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-gl-common.h"
+#include <X11/Xlib.h>
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+extern EGLDisplay egl_dpy;
+extern EGLConfig cfg;
+extern EGLContext ctx;
+
+extern bool parse_version_string(const char *string, int *major, int *minor);
+extern bool EGL_KHR_create_context_setup(EGLint renderable_type_mask);
+extern void EGL_KHR_create_context_teardown(void);
+
+static inline bool
+version_is_valid_for_context(int ctx_major, int major, int minor)
+{
+	if (ctx_major == 1) {
+		if (major == 1 && (minor == 0 || minor == 1)) {
+			return true;
+		}
+	} else if (ctx_major == 2) {
+		/* GLES 3.0 is backward compatible with 2.0 and is the only version
+		 * currently available that is compatible with 2.0.
+		 */
+		if ((major == 2 || major == 3) && minor == 0) {
+			return true;
+		}
+	}
+	return false;
+}
-- 
1.7.8.6



More information about the Piglit mailing list