[Piglit] [PATCH 02/25] util/shader: Define "nothrow" variant of piglit_compile_shader_text().

Francisco Jerez currojerez at riseup.net
Sun Oct 5 14:00:32 PDT 2014


Define a variant of piglit_compile_shader_text() that doesn't call
piglit_report_result() on failure killing the program, which is quite
annoying for tests that expect a compilation to fail and for tests
that are structured in a number of subtests, because a single sub-test
failing to compile a shader will prevent the remaining tests from
running.

I guess this would ideally be the default behavior of
piglit_compile_shader_text(), but with >300 callers in tree it seems
rather difficult to change at this stage.
---
 tests/util/piglit-shader.c | 20 ++++++++++++++++++--
 tests/util/piglit-shader.h |  1 +
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/tests/util/piglit-shader.c b/tests/util/piglit-shader.c
index e8fe9c4..37cc7cc 100644
--- a/tests/util/piglit-shader.c
+++ b/tests/util/piglit-shader.c
@@ -122,7 +122,7 @@ shader_name(GLenum target)
  * Convenience function to compile a GLSL shader.
  */
 GLuint
-piglit_compile_shader_text(GLenum target, const char *text)
+piglit_compile_shader_text_nothrow(GLenum target, const char *text)
 {
 	GLuint prog;
 	GLint ok;
@@ -149,7 +149,8 @@ piglit_compile_shader_text(GLenum target, const char *text)
 				info);
 
 			fprintf(stderr, "source:\n%s", text);
-			piglit_report_result(PIGLIT_FAIL);
+			glDeleteShader(prog);
+			prog = 0;
 		}
 		else if (0) {
 			/* Enable this to get extra compilation info.
@@ -164,6 +165,21 @@ piglit_compile_shader_text(GLenum target, const char *text)
 	return prog;
 }
 
+/**
+ * Convenience function to compile a GLSL shader.  Throws PIGLIT_FAIL
+ * on error terminating the program.
+ */
+GLuint
+piglit_compile_shader_text(GLenum target, const char *text)
+{
+        GLuint shader = piglit_compile_shader_text_nothrow(target, text);
+
+        if (!shader)
+                piglit_report_result(PIGLIT_FAIL);
+
+        return shader;
+}
+
 static GLboolean
 link_check_status(GLint prog, FILE *output)
 {
diff --git a/tests/util/piglit-shader.h b/tests/util/piglit-shader.h
index e2eef03..9208451 100644
--- a/tests/util/piglit-shader.h
+++ b/tests/util/piglit-shader.h
@@ -31,6 +31,7 @@
 void piglit_get_glsl_version(bool *es, int* major, int* minor);
 
 GLuint piglit_compile_shader(GLenum target, const char *filename);
+GLuint piglit_compile_shader_text_nothrow(GLenum target, const char *text);
 GLuint piglit_compile_shader_text(GLenum target, const char *text);
 GLboolean piglit_link_check_status(GLint prog);
 GLboolean piglit_link_check_status_quiet(GLint prog);
-- 
2.1.1



More information about the Piglit mailing list