aboutsummaryrefslogtreecommitdiff
path: root/tests/egl
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2012-07-23 09:54:18 -0700
committerMatt Turner <mattst88@gmail.com>2012-08-24 16:25:39 -0700
commit5af7535edd12c9c661830eabd6b244e9740b4e46 (patch)
tree0e1321d2519800bd7b51b036c1a53608dcfe05dd /tests/egl
parent15223f787647e93363fcd9c2d7789676b3d9b69d (diff)
egl_khr_create_context: Add common test infrastructure
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.
Diffstat (limited to 'tests/egl')
-rw-r--r--tests/egl/CMakeLists.gl.txt2
-rw-r--r--tests/egl/spec/CMakeLists.txt1
-rw-r--r--tests/egl/spec/egl_khr_create_context/CMakeLists.gl.txt14
-rw-r--r--tests/egl/spec/egl_khr_create_context/CMakeLists.txt1
-rw-r--r--tests/egl/spec/egl_khr_create_context/common.c134
-rw-r--r--tests/egl/spec/egl_khr_create_context/common.h52
6 files changed, 204 insertions, 0 deletions
diff --git a/tests/egl/CMakeLists.gl.txt b/tests/egl/CMakeLists.gl.txt
index fb732481..03b2ae01 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 00000000..de4de3f0
--- /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 00000000..a25f7472
--- /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 00000000..144a306f
--- /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 00000000..00fa6d0a
--- /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 00000000..a31aa534
--- /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;
+}