[Piglit] [PATCH 05/14] glx_ext_import_context: Add common test infrastructure
Ian Romanick
idr at freedesktop.org
Thu Dec 8 15:41:52 PST 2011
From: Ian Romanick <ian.d.romanick at intel.com>
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
tests/spec/CMakeLists.txt | 1 +
.../spec/glx_ext_import_context/CMakeLists.gl.txt | 20 ++
tests/spec/glx_ext_import_context/CMakeLists.txt | 1 +
tests/spec/glx_ext_import_context/common.c | 298 ++++++++++++++++++++
tests/spec/glx_ext_import_context/common.h | 66 +++++
5 files changed, 386 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/glx_ext_import_context/CMakeLists.gl.txt
create mode 100644 tests/spec/glx_ext_import_context/CMakeLists.txt
create mode 100644 tests/spec/glx_ext_import_context/common.c
create mode 100644 tests/spec/glx_ext_import_context/common.h
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index a4021c3..a5a8335 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -33,6 +33,7 @@ add_subdirectory (glsl-1.20)
add_subdirectory (glsl-1.30)
add_subdirectory (gl-2.0)
add_subdirectory (gl-3.0)
+add_subdirectory (glx_ext_import_context)
add_subdirectory (arb_vertex_type_2_10_10_10_rev)
add_subdirectory (ext_texture_integer)
add_subdirectory (arb_draw_buffers)
diff --git a/tests/spec/glx_ext_import_context/CMakeLists.gl.txt b/tests/spec/glx_ext_import_context/CMakeLists.gl.txt
new file mode 100644
index 0000000..b9521e5
--- /dev/null
+++ b/tests/spec/glx_ext_import_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_ext_import_context/CMakeLists.txt b/tests/spec/glx_ext_import_context/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/glx_ext_import_context/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/glx_ext_import_context/common.c b/tests/spec/glx_ext_import_context/common.c
new file mode 100644
index 0000000..b922233
--- /dev/null
+++ b/tests/spec/glx_ext_import_context/common.c
@@ -0,0 +1,298 @@
+/* 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 <assert.h>
+#include "piglit-util.h"
+#include "piglit-glx-util.h"
+#include "common.h"
+
+PFNGLXGETCURRENTDISPLAYEXTPROC __piglit_glXGetCurrentDisplayEXT = NULL;
+PFNGLXQUERYCONTEXTINFOEXTPROC __piglit_glXQueryContextInfoEXT = NULL;
+PFNGLXGETCONTEXTIDEXTPROC __piglit_glXGetContextIDEXT = NULL;
+PFNGLXIMPORTCONTEXTEXTPROC __piglit_glXImportContextEXT = NULL;
+PFNGLXFREECONTEXTEXTPROC __piglit_glXFreeContextEXT = NULL;
+
+Display *dpy = NULL;
+XVisualInfo *visinfo = NULL;
+GLXContext directCtx = NULL;
+GLXContextID directID = None;
+GLXContext indirectCtx = NULL;
+GLXContextID indirectID = 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;
+}
+
+void GLX_EXT_import_context_setup_for_child(void)
+{
+ dpy = piglit_get_glx_display();
+ old_handler = XSetErrorHandler(x_error_handler);
+}
+
+void GLX_EXT_import_context_setup(void)
+{
+ const char *const names[] = {
+ "glXGetCurrentDisplayEXT",
+ "glXQueryContextInfoEXT",
+ "glXGetContextIDEXT",
+ "glXImportContextEXT",
+ "glXFreeContextEXT"
+ };
+
+ __GLXextFuncPtr *procedures[ARRAY_SIZE(names)] = {
+ (__GLXextFuncPtr *) & __piglit_glXGetCurrentDisplayEXT,
+ (__GLXextFuncPtr *) & __piglit_glXQueryContextInfoEXT,
+ (__GLXextFuncPtr *) & __piglit_glXGetContextIDEXT,
+ (__GLXextFuncPtr *) & __piglit_glXImportContextEXT,
+ (__GLXextFuncPtr *) & __piglit_glXFreeContextEXT
+ };
+
+ const char *vendor;
+
+ dpy = piglit_get_glx_display();
+
+ /* NVIDIA incorrectly only list the extension in the client
+ * extenstions list. If the extension is available for applications
+ * to use, it is supposed to be included in the list returned by
+ * glXQueryExtensionsString.
+ *
+ * The glXImportContextEXT manual page is somewhat clear on this
+ * topic:
+ *
+ * "If _glxextstring(EXT_import_context) is included in the string
+ * returned by glXQueryExtensionsString, when called with argument
+ * GLX_EXTENSIONS, extension EXT_import_context is supported."
+ *
+ * The text is a little weird because the only parameters to
+ * glXQueryExtensionsString are the display and the screen.
+ */
+ vendor = glXGetClientString(dpy, GLX_VENDOR);
+ if (strcmp("NVIDIA Corporation", vendor) == 0) {
+ const char needle[] = "GLX_EXT_import_context";
+ const unsigned needle_len = sizeof(needle) - 1;
+ const char *haystack;
+ bool found = false;
+
+ haystack = glXGetClientString(dpy, GLX_EXTENSIONS);
+ while (haystack != NULL) {
+ const char *s = strstr(haystack, needle);
+
+ if (s != NULL
+ && (s[needle_len] == ' '
+ || s[needle_len] == '\0')) {
+ found = true;
+ break;
+ }
+
+ haystack = s;
+ }
+
+ if (!found) {
+ fprintf(stderr, "Test requires %s\n", needle);
+ piglit_report_result(PIGLIT_SKIP);
+ }
+ } else {
+ piglit_require_glx_extension(dpy, "GLX_EXT_import_context");
+ }
+
+ piglit_glx_get_all_proc_addresses(procedures, names, ARRAY_SIZE(names));
+
+ visinfo = piglit_get_glx_visual(dpy);
+
+ directCtx = glXCreateContext(dpy, visinfo, NULL, True);
+ if (directCtx == NULL) {
+ fprintf(stderr,
+ "Could not create initial direct-rendering context.\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ if (!glXIsDirect(dpy, directCtx)) {
+ glXDestroyContext(dpy, directCtx);
+ directCtx = NULL;
+ }
+
+ indirectCtx = glXCreateContext(dpy, visinfo, NULL, False);
+ if (indirectCtx == NULL) {
+ fprintf(stderr,
+ "Could not create initial indirect-rendering "
+ "context.\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ piglit_glx_get_error(dpy, NULL);
+ old_handler = XSetErrorHandler(x_error_handler);
+}
+
+void GLX_EXT_import_context_teardown(void)
+{
+ if (directCtx != NULL) {
+ glXDestroyContext(dpy, directCtx);
+ directCtx = NULL;
+ }
+
+ if (indirectCtx != NULL) {
+ glXDestroyContext(dpy, indirectCtx);
+ indirectCtx = NULL;
+ }
+
+ XFree(visinfo);
+ visinfo = NULL;
+
+ XSetErrorHandler(old_handler);
+}
+
+void get_context_IDs(void)
+{
+ directID = None;
+ if (directCtx != NULL) {
+ directID = glXGetContextIDEXT(directCtx);
+ }
+
+ indirectID = None;
+ if (indirectCtx != NULL) {
+ indirectID = glXGetContextIDEXT(indirectCtx);
+ }
+}
+
+const char *context_mode_name(enum context_mode mode)
+{
+ switch (mode) {
+ case direct_rendering:
+ return "direct-rendering";
+ case indirect_rendering:
+ return "indirect-rendering";
+ case invalid:
+ return "invalid";
+ default:
+ assert(!"Should not get here.");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ return "";
+}
+
+bool try_import_context(GLXContextID id, enum context_mode mode)
+{
+ const int expected_glx_error = (mode == invalid) ? GLXBadContext : -1;
+ bool pass = true;
+ GLXContext ctx = glXImportContextEXT(dpy, id);
+
+ XSync(dpy, 0);
+
+ switch (mode) {
+ case direct_rendering:
+ if (ctx != NULL) {
+ fprintf(stderr,
+ "Could import direct-rendering context, "
+ "but should have failed.\n");
+ pass = false;
+ }
+ break;
+
+ case indirect_rendering:
+ if (ctx == NULL) {
+ fprintf(stderr,
+ "Could not import indirect-rendering context, "
+ "but should have succeeded.\n");
+ pass = false;
+ }
+ break;
+
+ case invalid:
+ if (ctx != NULL) {
+ fprintf(stderr,
+ "Could import invalid context (0x%08x), "
+ "but should have failed.\n",
+ (int) id);
+ pass = false;
+ }
+ break;
+ }
+
+ assert(mode != invalid || expected_glx_error != -1);
+ pass = validate_glx_error_code(Success, expected_glx_error) && pass;
+
+ if (!pass)
+ fprintf(stderr, "Context ID = 0x%08x.\n", (int) id);
+
+ if (ctx != NULL)
+ glXFreeContextEXT(dpy, ctx);
+
+ return pass;
+}
+
+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_ext_import_context/common.h b/tests/spec/glx_ext_import_context/common.h
new file mode 100644
index 0000000..ec906a2
--- /dev/null
+++ b/tests/spec/glx_ext_import_context/common.h
@@ -0,0 +1,66 @@
+/* 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 PFNGLXGETCURRENTDISPLAYEXTPROC __piglit_glXGetCurrentDisplayEXT;
+#define glXGetCurrentDisplayEXT() (*__piglit_glXGetCurrentDisplayEXT)()
+
+extern PFNGLXQUERYCONTEXTINFOEXTPROC __piglit_glXQueryContextInfoEXT;
+#define glXQueryContextInfoEXT(dpy, ctx, attrib, value) \
+ (*__piglit_glXQueryContextInfoEXT)(dpy, ctx, attrib, value)
+
+extern PFNGLXGETCONTEXTIDEXTPROC __piglit_glXGetContextIDEXT;
+#define glXGetContextIDEXT(ctx) (*__piglit_glXGetContextIDEXT)(ctx)
+
+extern PFNGLXIMPORTCONTEXTEXTPROC __piglit_glXImportContextEXT;
+#define glXImportContextEXT(dpy, ctx) (*__piglit_glXImportContextEXT)(dpy, ctx)
+
+extern PFNGLXFREECONTEXTEXTPROC __piglit_glXFreeContextEXT;
+#define glXFreeContextEXT(dpy, ctx) (*__piglit_glXFreeContextEXT)(dpy, ctx)
+
+extern Display *dpy;
+extern XVisualInfo *visinfo;
+extern GLXContext directCtx;
+extern GLXContextID directID;
+extern GLXContext indirectCtx;
+extern GLXContextID indirectID;
+extern int glx_error_code;
+extern int x_error_code;
+
+extern void GLX_EXT_import_context_setup(void);
+
+extern void GLX_EXT_import_context_teardown(void);
+
+extern void GLX_EXT_import_context_setup_for_child(void);
+
+extern void get_context_IDs(void);
+
+enum context_mode {
+ direct_rendering = 0,
+ indirect_rendering,
+ invalid
+};
+
+extern bool validate_glx_error_code(int expected_x_error, int expected_glx_error);
+
+extern const char *context_mode_name(enum context_mode mode);
+
+extern bool try_import_context(GLXContextID id, enum context_mode mode);
--
1.7.6.4
More information about the Piglit
mailing list