[Piglit] [PATCH 2/2] query_renderer: Add test that compares values from glXQueryRendererIntegerMESA et al

Ian Romanick idr at freedesktop.org
Fri Oct 25 20:13:54 CEST 2013


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

Verifies that all values from glXQueryRendererIntegerMESA,
glXQueryCurrentRendererIntegerMESA, glXQueryRendererStringMESA, and
glXQueryCurrentRendererStringMESA can be queried.  It also verifies that
each of the Current and non-Current versions returns the same value for
each query.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
This test currently fails on Mesa master with the
GLX_MESA_query_renderer patches on the mesa-dev list.  It appears that
Adam's d101204 commit breaks some calls to glXMakeContextCurrent.  I'm
tracking down the root cause of that problem now.  With that patch
reverted, everything here passes.

 tests/all.tests                                    |   4 +
 tests/spec/CMakeLists.txt                          |   1 +
 .../spec/glx_mesa_query_renderer/CMakeLists.gl.txt |  28 +++
 tests/spec/glx_mesa_query_renderer/CMakeLists.txt  |   1 +
 tests/spec/glx_mesa_query_renderer/coverage.c      | 275 +++++++++++++++++++++
 5 files changed, 309 insertions(+)
 create mode 100644 tests/spec/glx_mesa_query_renderer/CMakeLists.gl.txt
 create mode 100644 tests/spec/glx_mesa_query_renderer/CMakeLists.txt
 create mode 100644 tests/spec/glx_mesa_query_renderer/coverage.c

diff --git a/tests/all.tests b/tests/all.tests
index e5e63e4..1d2a916 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -468,6 +468,10 @@ oml_sync_control['swapbuffersmsc-return swap_interval 0'] = concurrent_test('glx
 oml_sync_control['swapbuffersmsc-return swap_interval 1'] = concurrent_test('glx-oml-sync-control-swapbuffersmsc-return 1')
 oml_sync_control['waitformsc'] = concurrent_test('glx-oml-sync-control-waitformsc')
 
+mesa_query_renderer = Group()
+glx['GLX_MESA_query_renderer'] = mesa_query_renderer
+mesa_query_renderer['coverage'] = concurrent_test('glx-query-renderer-coverage')
+
 def texwrap_test(args):
     test = PlainExecTest(['texwrap', '-fbo', '-auto'] + args)
     test.runConcurrent = True
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 18b846d..a2903d8 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -77,6 +77,7 @@ add_subdirectory (gles-2.0)
 add_subdirectory (gles-3.0)
 add_subdirectory (glx_arb_create_context)
 add_subdirectory (glx_ext_import_context)
+add_subdirectory (glx_mesa_query_renderer)
 add_subdirectory (glx_oml_sync_control)
 add_subdirectory (arb_vertex_type_2_10_10_10_rev)
 add_subdirectory (ext_texture_array)
diff --git a/tests/spec/glx_mesa_query_renderer/CMakeLists.gl.txt b/tests/spec/glx_mesa_query_renderer/CMakeLists.gl.txt
new file mode 100644
index 0000000..f51ceff
--- /dev/null
+++ b/tests/spec/glx_mesa_query_renderer/CMakeLists.gl.txt
@@ -0,0 +1,28 @@
+
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+if(PIGLIT_BUILD_GLX_TESTS)
+    link_libraries (
+        piglitglxutil
+    )
+endif(PIGLIT_BUILD_GLX_TESTS)
+
+link_libraries (
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+)
+
+IF(PIGLIT_BUILD_GLX_TESTS)
+	include_directories(
+		${GLPROTO_INCLUDE_DIRS}
+	)
+	link_libraries (
+		${X11_X11_LIB}
+	)
+	piglit_add_executable (glx-query-renderer-coverage coverage.c query-renderer-common.c)
+ENDIF(PIGLIT_BUILD_GLX_TESTS)
+
+# vim: ft=cmake:
diff --git a/tests/spec/glx_mesa_query_renderer/CMakeLists.txt b/tests/spec/glx_mesa_query_renderer/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/glx_mesa_query_renderer/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/glx_mesa_query_renderer/coverage.c b/tests/spec/glx_mesa_query_renderer/coverage.c
new file mode 100644
index 0000000..2f5367c
--- /dev/null
+++ b/tests/spec/glx_mesa_query_renderer/coverage.c
@@ -0,0 +1,275 @@
+/* Copyright © 2013 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 "piglit-util-gl-common.h"
+#include "piglit-glx-util.h"
+#include "query-renderer-common.h"
+
+struct test_vector {
+	const char *name_string;
+	int attribute;
+	int value_count;
+};
+
+#define ENUM(name, count) { # name, name, count }
+
+static const struct test_vector all_valid_integer_enums[] = {
+        ENUM(GLX_RENDERER_VENDOR_ID_MESA, 1),
+        ENUM(GLX_RENDERER_DEVICE_ID_MESA, 1),
+        ENUM(GLX_RENDERER_VERSION_MESA, 3),
+        ENUM(GLX_RENDERER_ACCELERATED_MESA, 1),
+        ENUM(GLX_RENDERER_VIDEO_MEMORY_MESA, 1),
+        ENUM(GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA, 1),
+        ENUM(GLX_RENDERER_PREFERRED_PROFILE_MESA, 1),
+        ENUM(GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA, 2),
+        ENUM(GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA, 2),
+        ENUM(GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA, 2),
+        ENUM(GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA, 2),
+};
+
+static const struct test_vector all_valid_string_enums[] = {
+        ENUM(GLX_RENDERER_VENDOR_ID_MESA, 0),
+        ENUM(GLX_RENDERER_DEVICE_ID_MESA, 0),
+};
+
+static bool
+verify_integer_values(const char *name, Bool success,
+		      const struct test_vector *test,
+		      const unsigned *buffer, unsigned buffer_size,
+		      bool silent)
+{
+	char text[512];
+	unsigned text_size;
+	bool pass = true;
+	unsigned j;
+
+	if (!success) {
+		fprintf(stderr, "%s(%s) failed.\n", name, test->name_string);
+
+		/* If the call failed, don't bother checking that the correct
+		 * number of values were written.
+		 */
+		return false;
+	}
+
+	if (!silent) {
+		text_size = snprintf(text, sizeof(text), "%s(%s) values:\n    ",
+				     name,
+				     test->name_string);
+		for (j = 0; j < test->value_count; j++) {
+			text_size += snprintf(&text[text_size],
+					      sizeof(text) - text_size,
+					      "%d ",
+					      buffer[j]);
+		}
+
+		printf("%s\n", text);
+	}
+
+	for (j = 0; j < test->value_count; j++) {
+		if (buffer[j] == 0xDEADBEEF) {
+			fprintf(stderr,
+				"%s(%s) only wrote %d values, expected %d.\n",
+				name,
+				test->name_string,
+				j + 1,
+				test->value_count);
+			pass = false;
+			break;
+		}
+	}
+
+	for (j = test->value_count; j < buffer_size; j++) {
+		if (buffer[j] != 0xDEADBEEF) {
+			fprintf(stderr,
+				"%s(%s) only wrote %d values, expected %d.\n",
+				name,
+				test->name_string,
+				j + 1,
+				test->value_count);
+			pass = false;
+			break;
+		}
+	}
+
+	return pass;
+}
+
+static bool
+subtest_QueryRendererInteger(Display *dpy)
+{
+	static const char subtest_name[] =
+		"glXQueryRendererIntegerMESA and "
+		"glXQueryCurrentRendererIntegerMESA";
+
+	bool pass = true;
+	unsigned i;
+
+	for (i = 0; i < ARRAY_SIZE(all_valid_integer_enums); i++) {
+		unsigned buffer_a[16];
+		unsigned buffer_b[ARRAY_SIZE(buffer_a)];
+		Bool success;
+		unsigned j;
+
+		for (j = 0; j < ARRAY_SIZE(buffer_a); j++) {
+			buffer_a[j] = 0xDEADBEEF;
+			buffer_b[j] = 0xDEADBEEF;
+		}
+
+		success =
+			glXQueryRendererIntegerMESA(dpy, 0, 0,
+						    all_valid_integer_enums[i].attribute,
+						    buffer_a);
+		pass = verify_integer_values("glXQueryRendererIntegerMESA",
+					     success,
+					     &all_valid_integer_enums[i],
+					     buffer_a,
+					     ARRAY_SIZE(buffer_a),
+					     false)
+			&& pass;
+
+		success =
+			glXQueryCurrentRendererIntegerMESA(
+						    all_valid_integer_enums[i].attribute,
+						    buffer_b);
+		pass = verify_integer_values("glXQueryCurrentRendererIntegerMESA",
+					     success,
+					     &all_valid_integer_enums[i],
+					     buffer_b,
+					     ARRAY_SIZE(buffer_b),
+					     true)
+			&& pass;
+
+		for (j = 0; j < all_valid_integer_enums[i].value_count; j++) {
+			if (buffer_a[j] != buffer_b[j]) {
+				fprintf(stderr,
+					"glXQueryRendererIntegerMESA and "
+					"glXQueryCurrentRendererIntegerMESA "
+					"disagree about %s value %d: "
+					"%d != %d\n",
+					all_valid_integer_enums[i].name_string,
+					j,
+					buffer_a[j],
+					buffer_b[j]);
+				pass = false;
+			}
+		}
+	}
+
+	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
+				     subtest_name);
+	return pass;
+}
+
+static bool
+subtest_QueryRendererString(Display *dpy)
+{
+	static const char subtest_name[] =
+		"glXQueryRendererStringMESA and "
+		"glXQueryCurrentRendererStringMESA";
+
+	bool pass = true;
+	unsigned i;
+
+	for (i = 0; i < ARRAY_SIZE(all_valid_string_enums); i++) {
+		const char *string_a;
+		const char *string_b;
+
+		string_a =
+			glXQueryRendererStringMESA(dpy, 0, 0,
+						   all_valid_string_enums[i].attribute);
+		if (string_a == NULL) {
+			fprintf(stderr,
+				"glXQueryRendererStringMESA(%s) failed.\n",
+				all_valid_string_enums[i].name_string);
+			pass = false;
+		} else {
+			printf("glXQueryRendererStringMESA(%s) value:\n"
+			       "    %s\n",
+			       all_valid_string_enums[i].name_string,
+			       string_a);
+		}
+
+		string_b = glXQueryCurrentRendererStringMESA(all_valid_string_enums[i].attribute);
+		if (string_b == NULL) {
+			fprintf(stderr,
+				"glXQueryRendererStringMESA(%s) failed.\n",
+				all_valid_string_enums[i].name_string);
+			pass = false;
+		}
+
+		if (string_a != NULL && string_b != NULL
+		    && strcmp(string_a, string_b) != 0) {
+			fprintf(stderr,
+				"glXQueryRendererIntegerMESA and "
+				"glXQueryCurrentRendererIntegerMESA "
+				"disagree about %s: %s != %s\n",
+				all_valid_string_enums[i].name_string,
+				string_a,
+				string_b);
+			pass = false;
+		}
+	}
+
+	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
+				     subtest_name);
+	return pass;
+}
+
+int main(int argc, char **argv)
+{
+	bool pass = true;
+	Display *dpy = NULL;
+	GLXFBConfig fbconfig = None;
+	XVisualInfo *visinfo = NULL;
+	Window win = None;
+	GLXWindow glxWin = None;
+	GLXContext ctx;
+
+	dpy = piglit_get_glx_display();
+
+	piglit_require_glx_version(dpy, 1, 4);
+
+	initialize_function_pointers(dpy);
+
+	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);
+
+	ctx = glXCreateNewContext(dpy, fbconfig, GLX_RGBA, NULL, True);
+	if (ctx == NULL) {
+		fprintf(stderr,	"Unable to create OpenGL context!\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+        glXMakeContextCurrent(dpy, glxWin, glxWin, ctx);
+        piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
+
+	pass = subtest_QueryRendererInteger(dpy) && pass;
+	pass = subtest_QueryRendererString(dpy) && pass;
+
+        glXMakeContextCurrent(dpy, 0, 0, 0);
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+	return 0;
+}
-- 
1.8.1.4



More information about the Piglit mailing list