[Piglit] =?a?q?=5BPATCH=205/5=5D=20glx=3A=20Test=20behavior=20of=20glXQueryDrawable=28=29?=

Chad Versace chad at chad-versace.us
Wed Oct 19 18:37:50 PDT 2011


Add the following tests:

* glx-query-drawable-GLXBadDrawable
      Calls glXQueryDrawable(draw=0) and expects that the GLXBadDrawable
      error is generated.

* glx-query-drawalbe-GLX_WIDTH
* glx-query-drawalbe-GLX_HEIGHT
      Calls glXQueryDrawable() with the given attribute.

All tests fail on Fedora 15, which has Mesa 7.11 and Xserver 1.10.14.

Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 tests/all.tests                |    3 +
 tests/glx/CMakeLists.gl.txt    |    1 +
 tests/glx/glx-query-drawable.c |  211 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 215 insertions(+), 0 deletions(-)
 create mode 100644 tests/glx/glx-query-drawable.c

diff --git a/tests/all.tests b/tests/all.tests
index 0248164..c18ef99 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -607,6 +607,9 @@ add_plain_test(glx, 'glx-window-life')
 glx['glx-window-life'].runConcurrent = True
 add_plain_test(glx, 'glx-pixmap-crosscheck')
 glx['glx-pixmap-crosscheck'].runConcurrent = True
+glx['glx-query-drawable-GLX_WIDTH'] = PlainExecTest(['glx-query-drawable', '-auto', '--attr=GLX_WIDTH'])
+glx['glx-query-drawable-GLX_HEIGHT'] = PlainExecTest(['glx-query-drawable', '-auto', '--attr=GLX_HEIGHT'])
+glx['glx-query-drawable-GLXBadDrawable'] = PlainExecTest(['glx-query-drawable', '-auto', '--bad-drawable'])
 
 texturing = Group()
 add_plain_test(texturing, 'array-texture')
diff --git a/tests/glx/CMakeLists.gl.txt b/tests/glx/CMakeLists.gl.txt
index 4560ef0..4b04321 100644
--- a/tests/glx/CMakeLists.gl.txt
+++ b/tests/glx/CMakeLists.gl.txt
@@ -51,6 +51,7 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 	add_executable (glx-visuals-stencil glx-visuals-stencil.c)
 
 	add_executable (glx-copy-sub-buffer glx-copy-sub-buffer.c)
+	add_executable (glx-query-drawable glx-query-drawable.c)
 ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 
 # vim: ft=cmake:
diff --git a/tests/glx/glx-query-drawable.c b/tests/glx/glx-query-drawable.c
new file mode 100644
index 0000000..8eae623
--- /dev/null
+++ b/tests/glx/glx-query-drawable.c
@@ -0,0 +1,211 @@
+/*
+ * 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-query-drawable.c
+ *
+ * Test the behavior of glXQueryDrawable(). See GLX 1.4 spec, Section 3.3.6
+ * Querying Attributes.
+ *
+ * For usage information, see usage_error();
+ */
+
+#include "piglit-util.h"
+#include "piglit-glx-util.h"
+
+int piglit_width = 137;
+int piglit_height = 119;
+
+void
+usage_error()
+{
+   const char *message =
+	"usage:\n"
+	"    glx-query-drawable [-auto] --bad-drawable\n"
+	"        Call glXQueryDrawable(drawable=0) and expect that error\n"
+	"        GLXBadDrawableError is generated.\n"
+	"\n"
+	"    glx-query-drawable [-auto] --attr=GLX_WIDTH\n"
+	"    glx-query-drawable [-auto] --attr=GLX_HEIGHT\n"
+	"        Call glXQueryDrawable() with the given attribute.\n";
+	printf(message);
+	piglit_report_result(PIGLIT_FAIL);
+}
+
+/***************************************************************************/
+
+/**
+ * @name X Error Handlers
+ * @{
+ */
+
+bool found_error_glxbadwindow = false;
+
+static int
+expect_no_error(Display *display, XErrorEvent *error)
+{
+	static buf[256];
+	XGetErrorText(display, error->error_code, buf, 256);
+	fprintf(stderr, "error: unexpected X error: %s\n", buf);
+	piglit_report_result(PIGLIT_FAIL);
+	return 0;
+}
+
+static int
+expect_glxbadwindow(Display *display, XErrorEvent *error)
+{
+	if (piglit_glx_get_error(display, error) == GLXBadWindow) {
+		found_error_glxbadwindow = true;
+	} else {
+		static buf[256];
+		XGetErrorText(display, error->error_code, buf, 256);
+		fprintf(stderr, "error: unexpected X error: %s\n", buf);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+	return 0;
+}
+
+/***************************************************************************/
+
+/**
+ * @}
+ * @name Test Functions
+ * @{
+ */
+
+static void query_width(Display *display, GLXDrawable draw) {
+	unsigned int width = 0;
+
+	XSetErrorHandler(expect_no_error);
+	glXQueryDrawable(display, draw, GLX_WIDTH, &width);
+
+	/* Sync before checking width in order to catch X errors. */
+	XSync(display, 0);
+
+	if (width != piglit_width) {
+		fprintf(stderr,
+		        "error: width=%d but glXQueryDrawable returned %d\n",
+		        piglit_width, width);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	piglit_report_result(PIGLIT_PASS);
+}
+
+static void query_height(Display *display, GLXDrawable draw) {
+	unsigned int height = 0;
+
+	XSetErrorHandler(expect_no_error);
+	glXQueryDrawable(display, draw, GLX_HEIGHT, &height);
+
+	/* Sync before checking height in order to catch X errors. */
+	XSync(display, 0);
+
+	if (height != piglit_height) {
+		fprintf(stderr,
+		        "error: height=%d but glXQueryDrawable returned %d\n",
+		        piglit_height, height);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	piglit_report_result(PIGLIT_PASS);
+}
+
+
+static void query_bad_drawable(Display *display, GLXDrawable draw) {
+	unsigned int width;
+	(void) draw;
+
+	XSetErrorHandler(expect_glxbadwindow);
+	glXQueryDrawable(display, 0, GLX_WIDTH, &width);
+	XSync(display, 0);
+
+	if (!found_error_glxbadwindow) {
+		fprintf(stderr,
+		        "error: glXQueryDrawable(draw=0) did not generate "
+		        "GLXBadDrawable\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	piglit_report_result(PIGLIT_PASS);
+}
+
+/** @} */
+
+/***************************************************************************/
+
+static void
+parse_args(int argc, char **argv,
+           void (**test_func)(Display*, GLXDrawable))
+{
+	int i;
+
+	/* Count of parsed args, excluding -auto. */
+	int num_parsed_args = 0;
+
+	for (i = 1; i < argc; ++i) {
+		const char *arg = argv[i];
+		if (!strncmp(arg, "-auto", 5)) {
+			piglit_automatic = 1;
+		} else if (!strncmp(arg, "--bad-drawable", 14)) {
+			++num_parsed_args;
+			*test_func = query_bad_drawable;
+		} else if (!strncmp(arg, "--attr=GLX_WIDTH", 16)) {
+			++num_parsed_args;
+			*test_func = query_width;
+		} else if (!strncmp(arg, "--attr=GLX_HEIGHT", 17)) {
+			++num_parsed_args;
+			*test_func = query_height;
+		} else {
+		   /* Unrecognized argument. */
+		   usage_error();
+		}
+	}
+
+	if (num_parsed_args != 1) {
+	   usage_error();
+	}
+}
+
+int main(int argc, char **argv) {
+	Display *display;
+	XVisualInfo *visual;
+	Window window;
+	GLXContext ctx;
+	void (*test_func)(Display*, GLXDrawable);
+
+	parse_args(argc, argv, &test_func);
+
+	display = piglit_get_glx_display();
+	visual = piglit_get_glx_visual(display);
+	window = piglit_get_glx_window(display, visual);
+	ctx = piglit_get_glx_context(display, visual);
+	glXMakeCurrent(display, window, ctx);
+
+	/* Must initialize static variables of this function. */
+	piglit_glx_get_error(display, NULL);
+
+	test_func(display, window);
+
+	return 0;
+}
-- 
1.7.6.4



More information about the Piglit mailing list