[Piglit] [PATCH 2/3] arb_internalformat_query: Verify that glGetInternalformativ does over-run the buffer
Ian Romanick
idr at freedesktop.org
Tue Dec 11 18:06:06 PST 2012
On 12/11/2012 04:13 PM, Eric Anholt wrote:
> Ian Romanick <idr at freedesktop.org> writes:
>> +/**
>> + * \file overrun.c
>> + * Verify that queries don't over-run the size of the supplied buffer.
>> + */
>> +
>> +#include "piglit-util-gl-common.h"
>> +
>> +PIGLIT_GL_TEST_CONFIG_BEGIN
>> +
>> + config.supports_gl_compat_version = 10;
>> + config.window_visual = PIGLIT_GL_VISUAL_RGB;
>> +
>> +PIGLIT_GL_TEST_CONFIG_END
>> +
>> +/* These are all the formats that are required to be color-renderable by the
>> + * OpenGL 3.0 spec.
>> + */
>
> Require gl compat version of 30 in that case?
I can do that.
>> + /* Try GL_NUM_SAMPLE_COUNTS
>> + */
>> + buffer[0] = ~num_sample_counts;
>
> I'd prefer an explicit magic value like 0xd0d0d0d0. Yeah, the test
> wouldn't successfully test if there happened to be 0xd0d0d0d0 sample
> counts supported, but I think it's more obvious then what you're
> testing for.
Okay.
>> + glGetInternalformativ(GL_RENDERBUFFER,
>> + format,
>> + GL_NUM_SAMPLE_COUNTS,
>> + 0, buffer);
>> + pass = piglit_check_gl_error(0)
>> + && pass;
>> +
>> + if (buffer[0] != ~num_sample_counts) {
>> + pass = false;
>> + fprintf(stderr,
>> + "pname = GL_NUM_SAMPLE_COUNTS, bufSize = 0 "
>> + "over-ran the buffer.\n");
>> + }
>> +
>> + /* Try GL_SAMPLES
>> + */
>> + memset(buffer, 0x7e, buffer_size_in_bytes);
>> +
>> + glGetInternalformativ(GL_RENDERBUFFER,
>> + format,
>> + GL_SAMPLES,
>> + buffer_size_in_elements,
>> + buffer);
>> + pass = piglit_check_gl_error(0)
>> + && pass;
>> +
>> + for (i = 0; i < buffer_size_in_elements; i++) {
>> + buffer[i] = ~buffer[i];
>> + buffer_copy[i] = buffer[i];
>
> I'm confused, it looks like buffer_copy will have an inverted copy of
> the buffer data, but then we check an uninverted return value against
> it.
I call it once with the full size buffer. I smash the data in the
buffer. I call it again with a buffer size of 1. I verify that all of
the data after the first element is still the smashed data.
> Also, worth checking that exactly NUM_SAMPLES values were actually
> written at this point?
I think the api-errors test should catch most errors when not enough
data is written. The test pre-fills the buffer with zero, and zero is
an invalid value for the GL_SAMPLES query.
>> + glGetInternalformativ(GL_RENDERBUFFER,
>> + format,
>> + GL_SAMPLES,
>> + 1,
>> + buffer);
>> + pass = piglit_check_gl_error(0)
>> + && pass;
>> +
>> + for (i = 1; i < buffer_size_in_elements; i++) {
>> + if (buffer[i] != buffer_copy[i]) {
>> + fprintf(stderr,
>> + "pname = GL_SAMPLES, bufSize = 1 "
>> + "over-ran the buffer at element %u.\n",
>> + i);
>> + pass = false;
>> + }
>> + }
More information about the Piglit
mailing list