summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2016-01-22 11:53:27 -0800
committerIan Romanick <ian.d.romanick@intel.com>2019-06-26 08:31:49 -0700
commitb6eae5a72246d4d635cb6b71decfd1e0b7284cc2 (patch)
tree1ead5df546bb009102b29ee7f9ff4f5a96e5d7cb
parent18641fceeb5e90a631b410e648cef90bf443619f (diff)
arb_shader_objects: Test some edge cases of glGetAttachedObjectARB
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@intel.com> Cc: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
-rw-r--r--tests/opengl.py1
-rw-r--r--tests/spec/arb_shader_objects/CMakeLists.gl.txt1
-rw-r--r--tests/spec/arb_shader_objects/getattachedobjects.c340
3 files changed, 342 insertions, 0 deletions
diff --git a/tests/opengl.py b/tests/opengl.py
index 30ce3335f..4c963a301 100644
--- a/tests/opengl.py
+++ b/tests/opengl.py
@@ -2317,6 +2317,7 @@ with profile.test_list.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')
diff --git a/tests/spec/arb_shader_objects/CMakeLists.gl.txt b/tests/spec/arb_shader_objects/CMakeLists.gl.txt
index b3bc22b15..6c8b6b34d 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 000000000..a8280e7f6
--- /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;
+}