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
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
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
41 static const GLenum valid_formats
[] = {
87 GLint num_sample_counts
;
90 size_t buffer_size_in_elements
;
91 size_t buffer_size_in_bytes
;
94 glGetInternalformativ(GL_RENDERBUFFER
,
97 1, &num_sample_counts
);
98 pass
= piglit_check_gl_error(0)
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
,
114 GL_NUM_SAMPLE_COUNTS
,
116 pass
= piglit_check_gl_error(0)
119 if (buffer
[0] != 0xDEADBEEF) {
122 "pname = GL_NUM_SAMPLE_COUNTS, bufSize = 0 "
123 "over-ran the buffer.\n");
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
,
137 buffer_size_in_elements
,
139 pass
= piglit_check_gl_error(0)
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
,
152 pass
= piglit_check_gl_error(0)
155 for (i
= 1; i
< buffer_size_in_elements
; i
++) {
156 if (buffer
[i
] != buffer_copy
[i
]) {
158 "pname = GL_SAMPLES, bufSize = 1 "
159 "over-ran the buffer at element %u.\n",
171 piglit_init(int argc
, char **argv
)
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
);