framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / shaders / unsuccessful-relink.c
blobdbd6aa2cf751b8b7df7834e70f06260b02f84207
1 /*
2 * Copyright © 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * \file unsuccessful-relink.c
27 * Render using a program with a uniform. Modify the uniform and then
28 * do a relink that will fail. This shouldn’t affect the original
29 * program and it should render with the new uniform value.
31 * GLSL 4.6 spec section 7.3:
33 * “If a program object that is active for any shader stage is
34 * re-linked unsuccessfully, the link status will be set to FALSE,
35 * but any existing executables and associated state will remain part
36 * of the current rendering state until a subsequent call to
37 * UseProgram, UseProgramStages, or BindProgramPipeline removes them
38 * from use.”
41 #include "piglit-util-gl.h"
43 PIGLIT_GL_TEST_CONFIG_BEGIN
45 config.supports_gl_compat_version = 20;
46 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
48 PIGLIT_GL_TEST_CONFIG_END
50 static const char vs_source[] =
51 "attribute vec4 piglit_vertex;\n"
52 "void main()\n"
53 "{\n"
54 " gl_Position = piglit_vertex;\n"
55 "}\n";
57 static const char fs_source[] =
58 "uniform vec4 color;\n"
59 "void main()\n"
60 "{\n"
61 " gl_FragColor = color;\n"
62 "}\n";
64 static const float green[] = { 0.0f, 1.0f, 0.0f, 1.0f };
65 static const float purple[] = { 0.5f, 0.0f, 0.5f, 1.0f };
67 static bool
68 try_render(GLuint vertex_attrib,
69 const float *color)
71 struct vertex { float x, y; };
72 static const struct vertex verts[] = {
73 { -1, -1 }, { 1, -1 },
74 { -1, 1 }, { 1, 1 }
76 bool pass;
77 GLuint buf;
79 /* This isn’t using piglit_draw_rect because that tries to
80 * call glGetAttribLocation which won’t work on the unlinked
81 * program
84 glGenBuffers(1, &buf);
85 glBindBuffer(GL_ARRAY_BUFFER, buf);
86 glBufferData(GL_ARRAY_BUFFER, sizeof verts, verts, GL_STATIC_DRAW);
87 glVertexAttribPointer(vertex_attrib, 2, GL_FLOAT,
88 GL_FALSE, sizeof verts[0],
89 (void *) offsetof(struct vertex, x));
90 glEnableVertexAttribArray(vertex_attrib);
91 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
92 glBindBuffer(GL_ARRAY_BUFFER, 0);
93 glDeleteBuffers(1, &buf);
95 if (!piglit_check_gl_error(GL_NO_ERROR)) {
96 fprintf(stderr, "error while drawing\n");
97 piglit_report_result(PIGLIT_FAIL);
100 pass = piglit_probe_rect_rgb(0, 0,
101 piglit_width, piglit_height,
102 color);
103 if (!pass)
104 fprintf(stderr, "render failed\n");
106 return pass;
109 static void
110 unsuccessful_link(GLuint prog)
112 GLuint shader;
113 GLint status;
114 int i;
116 /* Add the fs shader again. This should cause a link error
117 * because there would be two main functions in the fragment
118 * stage. */
119 for (i = 0; i < 2; i++) {
120 shader = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
121 fs_source);
122 glAttachShader(prog, shader);
125 glLinkProgram(prog);
127 glGetProgramiv(prog, GL_LINK_STATUS, &status);
129 if (status) {
130 fprintf(stderr, "Broken shader unexpectedly linked\n");
131 piglit_report_result(PIGLIT_FAIL);
135 enum piglit_result
136 piglit_display(void)
138 bool pass = true;
139 GLuint prog;
140 GLint color_uniform;
141 GLint vertex_attrib;
142 void *dummy_data[2048];
143 int i;
145 glViewport(0, 0, piglit_width, piglit_height);
146 glClear(GL_COLOR_BUFFER_BIT);
148 prog = piglit_build_simple_program(vs_source, fs_source);
150 color_uniform = glGetUniformLocation(prog, "color");
152 if (color_uniform == -1) {
153 fprintf(stderr, "color uniform missing\n");
154 piglit_report_result(PIGLIT_FAIL);
157 vertex_attrib = glGetAttribLocation(prog, "piglit_vertex");
159 if (vertex_attrib == -1) {
160 fprintf(stderr, "piglit_vertex attrib missing\n");
161 piglit_report_result(PIGLIT_FAIL);
164 glUseProgram(prog);
166 glUniform4fv(color_uniform, 1, purple);
168 if (!try_render(vertex_attrib, purple))
169 pass = false;
171 glUniform4fv(color_uniform, 1, green);
173 unsuccessful_link(prog);
175 /* This test currently causes a use-after-free error in Mesa
176 * which causes sporadic failures. In order to increase the
177 * chances of making the test fail, we will do lots of little
178 * redundant allocations in the hope of overwriting the data
179 * previously allocated and freed by Mesa.
181 for (i = 0; i < ARRAY_SIZE(dummy_data); i++) {
182 dummy_data[i] = malloc(64);
183 memset(dummy_data[i], 0, 64);
185 for (i = 0; i < ARRAY_SIZE(dummy_data); i++)
186 free(dummy_data[i]);
188 if (!try_render(vertex_attrib, green))
189 pass = false;
191 piglit_present_results();
193 glDeleteProgram(prog);
195 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
198 void
199 piglit_init(int argc, char **argv)