glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / arb_compute_shader / api_errors.c
blob0a6daf46e0b1838ae3829d5ba05ad8d7e0ae1721
1 /*
2 * Copyright © 2014 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
21 * DEALINGS IN THE SOFTWARE.
24 /** \file
26 * Test cases in which the ARB_compute_shader API is expected to
27 * generate an error.
30 #include "piglit-util-gl.h"
31 #include "piglit-shader.h"
34 static struct piglit_gl_test_config *piglit_config;
37 PIGLIT_GL_TEST_CONFIG_BEGIN
38 piglit_config = &config;
39 config.supports_gl_compat_version = 33;
40 config.supports_gl_core_version = 33;
41 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
42 PIGLIT_GL_TEST_CONFIG_END
45 static const char *trivial_correct_shader =
46 "#version 330\n"
47 "#extension GL_ARB_compute_shader: enable\n"
48 "\n"
49 "layout(local_size_x = 1) in;\n"
50 "\n"
51 "void main()\n"
52 "{\n"
53 "}\n";
56 static const char *trivial_link_fail_shader =
57 "#version 330\n"
58 "#extension GL_ARB_compute_shader: enable\n"
59 "\n"
60 "void main()\n"
61 "{\n"
62 "}\n";
65 static const char *trivial_vertex_shader =
66 "#version 330\n"
67 "\n"
68 "void main()\n"
69 "{\n"
70 " gl_Position = vec4(0.0);\n"
71 "}\n";
74 static enum piglit_result
75 query_work_group_size_expect_error(GLint prog)
77 const GLint orig_query_result[3] = { 1234, 2345, 3456 };
78 GLint query_result[3];
79 int i;
81 for (i = 0; i < 3; i++)
82 query_result[i] = orig_query_result[i];
84 glGetProgramiv(prog, GL_COMPUTE_WORK_GROUP_SIZE, query_result);
86 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
87 return PIGLIT_FAIL;
88 for (i = 0; i < 3; i++) {
89 if (query_result[i] != orig_query_result[i]) {
90 printf("Error was generated, but query returned a "
91 "result anyway.");
92 return PIGLIT_FAIL;
95 return PIGLIT_PASS;
99 static enum piglit_result
100 query_work_group_size_unlinked(void *data)
102 /* From the ARB_compute_shader spec, in the description of the
103 * COMPUTE_WORK_GROUP_SIZE query:
105 * If <program> is the name of a program that has not been
106 * successfully linked, or is the name of a linked program
107 * object that contains no compute shaders, then an
108 * INVALID_OPERATION error is generated.
110 * In this test, we use an unlinked program.
112 GLint prog = piglit_build_simple_program_unlinked_multiple_shaders(
113 GL_COMPUTE_SHADER, trivial_correct_shader, 0);
114 return query_work_group_size_expect_error(prog);
118 static enum piglit_result
119 query_work_group_size_link_fail(void *data)
121 /* From the ARB_compute_shader spec, in the description of the
122 * COMPUTE_WORK_GROUP_SIZE query:
124 * If <program> is the name of a program that has not been
125 * successfully linked, or is the name of a linked program
126 * object that contains no compute shaders, then an
127 * INVALID_OPERATION error is generated.
129 * In this test, we use a program that fails to link.
131 GLint ok;
132 GLint prog = piglit_build_simple_program_unlinked_multiple_shaders(
133 GL_COMPUTE_SHADER, trivial_link_fail_shader, 0);
134 glLinkProgram(prog);
135 glGetProgramiv(prog, GL_LINK_STATUS, &ok);
136 if (ok) {
137 printf("Expected link failure, got link success\n");
138 return PIGLIT_FAIL;
140 if (!piglit_check_gl_error(GL_NO_ERROR))
141 return PIGLIT_FAIL;
143 return query_work_group_size_expect_error(prog);
147 static enum piglit_result
148 query_work_group_size_no_compute(void *data)
150 /* From the ARB_compute_shader spec, in the description of the
151 * COMPUTE_WORK_GROUP_SIZE query:
153 * If <program> is the name of a program that has not been
154 * successfully linked, or is the name of a linked program
155 * object that contains no compute shaders, then an
156 * INVALID_OPERATION error is generated.
158 * In this test, we use a program that has no compute shaders.
160 GLint prog = piglit_build_simple_program_multiple_shaders(
161 GL_VERTEX_SHADER, trivial_vertex_shader, 0);
162 return query_work_group_size_expect_error(prog);
166 static const struct piglit_subtest subtests[] = {
168 "Query COMPUTE_WORK_GROUP_SIZE on unlinked program",
169 "query-work-group-size-unlinked",
170 query_work_group_size_unlinked,
171 NULL
174 "Query COMPUTE_WORK_GROUP_SIZE on program that failed to link",
175 "query-work-group-size-link-fail",
176 query_work_group_size_link_fail,
177 NULL
180 "Query COMPUTE_WORK_GROUP_SIZE on program without compute shaders",
181 "query-work-group-size-no-compute",
182 query_work_group_size_no_compute,
183 NULL
186 NULL,
187 NULL,
188 NULL,
189 NULL
194 enum piglit_result
195 piglit_display(void)
197 return PIGLIT_FAIL;
201 void
202 piglit_init(int argc, char **argv)
204 enum piglit_result result;
206 piglit_require_extension("GL_ARB_compute_shader");
207 result = piglit_run_selected_subtests(subtests,
208 piglit_config->selected_subtests,
209 piglit_config->num_selected_subtests,
210 PIGLIT_SKIP);
211 piglit_report_result(result);