[Piglit] [PATCH 01/12] glx_arb_create_context: Add common test infrastructure

Ian Romanick idr at freedesktop.org
Wed Dec 14 10:47:20 PST 2011


From: Ian Romanick <ian.d.romanick at intel.com>

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 tests/all.tests                                    |    3 +
 tests/spec/CMakeLists.txt                          |    1 +
 .../spec/glx_arb_create_context/CMakeLists.gl.txt  |   20 +++
 tests/spec/glx_arb_create_context/CMakeLists.txt   |    1 +
 tests/spec/glx_arb_create_context/common.c         |  163 ++++++++++++++++++++
 tests/spec/glx_arb_create_context/common.h         |   41 +++++
 6 files changed, 229 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/glx_arb_create_context/CMakeLists.gl.txt
 create mode 100644 tests/spec/glx_arb_create_context/CMakeLists.txt
 create mode 100644 tests/spec/glx_arb_create_context/common.c
 create mode 100644 tests/spec/glx_arb_create_context/common.h

diff --git a/tests/all.tests b/tests/all.tests
index b713de0..ccc2db0 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -623,6 +623,9 @@ import_context['make current, multi process'] = PlainExecTest(['glx-make-current
 import_context['make current, single process'] = PlainExecTest(['glx-make-current-single-process'])
 import_context['query context info'] = PlainExecTest(['glx-query-context-info-ext'])
 
+create_context = Group();
+glx['GLX_ARB_create_context'] = create_context
+
 texturing = Group()
 add_concurrent_test(texturing, '1-1-linear-texture')
 add_plain_test(texturing, 'array-texture')
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index ae997c6..12e2e4a 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -35,6 +35,7 @@ add_subdirectory (glsl-1.30)
 add_subdirectory (gl-2.0)
 add_subdirectory (gl-2.1)
 add_subdirectory (gl-3.0)
+add_subdirectory (glx_arb_create_context)
 add_subdirectory (glx_ext_import_context)
 add_subdirectory (arb_vertex_type_2_10_10_10_rev)
 add_subdirectory (ext_texture_integer)
diff --git a/tests/spec/glx_arb_create_context/CMakeLists.gl.txt b/tests/spec/glx_arb_create_context/CMakeLists.gl.txt
new file mode 100644
index 0000000..b9521e5
--- /dev/null
+++ b/tests/spec/glx_arb_create_context/CMakeLists.gl.txt
@@ -0,0 +1,20 @@
+
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+	${GLUT_INCLUDE_DIR}
+	${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries (
+	piglitglxutil
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+	${GLUT_glut_LIBRARY}
+	${X11_X11_LIB}
+)
+
+IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+
+# vim: ft=cmake:
diff --git a/tests/spec/glx_arb_create_context/CMakeLists.txt b/tests/spec/glx_arb_create_context/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/glx_arb_create_context/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/glx_arb_create_context/common.c b/tests/spec/glx_arb_create_context/common.c
new file mode 100644
index 0000000..5498231
--- /dev/null
+++ b/tests/spec/glx_arb_create_context/common.c
@@ -0,0 +1,163 @@
+/* Copyright © 2011 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 "piglit-util.h"
+#include "piglit-glx-util.h"
+#include "common.h"
+
+PFNGLXCREATECONTEXTATTRIBSARBPROC __piglit_glXCreateContextAttribsARB = NULL;
+
+Display *dpy = NULL;
+GLXFBConfig fbconfig = None;
+XVisualInfo *visinfo = NULL;
+Window win = None;
+GLXWindow glxWin = None;
+
+int glx_error_code = -1;
+int x_error_code = Success;
+
+int piglit_height = 50;
+int piglit_width = 50;
+
+static int (*old_handler)(Display *, XErrorEvent *);
+
+static int x_error_handler(Display *dpy, XErrorEvent *e)
+{
+
+	x_error_code = e->error_code;
+	glx_error_code = piglit_glx_get_error(dpy, e);
+
+        return 0;
+}
+
+bool
+parse_version_string(const char *string, int *major, int *minor)
+{
+	char *next;
+	int ma;
+	int mi;
+
+	if (string == NULL)
+		return false;
+
+	errno = 0;
+	ma = strtol(string, &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;
+}
+
+void
+GLX_ARB_create_context_setup(void)
+{
+	dpy = piglit_get_glx_display();
+
+	piglit_require_glx_version(dpy, 1, 4);
+	piglit_require_glx_extension(dpy, "GLX_ARB_create_context");
+
+	__piglit_glXCreateContextAttribsARB =
+		(PFNGLXCREATECONTEXTATTRIBSARBPROC)
+		glXGetProcAddress((const GLubyte *)
+				  "glXCreateContextAttribsARB");
+	assert(__piglit_glXCreateContextAttribsARB != NULL);
+
+	visinfo = piglit_get_glx_visual(dpy);
+	fbconfig = piglit_glx_get_fbconfig_for_visinfo(dpy, visinfo);
+
+	win = piglit_get_glx_window_unmapped(dpy, visinfo);
+	glxWin = glXCreateWindow(dpy, fbconfig, win, NULL);
+
+	piglit_glx_get_error(dpy, NULL);
+	old_handler = XSetErrorHandler(x_error_handler);
+}
+
+void
+GLX_ARB_create_context_teardown(void)
+{
+	if (glxWin != None) {
+		glXDestroyWindow(dpy, glxWin);
+		glxWin = None;
+	}
+
+	XFree(visinfo);
+	visinfo = NULL;
+
+        XSetErrorHandler(old_handler);
+}
+
+bool validate_glx_error_code(int expected_x_error, int expected_glx_error)
+{
+	bool pass = true;
+
+	if (expected_glx_error == -1
+	    && expected_x_error == Success
+	    && (glx_error_code != -1 || x_error_code != Success)) {
+		fprintf(stderr,
+			"X error %d (%s (%d)) was generated, but "
+			"no error was expected.\n",
+			x_error_code,
+			piglit_glx_error_string(glx_error_code),
+			glx_error_code);
+		pass = false;
+	}
+
+	if (expected_glx_error != -1
+	    && glx_error_code != expected_glx_error) {
+		fprintf(stderr,
+			"X error %d (%s (%d)) was generated, but "
+			"%s (%d) was expected.\n",
+			x_error_code,
+			piglit_glx_error_string(glx_error_code),
+			glx_error_code,
+			piglit_glx_error_string(expected_glx_error),
+			expected_glx_error);
+		pass = false;
+	} else if (expected_x_error != Success
+		   && x_error_code != expected_x_error) {
+		fprintf(stderr,
+			"X error %d (%s (%d)) was generated, but "
+			"X error %d was expected.\n",
+			x_error_code,
+			piglit_glx_error_string(glx_error_code),
+			glx_error_code,
+			expected_x_error);
+		pass = false;
+	}
+
+	x_error_code = Success;
+	glx_error_code = -1;
+	return pass;
+}
diff --git a/tests/spec/glx_arb_create_context/common.h b/tests/spec/glx_arb_create_context/common.h
new file mode 100644
index 0000000..2e58b16
--- /dev/null
+++ b/tests/spec/glx_arb_create_context/common.h
@@ -0,0 +1,41 @@
+/* Copyright © 2011 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.
+ */
+
+extern PFNGLXCREATECONTEXTATTRIBSARBPROC __piglit_glXCreateContextAttribsARB;
+#define glXCreateContextAttribsARB(dpy, config, share, direct, attrib)     \
+	(*__piglit_glXCreateContextAttribsARB)(dpy, config, share, direct, \
+					       attrib)
+
+extern Display *dpy;
+extern GLXFBConfig fbconfig;
+extern XVisualInfo *visinfo;
+extern Window win;
+extern GLXWindow glxWin;
+
+extern bool parse_version_string(const char *string, int *major, int *minor);
+
+extern void GLX_ARB_create_context_setup(void);
+
+extern void GLX_ARB_create_context_teardown(void);
+
+extern bool validate_glx_error_code(int expected_x_error,
+				    int expected_glx_error);
-- 
1.7.6.4



More information about the Piglit mailing list