[Piglit] [PATCH 2/2] glx-destroycontext-3: A new way to mess with glXDestroyContext().

Eric Anholt eric at anholt.net
Fri Feb 4 15:48:43 PST 2011


A side note: There's some weird spec text about contexts.  They're
pointers to GLX structures, so they're freed on destroy.  But if you
destroy a pointer that "is not a valid rendering context", it's
supposed to throw GLXBadContext.  I'm not sure how it should intuit
that some arbitrary pointer is not a valid context without
dereferencing that pointer and segfaulting instead.
---
 tests/all.tests                  |    1 +
 tests/glx/CMakeLists.txt         |    1 +
 tests/glx/glx-destroycontext-3.c |  116 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 0 deletions(-)
 create mode 100644 tests/glx/glx-destroycontext-3.c

diff --git a/tests/all.tests b/tests/all.tests
index 9073386..70d3ec4 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -823,6 +823,7 @@ glx = Group()
 add_plain_test(glx, 'glx-create-new-context-bad-1')
 add_plain_test(glx, 'glx-destroycontext-1')
 add_plain_test(glx, 'glx-destroycontext-2')
+add_plain_test(glx, 'glx-destroycontext-3')
 add_plain_test(glx, 'glx-multithread')
 add_plain_test(glx, 'glx-shader-sharing')
 add_plain_test(glx, 'glx-swap-exchange')
diff --git a/tests/glx/CMakeLists.txt b/tests/glx/CMakeLists.txt
index 701f196..6657042 100644
--- a/tests/glx/CMakeLists.txt
+++ b/tests/glx/CMakeLists.txt
@@ -25,6 +25,7 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 	add_executable (glx-shader-sharing glx-shader-sharing.c)
 	add_executable (glx-destroycontext-1 glx-destroycontext-1.c)
 	add_executable (glx-destroycontext-2 glx-destroycontext-2.c)
+	add_executable (glx-destroycontext-3 glx-destroycontext-3.c)
 	add_executable (glx-multithread glx-multithread.c)
 	add_executable (glx-make-current glx-make-current.c)
 	add_executable (glx-swap-event glx-swap-event.c)
diff --git a/tests/glx/glx-destroycontext-3.c b/tests/glx/glx-destroycontext-3.c
new file mode 100644
index 0000000..b656f89
--- /dev/null
+++ b/tests/glx/glx-destroycontext-3.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright © 2010-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.
+ */
+
+/** @file glx-destroycontext-3.c
+ *
+ * Test that MakeCurrent of the current context throws an error after
+ * destroying a context bound to the current thread.
+ *
+ * Page 26 of the GLX 1.4 spec (page 32 of the PDF) says:
+ *
+ * "If ctx is still current to any thread, ctx is not destroyed until
+ *  it is no longer current.  In any event, the associated XID will be
+ *  destroyed and ctx cannot subsequently be made current to any
+ *  thread."
+ *
+ * However, I see no spec of a particular error that should be thrown.
+ */
+
+#include "piglit-util.h"
+#include "piglit-glx-util.h"
+
+int piglit_width = 50, piglit_height = 50;
+static Display *dpy;
+static Window win;
+static XVisualInfo *visinfo;
+
+bool found_error = false;
+int expect_error(Display *dpy, XErrorEvent *e)
+{
+	found_error = true;
+
+	return 0;
+}
+
+enum piglit_result
+draw(Display *dpy)
+{
+	GLboolean pass = GL_TRUE;
+	float green[] = {0.0, 1.0, 0.0, 0.0};
+	GLXContext ctx;
+	int (*old_handler)(Display *dpy, XErrorEvent *e);
+
+	ctx = piglit_get_glx_context(dpy, visinfo);
+	glXMakeCurrent(dpy, win, ctx);
+	glClearColor(1.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+	glXDestroyContext(dpy, ctx);
+
+	/* Now that it's destroyed but still current to a thread, it's
+	 * invalid and we shouldn't be able to bind it to a thread,
+	 * even if it's our own thread.
+	 */
+	old_handler = XSetErrorHandler(expect_error);
+	glXMakeCurrent(dpy, win, ctx);
+	XSync(dpy, 0);
+	XSetErrorHandler(old_handler);
+
+	glClearColor(0.0, 1.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	pass &= piglit_probe_pixel_rgb(1, 1, green);
+
+	glXSwapBuffers(dpy, win);
+
+	/* Free our resources when we're done. */
+	glXMakeCurrent(dpy, None, NULL);
+
+	return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
+}
+
+int
+main(int argc, char **argv)
+{
+	int i;
+
+	for(i = 1; i < argc; ++i) {
+		if (!strcmp(argv[i], "-auto"))
+			piglit_automatic = 1;
+		else
+			fprintf(stderr, "Unknown option: %s\n", argv[i]);
+	}
+
+	dpy = XOpenDisplay(NULL);
+	if (dpy == NULL) {
+		fprintf(stderr, "couldn't open display\n");
+		piglit_report_result(PIGLIT_FAILURE);
+	}
+	visinfo = piglit_get_glx_visual(dpy);
+	win = piglit_get_glx_window(dpy, visinfo);
+
+	XMapWindow(dpy, win);
+
+	piglit_glx_event_loop(dpy, draw);
+
+	return 0;
+}
-- 
1.7.2.3



More information about the Piglit mailing list