[Piglit] [PATCH 2/3] arb_internalformat_query: Verify that glGetInternalformativ does over-run the buffer

Eric Anholt eric at anholt.net
Tue Dec 11 16:13:37 PST 2012


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?

> +	/* 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.

> +	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.

Also, worth checking that exactly NUM_SAMPLES values were actually
written at this point?

> +	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;
> +		}
> +	}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20121211/f102e848/attachment.pgp>


More information about the Piglit mailing list