[Piglit] [PATCH] Add test glsl-uniform-out-of-bounds-2.c

Eric Anholt eric at anholt.net
Mon Nov 26 11:27:29 PST 2012


Frank Henigman <fjhenigman at google.com> writes:
> diff --git a/tests/all.tests b/tests/all.tests
> index 36c5847..2cf1ef4 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -240,6 +240,7 @@ add_plain_test(shaders, 'glsl-novertexdata')
>  add_plain_test(shaders, 'glsl-preprocessor-comments')
>  add_plain_test(shaders, 'glsl-reload-source')
>  add_plain_test(shaders, 'glsl-uniform-out-of-bounds')
> +add_plain_test(shaders, 'glsl-uniform-out-of-bounds-2')

I think this could safely be a concurrent test.

> +static GLint prog;

Looks like this ought to live next to vs, fs declarations.

> +void
> +piglit_init(int argc, char **argv)
> +{
> +	GLint vs, fs;
> +	int i, j, k;
> +	bool pass = true;
> +	GLint numActiveUniform;

Generally we try to go for names_with_underscores.

> +	// for each array in shader
> +	for (k = 0; k < numActiveUniform; ++k) {
> +		GLchar name[99];
> +		GLint numActiveElements;
> +		GLenum type;
> +		int size;
> +		glGetActiveUniform(prog, k, ARRAY_SIZE(name), NULL,
> +						   &numActiveElements, &type, name);
> +		if (name[1] != 0)
> +			continue;
> +		if (name[0] == 'v')
> +			size = 4;
> +		else if (name[0] == 'm')
> +			size = 16;
> +		else
> +			continue;
> +		printf("array '%s' active elements %d\n", name, numActiveElements);
> +
> +		// for each index in array, plus some before and after
> +		for (i = -2; i < 6; ++i) {
> +			bool isActive = 0 <= i && i < numActiveElements;
> +			GLchar element[9];
> +			GLint loc;
> +			sprintf(element, "%s[%d]", name, i);
> +			loc = glGetUniformLocation(prog, element);
> +
> +			// check result of glGetUniformLocation
> +			if (loc == -1) {
> +				if (isActive) {
> +					printf("FAIL: no location for active %s\n", element);
> +					pass = false;
> +				}
> +			} else {
> +				if (!isActive) {
> +					printf("FAIL: got location for inactive %s\n", element);
> +					pass = false;
> +				}
> +
> +				// write location
> +				if (size == 4) {
> +					glUniform4fv(loc, 1, data);
> +				} else {
> +					glUniformMatrix4fv(loc, 1, GL_FALSE, data);
> +				}
> +				// read back
> +				for (j = 0; j < size; ++j)
> +					v[j] = 0;
> +				glGetUniformfv(prog, loc, v);
> +				// compare
> +				for (j = 0; j < size; ++j) {
> +					if (v[j] != data[j]) {
> +						printf("FAIL: wrong value in %s\n", element);
> +						pass = false;
> +						break;
> +					}
> +				}

Being able to round-trip data through the various components of a
uniform array/matrix seems like a very separate thing to test from
glsl-uniform-out-of-bounds-2.  This test would make a lot more sense to
me without it.  In that case, this loop would just be checking that
out-of-bounds stuff gets -1 location (a good thing to test), and
computing the bounds of the valid locations.

> +	// make up some bogus locations
> +	for (i = 1; i < 6; ++i) {
> +		bogus[nbogus++] = min - i;
> +		bogus[nbogus++] = max + i;
> +		bogus[nbogus++] = max + (1<<16) + i - 3;
> +	}

The last bogus location could use a comment pointing out that this is
white-box testing Mesa's implementation that uses 1 << 16 to
differentiate different uniform names, so poking at things at at that
offset from the max may trigger interesting bugs.
-------------- 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/20121126/02cbbb38/attachment.pgp>


More information about the Piglit mailing list