ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_internalformat_query / overrun.c
blob4aec2896fb992b6b09ef259817af744723883e74
1 /*
2 * Copyright © 2012 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 overrun.c
26 * Verify that queries don't over-run the size of the supplied buffer.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config.supports_gl_compat_version = 30;
34 config.window_visual = PIGLIT_GL_VISUAL_RGB;
36 PIGLIT_GL_TEST_CONFIG_END
38 /* These are all the formats that are required to be color-renderable by the
39 * OpenGL 3.0 spec.
41 static const GLenum valid_formats[] = {
42 GL_RGBA32F,
43 GL_RGBA32I,
44 GL_RGBA32UI,
45 GL_RGBA16,
46 GL_RGBA16F,
47 GL_RGBA16I,
48 GL_RGBA16UI,
49 GL_RGBA8,
50 GL_RGBA8I,
51 GL_RGBA8UI,
52 GL_SRGB8_ALPHA8,
53 GL_R11F_G11F_B10F,
54 GL_RG32F,
55 GL_RG32I,
56 GL_RG32UI,
57 GL_RG16,
58 GL_RG16F,
59 GL_RG16I,
60 GL_RG16UI,
61 GL_RG8,
62 GL_RG8I,
63 GL_RG8UI,
64 GL_R32F,
65 GL_R32I,
66 GL_R32UI,
67 GL_R16,
68 GL_R16F,
69 GL_R16I,
70 GL_R16UI,
71 GL_R8,
72 GL_R8I,
73 GL_R8UI,
74 GL_ALPHA8,
77 enum piglit_result
78 piglit_display(void)
80 return PIGLIT_FAIL;
83 static bool
84 try(GLenum format)
86 bool pass = true;
87 GLint num_sample_counts;
88 GLint *buffer;
89 GLint *buffer_copy;
90 size_t buffer_size_in_elements;
91 size_t buffer_size_in_bytes;
92 unsigned i;
94 glGetInternalformativ(GL_RENDERBUFFER,
95 format,
96 GL_NUM_SAMPLE_COUNTS,
97 1, &num_sample_counts);
98 pass = piglit_check_gl_error(0)
99 && pass;
101 buffer_size_in_elements = num_sample_counts + 2;
102 buffer_size_in_bytes = buffer_size_in_elements * sizeof(GLint);
103 buffer = malloc(buffer_size_in_bytes);
104 buffer_copy = malloc(buffer_size_in_bytes);
106 /* Try GL_NUM_SAMPLE_COUNTS.
108 * It seems very unlikely that an implementation will support
109 * 0xDEADBEEF number sample counts.
111 buffer[0] = 0xDEADBEEF;
112 glGetInternalformativ(GL_RENDERBUFFER,
113 format,
114 GL_NUM_SAMPLE_COUNTS,
115 0, buffer);
116 pass = piglit_check_gl_error(0)
117 && pass;
119 if (buffer[0] != 0xDEADBEEF) {
120 pass = false;
121 fprintf(stderr,
122 "pname = GL_NUM_SAMPLE_COUNTS, bufSize = 0 "
123 "over-ran the buffer.\n");
126 /* Try GL_SAMPLES.
128 * Call it once with the full size buffer. Smash the data in the
129 * buffer. Call it again with a buffer size of 1. Verify that all of
130 * the data after the first element is still the smashed data.
132 memset(buffer, 0x7e, buffer_size_in_bytes);
134 glGetInternalformativ(GL_RENDERBUFFER,
135 format,
136 GL_SAMPLES,
137 buffer_size_in_elements,
138 buffer);
139 pass = piglit_check_gl_error(0)
140 && pass;
142 for (i = 0; i < buffer_size_in_elements; i++) {
143 buffer[i] = ~buffer[i];
144 buffer_copy[i] = buffer[i];
147 glGetInternalformativ(GL_RENDERBUFFER,
148 format,
149 GL_SAMPLES,
151 buffer);
152 pass = piglit_check_gl_error(0)
153 && pass;
155 for (i = 1; i < buffer_size_in_elements; i++) {
156 if (buffer[i] != buffer_copy[i]) {
157 fprintf(stderr,
158 "pname = GL_SAMPLES, bufSize = 1 "
159 "over-ran the buffer at element %u.\n",
161 pass = false;
165 free(buffer);
166 free(buffer_copy);
167 return pass;
170 void
171 piglit_init(int argc, char **argv)
173 bool pass = true;
174 unsigned i;
176 piglit_require_extension("GL_ARB_framebuffer_object");
177 piglit_require_extension("GL_ARB_internalformat_query");
179 for (i = 0; i < ARRAY_SIZE(valid_formats); i++) {
180 pass = try(valid_formats[i]) && pass;
183 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);