<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt">Any feedback on this?  Thanks.<br><br><div class="gmail_quote">On Mon, Nov 5, 2012 at 2:39 PM, Frank Henigman <span dir="ltr"><<a href="mailto:fjhenigman@google.com" target="_blank">fjhenigman@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This test shows the problem fixed by my "add bounds checking for<br>
uniform array access" patch, sent to mesa-dev on Nov. 2.<br>
<br>
Check behavior of glGetUniformLocation, glGetUniform and glUniform(Matrix)<br>
when attempting to access non-existent array elements.<br>
---<br>
 tests/all.tests                              |    1 +<br>
 tests/shaders/CMakeLists.gl.txt              |    1 +<br>
 tests/shaders/glsl-uniform-out-of-bounds-2.c |  155 ++++++++++++++++++++++++++<br>
 3 files changed, 157 insertions(+), 0 deletions(-)<br>
 create mode 100644 tests/shaders/glsl-uniform-out-of-bounds-2.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 0a8a5aa..63bf1f6 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -240,6 +240,7 @@ add_plain_test(shaders, 'glsl-novertexdata')<br>
 add_plain_test(shaders, 'glsl-preprocessor-comments')<br>
 add_plain_test(shaders, 'glsl-reload-source')<br>
 add_plain_test(shaders, 'glsl-uniform-out-of-bounds')<br>
+add_plain_test(shaders, 'glsl-uniform-out-of-bounds-2')<br>
 add_plain_test(shaders, 'glsl-uniform-update')<br>
 add_plain_test(shaders, 'glsl-unused-varying')<br>
 add_plain_test(shaders, 'glsl-fs-bug25902')<br>
diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt<br>
index 6ac0230..93cbf7b 100644<br>
--- a/tests/shaders/CMakeLists.gl.txt<br>
+++ b/tests/shaders/CMakeLists.gl.txt<br>
@@ -66,6 +66,7 @@ piglit_add_executable (glsl-reload-source glsl-reload-source.c)<br>
 piglit_add_executable (glsl-unused-varying glsl-unused-varying.c)<br>
 piglit_add_executable (glsl-uniform-update glsl-uniform-update.c)<br>
 piglit_add_executable (glsl-uniform-out-of-bounds glsl-uniform-out-of-bounds.c)<br>
+piglit_add_executable (glsl-uniform-out-of-bounds-2 glsl-uniform-out-of-bounds-2.c)<br>
 piglit_add_executable (glsl-fs-bug25902 glsl-fs-bug25902.c)<br>
 piglit_add_executable (glsl-fs-color-matrix glsl-fs-color-matrix.c)<br>
 piglit_add_executable (glsl-fs-exp2 glsl-fs-exp2.c)<br>
diff --git a/tests/shaders/glsl-uniform-out-of-bounds-2.c b/tests/shaders/glsl-uniform-out-of-bounds-2.c<br>
new file mode 100644<br>
index 0000000..94a9f88<br>
--- /dev/null<br>
+++ b/tests/shaders/glsl-uniform-out-of-bounds-2.c<br>
@@ -0,0 +1,155 @@<br>
+/*<br>
+ * Copyright 2012 Google Inc.<br>
+ *<br>
+ * This library is free software; you can redistribute it and/or<br>
+ * modify it under the terms of the GNU Lesser General Public<br>
+ * License as published by the Free Software Foundation; either<br>
+ * version 2.1 of the License, or (at your option) any later version.<br>
+ *<br>
+ * This library is distributed in the hope that it will be useful,<br>
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
+ * Lesser General Public License for more details.<br>
+ *<br>
+ * You should have received a copy of the GNU Lesser General Public<br>
+ * License along with this library; if not, write to the Free Software<br>
+ * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA<br>
+ *<br>
+ * Authors:<br>
+ *   Frank Henigman <<a href="mailto:fjhenigman@google.com">fjhenigman@google.com</a>><br>
+ */<br>
+<br>
+#include "piglit-util-gl-common.h"<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+       config.supports_gl_compat_version = 10;<br>
+<br>
+       config.window_width = 100;<br>
+       config.window_height = 100;<br>
+       config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+static GLint prog;<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       /* unreached */<br>
+       return PIGLIT_FAIL;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       GLint vs, fs, len;<br>
+       GLchar name[99];<br>
+       int size;<br>
+       GLenum type;<br>
+       int i, j, activeIdx;<br>
+       enum piglit_result result = PIGLIT_PASS;<br>
+       GLint min = -1, max = -1;<br>
+       GLint numActive;<br>
+       GLfloat v[16];<br>
+<br>
+       piglit_require_gl_version(20);<br>
+<br>
+       vs = piglit_compile_shader_text(GL_VERTEX_SHADER,<br>
+               "attribute vec4 p;\n"<br>
+               "void main() { gl_Position = p; }\n"<br>
+       );<br>
+       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER,<br>
+               "uniform vec4 v[4];\n"<br>
+               "uniform mat4 m[4];\n"<br>
+               "void main() { gl_FragColor = v[1] + m[1][1]; }\n"<br>
+       );<br>
+<br>
+       prog = piglit_link_simple_program(vs, fs);<br>
+       glUseProgram(prog);<br>
+       glGetProgramiv(prog, GL_ACTIVE_UNIFORMS, &numActive);<br>
+       printf("num active %d\n", numActive);<br>
+<br>
+       for ( activeIdx = 0; activeIdx < numActive; ++activeIdx ) {<br>
+               glGetActiveUniform(prog, activeIdx, sizeof(name)/sizeof(name[0]), NULL, &len, &type, name);<br>
+               printf("name %s length %d\n", name, len);<br>
+               if (name[1] != 0) continue;<br>
+               if (name[0] == 'v') {<br>
+                       size = 4;<br>
+               } else if (name[0] == 'm' ) {<br>
+                       size = 16;<br>
+               } else {<br>
+                       continue;<br>
+               }<br>
+<br>
+               // try each location in array, plus some outside<br>
+               for ( i = -2; i < len + 2; ++i ) {<br>
+                       GLchar buf[9];<br>
+                       sprintf(buf, "%c[%d]", name[0], i);<br>
+                       GLint loc = glGetUniformLocation(prog, buf);<br>
+                       int isActive;<br>
+                       if (loc == -1) {<br>
+                               printf("no index %d\n", i);<br>
+                               isActive = 0;<br>
+                       } else {<br>
+                               isActive = 1;<br>
+                               if (min == -1 || loc < min) min = loc;<br>
+                               if (max == -1 || loc > max) max = loc;<br>
+<br>
+                               // write, read back, compare<br>
+                               for ( j = 0; j < 16; ++j ) v[j] = j + 11;<br>
+                               if (size == 4 ) {<br>
+                                       glUniform4fv(loc, 1, v);<br>
+                               } else {<br>
+                                       glUniformMatrix4fv(loc, 1, GL_FALSE, v);<br>
+                               }<br>
+                               glGetUniformfv(prog, loc, v);<br>
+                               for ( j = 0; j < size; ++j ) {<br>
+                                       if (v[j] != j + 11) {<br>
+                                               printf("FAIL: value at index %d\n", i);<br>
+                                               result = PIGLIT_FAIL;<br>
+                                               break;<br>
+                                       }<br>
+                               }<br>
+                       }<br>
+<br>
+                       // does glGetActiveUniform agree with glGetUniformLocation?<br>
+                       if (isActive ^ (0 <= i && i < len)) {<br>
+                               printf("FAIL: inconsistent reporting of active array elements\n");<br>
+                               result = PIGLIT_FAIL;<br>
+                       }<br>
+               }<br>
+       }<br>
+<br>
+       // make up some bogus locations<br>
+       GLint bogus[99];<br>
+       int nbogus = 0;<br>
+       for ( i = 1; i < 6; ++i ) {<br>
+               bogus[nbogus++] = min - i;<br>
+               bogus[nbogus++] = max + i;<br>
+               bogus[nbogus++] = max + (1<<16) + i - 3;<br>
+       }<br>
+<br>
+       // test bogus locations<br>
+       for ( i = 0; i < nbogus; ++i ) {<br>
+               if (bogus[i] == -1) continue;<br>
+               printf("try bogus location %d\n", bogus[i]);<br>
+               glUniform4fv(bogus[i], 1, v);<br>
+               if (glGetError() != GL_INVALID_OPERATION) {<br>
+                       printf("FAIL: wrote bogus location\n");<br>
+                       result = PIGLIT_FAIL;<br>
+               }<br>
+               glUniformMatrix4fv(bogus[i], 1, GL_FALSE, v);<br>
+               if (glGetError() != GL_INVALID_OPERATION) {<br>
+                       printf("FAIL: wrote bogus location (matrix)\n");<br>
+                       result = PIGLIT_FAIL;<br>
+               }<br>
+               glGetUniformfv(prog, bogus[i], v);<br>
+               if (glGetError() != GL_INVALID_OPERATION) {<br>
+                       printf("FAIL: read bogus location\n");<br>
+                       result = PIGLIT_FAIL;<br>
+               }<br>
+       }<br>
+<br>
+       piglit_report_result(result);<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.7.3<br>
<br>
</font></span></blockquote></div><br></div>