<div dir="ltr">On 21 August 2013 09:08, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_extra"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com" target="_blank">ian.d.romanick@intel.com</a>><br>
<br>
This test works with both GL_PROGRAM_BINARY_FORMATS (from<br>
ARB_get_program_binary) and GL_SHADER_BINARY_FORMATS (from<br>
ARB_ES2_compatibility). Mesa fails GL_SHADER_BINARY_FORMATS because it<br>
generates an error (!) for the queries. Fix the error causes it to<br>
over-run the buffer. I suspect the over-run will happen in an ES2 with<br>
Mesa as-is.<br>
<br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com" target="_blank">ian.d.romanick@intel.com</a>><br></blockquote><div><br></div><div>I'm not a fan of the one-word function names in this patch, especially "munge". How about something like:<br>
<br></div><div>munge -> fill_with_garbage<br></div><div>check -> check_overrun<br></div><div>try -> test_params<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
tests/all.tests | 7 +<br>
tests/spec/CMakeLists.txt | 1 +<br>
.../spec/arb_get_program_binary/CMakeLists.gl.txt | 14 ++<br>
tests/spec/arb_get_program_binary/CMakeLists.txt | 1 +<br>
tests/spec/arb_get_program_binary/overrun.c | 156 +++++++++++++++++++++<br>
5 files changed, 179 insertions(+)<br>
create mode 100644 tests/spec/arb_get_program_binary/CMakeLists.gl.txt<br>
create mode 100644 tests/spec/arb_get_program_binary/CMakeLists.txt<br>
create mode 100644 tests/spec/arb_get_program_binary/overrun.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index ab75f99..fa3812f 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -1031,6 +1031,13 @@ arb_es2_compatibility['FBO blit to missing attachment (ES2 completeness rules)']<br>
arb_es2_compatibility['FBO blit from missing attachment (ES2 completeness rules)'] = PlainExecTest(['fbo-missing-attachment-blit', '-auto', 'es2', 'from'])<br>
add_fbo_formats_tests('spec/ARB_ES2_compatibility', 'GL_ARB_ES2_compatibility')<br>
add_texwrap_format_tests(arb_es2_compatibility, 'GL_ARB_ES2_compatibility')<br>
+arb_es2_compatibility['NUM_SHADER_BINARY_FORMATS over-run check'] = concurrent_test('arb_get_program_binary-overrun shader')<br>
+<br>
+<br>
+# Group ARB_get_program_binary<br>
+arb_get_program_binary = Group()<br>
+spec['ARB_get_program_binary'] = arb_get_program_binary<br>
+arb_get_program_binary['NUM_PROGRAM_BINARY_FORMATS over-run check'] = concurrent_test('arb_get_program_binary-overrun program')<br>
<br>
arb_depth_clamp = Group()<br>
spec['ARB_depth_clamp'] = arb_depth_clamp<br>
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt<br>
index 77ed821..9016c9e 100644<br>
--- a/tests/spec/CMakeLists.txt<br>
+++ b/tests/spec/CMakeLists.txt<br>
@@ -7,6 +7,7 @@ add_subdirectory (arb_es2_compatibility)<br>
add_subdirectory (arb_framebuffer_object)<br>
add_subdirectory (arb_framebuffer_srgb)<br>
add_subdirectory (arb_geometry_shader4)<br>
+add_subdirectory (arb_get_program_binary)<br>
add_subdirectory (arb_instanced_arrays)<br>
add_subdirectory (arb_internalformat_query)<br>
add_subdirectory (arb_map_buffer_alignment)<br>
diff --git a/tests/spec/arb_get_program_binary/CMakeLists.gl.txt b/tests/spec/arb_get_program_binary/CMakeLists.gl.txt<br>
new file mode 100644<br>
index 0000000..be52044<br>
--- /dev/null<br>
+++ b/tests/spec/arb_get_program_binary/CMakeLists.gl.txt<br>
@@ -0,0 +1,14 @@<br>
+include_directories(<br>
+ ${GLEXT_INCLUDE_DIR}<br>
+ ${OPENGL_INCLUDE_PATH}<br>
+)<br>
+<br>
+link_libraries (<br>
+ piglitutil_${piglit_target_api}<br>
+ ${OPENGL_gl_LIBRARY}<br>
+ ${OPENGL_glu_LIBRARY}<br>
+)<br>
+<br>
+piglit_add_executable (arb_get_program_binary-overrun overrun.c)<br>
+<br>
+# vim: ft=cmake:<br>
diff --git a/tests/spec/arb_get_program_binary/CMakeLists.txt b/tests/spec/arb_get_program_binary/CMakeLists.txt<br>
new file mode 100644<br>
index 0000000..144a306<br>
--- /dev/null<br>
+++ b/tests/spec/arb_get_program_binary/CMakeLists.txt<br>
@@ -0,0 +1 @@<br>
+piglit_include_target_api()<br>
diff --git a/tests/spec/arb_get_program_binary/overrun.c b/tests/spec/arb_get_program_binary/overrun.c<br>
new file mode 100644<br>
index 0000000..8416677<br>
--- /dev/null<br>
+++ b/tests/spec/arb_get_program_binary/overrun.c<br>
@@ -0,0 +1,156 @@<br>
+/*<br>
+ * Copyright © 2012 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+/**<br>
+ * \file overrun.c<br>
+ * Verify that queries don't over-run the size of the supplied buffer.<br>
+ */<br>
+<br>
+#include "piglit-util-gl-common.h"<br>
+#include <stdlib.h><br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+ config.supports_gl_compat_version = 10;<br>
+ config.window_visual = PIGLIT_GL_VISUAL_RGB;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+ return PIGLIT_FAIL;<br>
+}<br>
+<br>
+/**<br>
+ * Fill the real buffer and the scratch buffer with the same set of<br>
+ * garbage data.<br>
+ */<br>
+static void<br>
+munge(void *buffer, void *buffer_scratch, size_t buffer_size_in_bytes) <br></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+{<br>
+ unsigned i;<br>
+ uint32_t *scratch = (uint32_t *) buffer;<br>
+<br>
+ assert(buffer_size_in_bytes % sizeof(uint32_t) == 0);<br>
+ for (i = 0; i < (buffer_size_in_bytes / sizeof(uint32_t)); i++)<br>
+ do {<br>
+ scratch[i] = rand();<br></blockquote><div><br></div><div>In my experience, tests that rely on rand() are generally a bad idea because they can lead to inconsistent results from one run to the next due to concidences. I realize that's unlikely with this test, but I would feel much more comfortable if we would just fill the buffer with a recognizable bit pattern (e.g. 0xcc) rather than random data.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ } while (scratch[i] == 0);<br>
+<br>
+ memcpy(buffer_scratch, buffer, buffer_size_in_bytes);<br>
+}<br>
+<br>
+static bool<br>
+check(const void *buffer, const void *buffer_scratch,<br>
+ size_t buffer_size_in_bytes, size_t data_size_in_bytes,<br>
+ const char *getter_name, const char *enum_name)<br>
+{<br>
+ if (memcmp(buffer + data_size_in_bytes,<br>
+ buffer_scratch + data_size_in_bytes,<br>
+ buffer_size_in_bytes - data_size_in_bytes) == 0)<br>
+ return true;<br>
+<br>
+ fprintf(stderr, "%s(%s) over-ran the buffer\n",<br>
+ getter_name, enum_name);<br>
+ return false;<br>
+}<br>
+<br>
+static bool<br>
+try(GLenum pname1, GLenum pname2)<br></blockquote><div><br></div><div>This function would be a lot easier to read if we renamed pname1 and pname2 to reflect how they are used, e.g.:<br><br></div><div>pname1 -> num_binary_formats_enum<br>
pname2 -> binary_formats_enum<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+{<br>
+ bool pass = true;<br>
+ GLint count = 0;<br>
+ char *buffer;<br>
+ char *buffer_scratch;<br>
+ unsigned buffer_size_in_elements;<br>
+ size_t buffer_size_in_bytes;<br>
+<br>
+<br>
+ glGetIntegerv(pname1, &count);<br>
+<br>
+ if (!piglit_check_gl_error(0))<br>
+ return false;<br>
+<br>
+ if (count < 0) {<br>
+ fprintf(stderr, "%s returned %d\n",<br>
+ piglit_get_gl_enum_name(pname1),<br>
+ count);<br>
+ return false;<br>
+ }<br>
+<br>
+ /* Both of the queries can return zero, so make sure that at least one<br>
+ * element is allocated. We need to check that when the first query<br>
+ * returns zero, the second query doesn't write any data.<br>
+ */<br>
+ buffer_size_in_elements = (count + 1) * 2;<br>
+ buffer_size_in_bytes = buffer_size_in_elements * sizeof(GLint64);<br>
+ buffer = malloc(buffer_size_in_bytes);<br>
+ buffer_scratch = malloc(buffer_size_in_bytes);<br>
+<br>
+#define TEST_CASE(fn, type) \<br>
+ do { \<br>
+ munge(buffer, buffer_scratch, buffer_size_in_bytes); \<br>
+ fn (pname2, (type *) buffer); \<br>
+ pass = piglit_check_gl_error(0) && pass; \<br>
+ pass = check(buffer, buffer_scratch, \<br>
+ buffer_size_in_bytes, \<br>
+ sizeof(type) * count, \<br>
+ # fn, \<br>
+ piglit_get_gl_enum_name(pname2)) \<br>
+ && pass; \<br>
+ } while (0)<br>
+<br>
+ TEST_CASE(glGetBooleanv, GLboolean);<br>
+ TEST_CASE(glGetIntegerv, GLint);<br>
+ TEST_CASE(glGetInteger64v, GLint64);<br>
+ TEST_CASE(glGetFloatv, GLfloat);<br>
+ TEST_CASE(glGetDoublev, GLdouble);<br>
+<br>
+ free(buffer);<br>
+ free(buffer_scratch);<br>
+ return pass;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+ bool pass = true;<br>
+<br>
+ if (argc == 1) {<br>
+ fprintf(stderr, "Usage: %s [shader|program]\n", argv[0]);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ if (strcmp(argv[1], "shader") == 0) {<br>
+ piglit_require_extension("GL_ARB_ES2_compatibility");<br>
+ pass = try(GL_NUM_SHADER_BINARY_FORMATS,<br>
+ GL_SHADER_BINARY_FORMATS);<br>
+ } else {<br>
+ piglit_require_extension("GL_ARB_get_program_binary");<br>
+ pass = try(GL_NUM_PROGRAM_BINARY_FORMATS,<br>
+ GL_PROGRAM_BINARY_FORMATS);<br>
+ }<br>
+<br>
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);<br>
+}<br>
<span><font color="#888888">--<br>
1.8.1.4<br></font></span></blockquote><div><br></div><div>With those changes, the patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br></div></div></div>
</div>