[Piglit] [PATCH 1/2] glx-create-new-context-bad-1: New test for a glXCreateNewContext() error.

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


Our GLX is not currently throwing the BadValue like the spec suggests
it should.
---
 tests/all.tests                          |    1 +
 tests/glx/CMakeLists.txt                 |    1 +
 tests/glx/glx-create-new-context-bad-1.c |  100 ++++++++++++++++++++++++++++++
 3 files changed, 102 insertions(+), 0 deletions(-)
 create mode 100644 tests/glx/glx-create-new-context-bad-1.c

diff --git a/tests/all.tests b/tests/all.tests
index f2b0f81..9073386 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -820,6 +820,7 @@ add_plain_test(bugs, 'fdo31934')
 add_plain_test(bugs, 'tri-tex-crash')
 
 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-multithread')
diff --git a/tests/glx/CMakeLists.txt b/tests/glx/CMakeLists.txt
index cd5da21..701f196 100644
--- a/tests/glx/CMakeLists.txt
+++ b/tests/glx/CMakeLists.txt
@@ -21,6 +21,7 @@ link_libraries (
 )
 
 IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+	add_executable (glx-create-new-context-bad-1 glx-create-new-context-bad-1.c)
 	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)
diff --git a/tests/glx/glx-create-new-context-bad-1.c b/tests/glx/glx-create-new-context-bad-1.c
new file mode 100644
index 0000000..d20901f
--- /dev/null
+++ b/tests/glx/glx-create-new-context-bad-1.c
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+
+/** @file glx-create-new-context-bad-1.c
+ *
+ * Test that glXCreateNewContext() with a render_type other than
+ * GLX_RGBA_TYPE or GLX_COLOR_INDEX_TYPE generates BadValue.
+ *
+ * Page 26 of the GLX 1.4 spec (page 32 of the PDF) says:
+ *
+ * "If render type is set to GLX RGBA TYPE then a context that
+ *  supports RGBA rendering is created; if render type is set to GLX
+ *  COLOR INDEX TYPE then a context that supports color index
+ *  rendering is created.
+ *  ...
+ *  glXCreateNewContext can generate the following errors: ...
+ *  BadValue if render type does not refer to a valid rendering
+ *  type."
+ */
+
+#include "piglit-util.h"
+#include "piglit-glx-util.h"
+
+int piglit_width = 50, piglit_height = 50;
+
+bool found_badvalue = false;
+int expect_badvalue(Display *dpy, XErrorEvent *e)
+{
+	if (e->error_code == BadValue)
+		found_badvalue = true;
+
+	return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+	Display *dpy;
+	XVisualInfo *visinfo;
+	int (*old_handler)(Display *, XErrorEvent *);
+	GLXContext ctx;
+	int attrib[] = {
+		GLX_RGBA,
+		GLX_RED_SIZE, 1,
+		GLX_GREEN_SIZE, 1,
+		GLX_BLUE_SIZE, 1,
+		GLX_DOUBLEBUFFER,
+		None
+	};
+	GLXFBConfig config, *configs;
+	int nconfigs;
+
+	dpy = XOpenDisplay(NULL);
+	if (dpy == NULL) {
+		fprintf(stderr, "couldn't open display\n");
+		piglit_report_result(PIGLIT_FAILURE);
+	}
+
+	configs = glXChooseFBConfig(dpy, DefaultScreen(dpy),
+				    attrib, &nconfigs);
+	assert(nconfigs > 0);
+	config = configs[0];
+	XFree(configs);
+
+	visinfo = glXGetVisualFromFBConfig(dpy, config);
+
+	old_handler = XSetErrorHandler(expect_badvalue);
+	ctx = glXCreateNewContext(dpy, config, GLX_NONE, NULL, True);
+	XSync(dpy, 0);
+	XSetErrorHandler(old_handler);
+
+	if (!found_badvalue) {
+		printf("Failed to get BadValue from glXCreateContext().\n");
+		piglit_report_result(PIGLIT_FAIL);
+	} else {
+		piglit_report_result(PIGLIT_PASS);
+	}
+
+	return 0;
+}
-- 
1.7.2.3



More information about the Piglit mailing list