[Piglit] [PATCH 1/3] ARB_query_buffer_object: Add out of bound buffer access test

Rafal Mielniczuk rafal.mielniczuk2 at gmail.com
Wed Mar 19 14:29:07 PDT 2014


Test runs asynchronous query and tries to store the result
out of the bound of query buffer object to check if
GL_INVALID_OPERATION is generated correctly.

Signed-off-by: Rafal Mielniczuk <rafal.mielniczuk2 at gmail.com>
---
 tests/all.py                                       |   5 +
 tests/spec/CMakeLists.txt                          |   1 +
 .../spec/arb_query_buffer_object/CMakeLists.gl.txt |  14 +++
 tests/spec/arb_query_buffer_object/CMakeLists.txt  |   1 +
 .../query_buffer_object-out-of-bound.c             | 138 +++++++++++++++++++++
 5 files changed, 159 insertions(+)
 create mode 100644 tests/spec/arb_query_buffer_object/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_query_buffer_object/CMakeLists.txt
 create mode 100644 tests/spec/arb_query_buffer_object/query_buffer_object-out-of-bound.c

diff --git a/tests/all.py b/tests/all.py
index 6ce459d..f47b215 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -1865,6 +1865,11 @@ add_plain_test(arb_provoking_vertex, 'arb-provoking-vertex-initial')
 add_plain_test(arb_provoking_vertex, 'arb-quads-follow-provoking-vertex')
 add_plain_test(arb_provoking_vertex, 'arb-xfb-before-flatshading')
 
+# Group ARB_query_buffer_object
+arb_query_buffer_object = Group()
+spec['ARB_query_buffer_object'] = arb_query_buffer_object;
+add_plain_test(arb_query_buffer_object, 'arb_query_buffer_object-out-of-bound')
+
 # Group ARB_robustness
 arb_robustness = Group()
 spec['ARB_robustness'] = arb_robustness
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index eb3fd51..29ca77c 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -23,6 +23,7 @@ add_subdirectory (arb_multisample)
 add_subdirectory (arb_occlusion_query)
 add_subdirectory (arb_occlusion_query2)
 add_subdirectory (arb_provoking_vertex)
+add_subdirectory (arb_query_buffer_object)
 add_subdirectory (arb_robustness)
 add_subdirectory (arb_sample_shading)
 add_subdirectory (arb_sampler_objects)
diff --git a/tests/spec/arb_query_buffer_object/CMakeLists.gl.txt b/tests/spec/arb_query_buffer_object/CMakeLists.gl.txt
new file mode 100644
index 0000000..d007742
--- /dev/null
+++ b/tests/spec/arb_query_buffer_object/CMakeLists.gl.txt
@@ -0,0 +1,14 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+)
+
+piglit_add_executable (arb_query_buffer_object-out-of-bound query_buffer_object-out-of-bound.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_query_buffer_object/CMakeLists.txt b/tests/spec/arb_query_buffer_object/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_query_buffer_object/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_query_buffer_object/query_buffer_object-out-of-bound.c b/tests/spec/arb_query_buffer_object/query_buffer_object-out-of-bound.c
new file mode 100644
index 0000000..1c79a76
--- /dev/null
+++ b/tests/spec/arb_query_buffer_object/query_buffer_object-out-of-bound.c
@@ -0,0 +1,138 @@
+/**
+ * Copyright © 2014 Rafał Mielniczuk
+ *
+ * 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"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+
+	config.window_width = 180;
+	config.window_height = 100;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_DEPTH;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+#if !defined GL_QUERY_BUFFER
+#define GL_QUERY_BUFFER GL_QUERY_BUFFER_AMD
+#define GL_QUERY_BUFFER_BINDING GL_QUERY_BUFFER_BINDING_AMD
+#endif
+
+#define BUFFER_OFFSET(i) ((void*)NULL + (i))
+
+static void
+draw_box(float x, float y, float z, float w, float h)
+{
+	glBegin(GL_QUADS);
+	glVertex3f(x, y, z);
+	glVertex3f(x + w, y, z);
+	glVertex3f(x + w, y + h, z);
+	glVertex3f(x, y + h, z);
+	glEnd();
+}
+
+static int
+check_error(const char *func)
+{
+	if (piglit_check_gl_error(GL_INVALID_OPERATION)) {
+		return 1;
+	}
+
+	fprintf(stderr,
+		"Function %s did not generate expected "
+		"GL_INVALID_OPERATION error\n", func);
+
+	return 0;
+}
+
+static int
+do_test(void)
+{
+	GLuint queryBuffer;
+	GLuint queryId;
+	int passed = 1;
+
+	glClearColor(0.0, 0.2, 0.3, 0.0);
+	glClearDepth(1.0);
+	glEnable(GL_DEPTH_TEST);
+	glDepthFunc(GL_LESS);
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	glGenQueries(1, &queryId);
+	glGenBuffers(1, &queryBuffer);
+	/* Get query results to buffer object */
+	glBindBuffer(GL_QUERY_BUFFER, queryBuffer);
+	glBufferData(GL_QUERY_BUFFER, sizeof(GLuint64),
+		     NULL, GL_DYNAMIC_COPY);
+
+	glColor3ub(0xff, 0x00, 0x00);
+	draw_box(20.0f, 20.0f, 0.0f, 55.0f, 55.0f);
+
+	/* Generate some occlusion tests */
+	glBeginQuery(GL_SAMPLES_PASSED, queryId);
+		glColor3ub(0xff, 0xff, 0x00);
+		draw_box(10.0f, 10.0f, 0.3f, 75.0f, 75.0f);
+	glEndQuery(GL_SAMPLES_PASSED);
+
+	if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		fprintf(stderr, "Unexpected error detected "
+			"before calling glGetQueryObject{ui64v}\n");
+		return 0;
+	}
+
+	/* Try to access beyond buffer size to generate error */
+	glGetQueryObjectiv(queryId, GL_QUERY_RESULT, BUFFER_OFFSET(5));
+	passed &= check_error("glGetQueryObjectiv");
+
+	glGetQueryObjectuiv(queryId, GL_QUERY_RESULT, BUFFER_OFFSET(5));
+	passed &= check_error("glGetQueryObjectuiv");
+
+	glGetQueryObjecti64v(queryId, GL_QUERY_RESULT, BUFFER_OFFSET(5));
+	passed &= check_error("glGetQueryObjecti64v");
+
+	glGetQueryObjectui64v(queryId, GL_QUERY_RESULT, BUFFER_OFFSET(5));
+	passed &= check_error("glGetQueryObjectui64v");
+
+	return passed;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	int test_pass;
+
+	piglit_require_extension("GL_ARB_query_buffer_object");
+	piglit_require_extension("GL_ARB_occlusion_query");
+
+	test_pass = do_test();
+
+	piglit_report_result(test_pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_FAIL;
+}
-- 
1.9.0



More information about the Piglit mailing list