[Piglit] [PATCH] arb_shader_objects: Test some edge cases of glGetAttachedObjectARB

Ian Romanick idr at freedesktop.org
Fri Jan 22 11:56:21 PST 2016


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

NOTE: On builds of Mesa that include commit 739ac3d3, this test fails
with:

Testing glGetAttachedObjectsARB...
Unexpected GL error: GL_OUT_OF_MEMORY 0x505
(Error at tests/spec/arb_shader_objects/getattachedobjects.c:156)
Expected GL error: GL_INVALID_VALUE 0x501
Segmentation fault (core dumped)

I verified that the test passes with my distro Mesa:

OpenGL version string: 3.0 Mesa 11.1.0 (git-525f3c2)

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Cc: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
---
 tests/all.py                                       |   2 +
 tests/spec/arb_shader_objects/CMakeLists.gl.txt    |   1 +
 tests/spec/arb_shader_objects/getattachedobjects.c | 340 +++++++++++++++++++++
 3 files changed, 343 insertions(+)
 create mode 100644 tests/spec/arb_shader_objects/getattachedobjects.c

diff --git a/tests/all.py b/tests/all.py
index 8c5c8f9..6ce805f 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -2359,11 +2359,13 @@ with profile.group_manager(
       'bindattriblocation-scratch-name')
     g(['arb_shader_objects-getactiveuniform-beginend'],
       'getactiveuniform-beginend')
+    g(['arb_shader_objects-getattachedobjects'], 'getattachedobjects')
     g(['arb_shader_objects-getuniformlocation-array-of-struct-of-array'],
       'getuniformlocation-array-of-struct-of-array')
     g(['arb_shader_objects-clear-with-deleted'], 'clear-with-deleted')
     g(['arb_shader_objects-delete-repeat'], 'delete-repeat')
 
+
 with profile.group_manager(
         PiglitGLTest,
         grouptools.join('spec', 'ARB_shading_language_420pack')) as g:
diff --git a/tests/spec/arb_shader_objects/CMakeLists.gl.txt b/tests/spec/arb_shader_objects/CMakeLists.gl.txt
index b3bc22b..6c8b6b3 100644
--- a/tests/spec/arb_shader_objects/CMakeLists.gl.txt
+++ b/tests/spec/arb_shader_objects/CMakeLists.gl.txt
@@ -14,3 +14,4 @@ piglit_add_executable (arb_shader_objects-getuniform getuniform.c)
 piglit_add_executable (arb_shader_objects-getuniformlocation-array-of-struct-of-array getuniformlocation-array-of-struct-of-array.c)
 piglit_add_executable (arb_shader_objects-clear-with-deleted clear-with-deleted.c)
 piglit_add_executable (arb_shader_objects-delete-repeat delete-repeat.c)
+piglit_add_executable (arb_shader_objects-getattachedobjects getattachedobjects.c)
diff --git a/tests/spec/arb_shader_objects/getattachedobjects.c b/tests/spec/arb_shader_objects/getattachedobjects.c
new file mode 100644
index 0000000..a8280e7
--- /dev/null
+++ b/tests/spec/arb_shader_objects/getattachedobjects.c
@@ -0,0 +1,340 @@
+/*
+ * Copyright © 2016 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 getattachedobjects.c
+ * Verify some error cases around glGetAttachedObjectsARB
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const GLchar vertex_shader_text[] =
+	"void main() { gl_Position = vec4(0); }\n";
+
+static const GLchar fragment_shader_text[] =
+	"void main() { gl_FragColor = vec4(0); }\n";
+
+static bool
+validate_data_ARB(GLsizei count,
+		  GLsizei expected_count,
+		  const GLhandleARB *handles,
+		  const GLhandleARB *expected_handles,
+		  unsigned num_handles, const char *text)
+{
+	bool pass = true;
+	const size_t bytes = sizeof(GLhandleARB) * num_handles;
+
+	if (count != expected_count) {
+		printf("    glGetAttachedObjectsARB(%s) modified *count\n",
+		       text);
+		pass = false;
+	}
+
+	if (memcmp(handles, expected_handles, bytes) != 0) {
+		printf("    glGetAttachedObjectsARB(%s) modified *obj\n",
+		       text);
+		pass = false;
+	}
+
+	return pass;
+}
+
+static bool
+validate_data_20(GLsizei count,
+		 GLsizei expected_count,
+		 const GLuint *handles,
+		 const GLuint *expected_handles,
+		 unsigned num_handles, const char *text)
+{
+	bool pass = true;
+	const size_t bytes = sizeof(GLuint) * num_handles;
+
+	if (count != expected_count) {
+		printf("    glGetAttachedShaders(%s) modified *count\n",
+		       text);
+		pass = false;
+	}
+
+	if (memcmp(handles, expected_handles, bytes) != 0) {
+		printf("    glGetAttachedShaders(%s) modified *obj\n",
+		       text);
+		pass = false;
+	}
+
+	return pass;
+}
+
+static bool
+verify_glGetAttachedObjectsARB(GLenum target)
+{
+	GLhandleARB prog;
+	GLhandleARB shader;
+	const GLchar *const source = (target == GL_VERTEX_SHADER)
+		? vertex_shader_text : fragment_shader_text;
+	static const GLhandleARB expected_handles[8] = {
+		(GLhandleARB) 0xDEADBEEF, (GLhandleARB) 0xDEADBEEF,
+		(GLhandleARB) 0xDEADBEEF, (GLhandleARB) 0xDEADBEEF,
+		(GLhandleARB) 0xDEADBEEF, (GLhandleARB) 0xDEADBEEF,
+		(GLhandleARB) 0xDEADBEEF, (GLhandleARB) 0xDEADBEEF
+	};
+	GLhandleARB handles[ARRAY_SIZE(expected_handles)];
+	GLsizei count = 0xBADC0DE;
+	bool pass = true;
+
+	printf("Testing glGetAttachedObjectsARB...\n");
+
+	prog = glCreateProgramObjectARB();
+	if (prog == 0) {
+		printf("    Could not create program object.\n");
+		return false;
+	}
+
+	shader = glCreateShaderObjectARB(target);
+	if (shader == 0) {
+		printf("    Could not create shader object.\n");
+		return false;
+	}
+
+	glShaderSourceARB(shader, 1, &source, NULL);
+	glCompileShaderARB(shader);
+	glAttachObjectARB(prog, shader);
+
+	/*  The GL_ARB_shader_objects says:
+	 *
+	 *     "If an error occurred, the return parameters <count> and <obj>
+	 *     will be unmodified."
+	 *
+	 * The GL_ARB_shader_objects spec makes no mention of maxCount==0
+	 * being an error.  It's also somewhat unclear whether or not it
+	 * should set *count to zero.
+	 */
+	memcpy(handles, expected_handles, sizeof(expected_handles));
+	count = 0xBADC0DE;
+	glGetAttachedObjectsARB(prog, 0, &count, handles);
+
+	pass = validate_data_ARB(count, 0, handles, expected_handles,
+				 ARRAY_SIZE(handles), "maxCount==0")
+		&& pass;
+
+	/* Section 2.5 (GL Errors) of the OpenGL 1.5 spec says:
+	 *
+	 *     "Second, if a negative number is provided where an argument of
+	 *     type sizei is specified, the error INVALID_VALUE results."
+	 */
+	memcpy(handles, expected_handles, sizeof(expected_handles));
+	count = 0xBADC0DE;
+	glGetAttachedObjectsARB(prog, -1, &count, handles);
+
+	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
+
+	pass = validate_data_ARB(count, 0xBADC0DE, handles, expected_handles,
+				 ARRAY_SIZE(handles), "maxCount==-1")
+		&& pass;
+
+	/*  The GL_ARB_shader_objects says:
+	 *
+	 *     "If <count> is NULL then the GL ignores this parameter."
+	 */
+	memcpy(handles, expected_handles, sizeof(expected_handles));
+	count = 0xBADC0DE;
+	glGetAttachedObjectsARB(prog, ARRAY_SIZE(handles), NULL, handles);
+
+	if (handles[0] != shader) {
+		printf("    obj[0] is %p, expected %p\n",
+		       (void *)(intptr_t) handles[0],
+		       (void *)(intptr_t) shader);
+		pass = false;
+	}
+
+	handles[0] = expected_handles[0];
+	pass = validate_data_ARB(count, 0xBADC0DE, handles, expected_handles,
+				 ARRAY_SIZE(handles), "count==NULL")
+		&& pass;
+
+	/* Finally, try one last time with all the parameters set.
+	 */
+	memcpy(handles, expected_handles, sizeof(expected_handles));
+	count = 0xBADC0DE;
+	glGetAttachedObjectsARB(prog, ARRAY_SIZE(handles), &count, handles);
+
+	if (handles[0] != shader) {
+		printf("    obj[0] is %p, expected %p\n",
+		       (void *)(intptr_t) handles[0],
+		       (void *)(intptr_t) shader);
+		pass = false;
+	}
+
+	handles[0] = expected_handles[0];
+	pass = validate_data_ARB(count, 1, handles, expected_handles,
+				 ARRAY_SIZE(handles), "count==NULL")
+		&& pass;
+
+	return pass;
+}
+
+static bool
+verify_glGetAttachedShaders(GLenum target)
+{
+	GLuint prog;
+	GLuint shader;
+	const GLchar *const source = (target == GL_VERTEX_SHADER)
+		? vertex_shader_text : fragment_shader_text;
+	static const GLuint expected_handles[8] = {
+		0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF,
+		0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF
+	};
+	GLuint handles[ARRAY_SIZE(expected_handles)];
+	GLsizei count = 0xBADC0DE;
+	bool pass = true;
+
+	printf("Testing glGetAttachedShaders...\n");
+
+	prog = glCreateProgram();
+	if (prog == 0) {
+		printf("    Could not create program object.\n");
+		return false;
+	}
+
+	shader = glCreateShaderObjectARB(target);
+	if (shader == 0) {
+		printf("    Could not create shader object.\n");
+		return false;
+	}
+
+	glShaderSource(shader, 1, &source, NULL);
+	glCompileShader(shader);
+	glAttachShader(prog, shader);
+
+	/*  The GL_ARB_shader_objects says:
+	 *
+	 *     "If an error occurred, the return parameters <count> and <obj>
+	 *     will be unmodified."
+	 *
+	 * The GL_ARB_shader_objects spec makes no mention of maxCount==0
+	 * being an error.  It's also somewhat unclear whether or not it
+	 * should set *count to zero.
+	 */
+	memcpy(handles, expected_handles, sizeof(expected_handles));
+	count = 0xBADC0DE;
+	glGetAttachedShaders(prog, 0, &count, handles);
+
+	pass = validate_data_20(count, 0, handles, expected_handles,
+				ARRAY_SIZE(handles), "maxCount==0")
+		&& pass;
+
+	/* Section 2.5 (GL Errors) of the OpenGL 1.5 spec says:
+	 *
+	 *     "Second, if a negative number is provided where an argument of
+	 *     type sizei is specified, the error INVALID_VALUE results."
+	 */
+	memcpy(handles, expected_handles, sizeof(expected_handles));
+	count = 0xBADC0DE;
+	glGetAttachedShaders(prog, -1, &count, handles);
+
+	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
+
+	pass = validate_data_20(count, 0xBADC0DE, handles, expected_handles,
+				ARRAY_SIZE(handles), "maxCount==-1")
+		&& pass;
+
+	/*  The GL_ARB_shader_objects says:
+	 *
+	 *     "If <count> is NULL then the GL ignores this parameter."
+	 */
+	memcpy(handles, expected_handles, sizeof(expected_handles));
+	count = 0xBADC0DE;
+	glGetAttachedShaders(prog, ARRAY_SIZE(handles), NULL, handles);
+
+	if (handles[0] != shader) {
+		printf("    obj[0] is 0x%08x, expected 0x%08x\n",
+		       handles[0],
+		       shader);
+		pass = false;
+	}
+
+	handles[0] = expected_handles[0];
+	pass = validate_data_20(count, 0xBADC0DE, handles, expected_handles,
+				ARRAY_SIZE(handles), "count==NULL")
+		&& pass;
+
+	/* Finally, try one last time with all the parameters set.
+	 */
+	memcpy(handles, expected_handles, sizeof(expected_handles));
+	count = 0xBADC0DE;
+	glGetAttachedShaders(prog, ARRAY_SIZE(handles), &count, handles);
+
+	if (handles[0] != shader) {
+		printf("    obj[0] is 0x%08x, expected 0x%08x\n",
+		       handles[0],
+		       shader);
+		pass = false;
+	}
+
+	handles[0] = expected_handles[0];
+	pass = validate_data_20(count, 1, handles, expected_handles,
+				ARRAY_SIZE(handles), "count==NULL")
+		&& pass;
+
+	return pass;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	const unsigned version = piglit_get_gl_version();
+	const bool has_fragment_shader = version >= 20 ||
+		piglit_is_extension_supported("GL_ARB_fragment_shader");
+	const bool has_vertex_shader = version >= 20 ||
+		piglit_is_extension_supported("GL_ARB_vertex_shader");
+	const bool has_shaders = version >= 20 ||
+		(piglit_is_extension_supported("GL_ARB_shader_objects") &&
+		 (has_vertex_shader || has_fragment_shader));
+	const GLenum target = has_vertex_shader
+		? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER;
+	bool pass = true;
+
+	if (!has_shaders)
+		piglit_report_result(PIGLIT_SKIP);
+
+	if (piglit_is_extension_supported("GL_ARB_shader_objects"))
+		pass = verify_glGetAttachedObjectsARB(target) && pass;
+
+	if (version >= 20)
+		pass = verify_glGetAttachedShaders(GL_FRAGMENT_SHADER) && pass;
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_FAIL;
+}
-- 
2.5.0



More information about the Piglit mailing list