commit da93767346ee206eee9e22c99377cdc41869c388 Author: Gordon Jin Date: Fri Feb 25 10:27:58 2011 +0800 add shader test glsl-link-global-init diff --git a/tests/all.tests b/tests/all.tests index 072208f..642fec5 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -729,6 +729,7 @@ add_shader_generic(shaders, 'glsl-link-varyings-1') add_shader_generic(shaders, 'glsl-link-varyings-2') add_shader_generic(shaders, 'glsl-link-varyings-3') add_shader_generic(shaders, 'glsl-link-varying-TexCoord') +add_shader_generic(shaders, 'glsl-link-global-init') add_shader_generic(shaders, 'glsl-override-builtin') add_shader_generic(shaders, 'glsl-override-builtin-2') add_plain_test(shaders, 'glsl-kwin-blur-1') diff --git a/tests/shaders/CMakeLists.txt b/tests/shaders/CMakeLists.txt index 27a7806..80f8fe6 100644 --- a/tests/shaders/CMakeLists.txt +++ b/tests/shaders/CMakeLists.txt @@ -121,6 +121,7 @@ add_executable (glsl-link-initializer-06 glsl-link-initializer-06.c) add_executable (glsl-link-invariant-01 glsl-link-invariant-01.c) add_executable (glsl-link-centroid-01 glsl-link-centroid-01.c) add_executable (glsl-link-struct-array glsl-link-struct-array.c) +add_executable (glsl-link-global-init glsl-link-global-init.c) add_executable (gpu_shader4_attribs gpu_shader4_attribs.c) add_executable (vp-address-01 vp-address-01.c) add_executable (vp-address-02 vp-address-02.c) diff --git a/tests/shaders/glsl-link-global-init-a.vert b/tests/shaders/glsl-link-global-init-a.vert new file mode 100644 index 0000000..f8dc990 --- /dev/null +++ b/tests/shaders/glsl-link-global-init-a.vert @@ -0,0 +1,7 @@ +float f = 0.1; +void myfunc(); +void main() +{ + myfunc(); + gl_Position = gl_Vertex; +} diff --git a/tests/shaders/glsl-link-global-init-b.vert b/tests/shaders/glsl-link-global-init-b.vert new file mode 100644 index 0000000..a1f4d3b --- /dev/null +++ b/tests/shaders/glsl-link-global-init-b.vert @@ -0,0 +1,4 @@ +float f = 0.2; +void myfunc() +{ +} diff --git a/tests/shaders/glsl-link-global-init.c b/tests/shaders/glsl-link-global-init.c new file mode 100644 index 0000000..4cf1702 --- /dev/null +++ b/tests/shaders/glsl-link-global-init.c @@ -0,0 +1,106 @@ +/* + * 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 glsl-link-global-init.c + * + * Negative test for initializing a shared global in 2 shaders to different + * values. + * + * The test verifies that linking these 2 shaders together results in an error, + * according to GLSL 1.10 section 4.2: + * All initializers for a shared global must have the same value, or a link + * error will result. + * + * \author Gordon Jin + */ + +#include "piglit-util.h" + +int piglit_width = 100, piglit_height = 100; +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; + +enum piglit_result +piglit_display(void) +{ + return PIGLIT_FAILURE; +} + +/** + * Don't use piglit_link_check_status because it will log a message to stderr + * when the link fails. Since this test wants the link to fail, logging an + * error message will cause the test to be listed as "warn" instead of "pass". + */ +GLboolean +link_check_status(GLint prog) +{ + GLint ok; + + glGetProgramiv(prog, GL_LINK_STATUS, &ok); + if (!ok) { + GLchar *info; + GLint size; + + glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size); + info = malloc(size); + + glGetProgramInfoLog(prog, size, NULL, info); + printf("Failed to link: %s\n", info); + + free(info); + } + + return ok; +} + +void piglit_init(int argc, char **argv) +{ + GLint vert[2]; + GLint prog; + GLboolean ok; + + if (!GLEW_VERSION_2_0) { + printf("Requires OpenGL 2.0\n"); + piglit_report_result(PIGLIT_SKIP); + } + + vert[0] = + piglit_compile_shader(GL_VERTEX_SHADER, + "shaders/glsl-link-global-init-a.vert"); + vert[1] = + piglit_compile_shader(GL_VERTEX_SHADER, + "shaders/glsl-link-global-init-b.vert"); + prog = glCreateProgram(); + glAttachShader(prog, vert[0]); + glAttachShader(prog, vert[1]); + glLinkProgram(prog); + + ok = link_check_status(prog); + if (ok) + fprintf(stderr, + "Program should have failed linking, but " + "it was (incorrectly) successful.\n"); + + piglit_report_result((!ok) ? PIGLIT_SUCCESS : PIGLIT_FAILURE); +} +