[Piglit] [PATCH 1/4] shader_runner: support compile error/success commands

Jordan Justen jordan.l.justen at intel.com
Mon Mar 25 10:56:45 PDT 2013


'compile error' in the test section will make sure that all
shader sections failed to compile.

'compile success' in the test section will make sure that all
shader sections successfully compiled.

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 tests/shaders/shader_runner.c |   92 +++++++++++++++++++++++++++++------------
 1 file changed, 66 insertions(+), 26 deletions(-)

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index 78385af..6d3c1a4 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -97,9 +97,12 @@ const char *vertex_data_start = NULL;
 const char *vertex_data_end = NULL;
 GLuint prog;
 size_t num_vbo_rows = 0;
+int compile_count = 0;
+int first_compile_success = 0;
+int first_compile_failure = 0;
 bool link_ok = false;
 bool prog_in_use = false;
-GLchar *prog_err_info = NULL;
+GLchar *saved_err_info = NULL;
 
 enum states {
 	none = 0,
@@ -260,30 +263,32 @@ compile_glsl(GLenum target, bool release_text)
 	}
 
 	glCompileShader(shader);
+	compile_count++;
 
 	glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
 
-	if (!ok) {
-		GLchar *info;
-		GLint size;
-
-		glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &size);
-		info = malloc(size);
-
-		glGetShaderInfoLog(shader, size, NULL, info);
+	if (ok) {
+		if (first_compile_success == 0)
+			first_compile_success = compile_count;
+	} else {
+		if (first_compile_failure == 0) {
+			GLint size;
+			first_compile_failure = compile_count;
 
-		fprintf(stderr, "Failed to compile %s: %s\n",
-			target_to_short_name(target),
-			info);
+			glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &size);
+			saved_err_info = malloc(size);
 
-		free(info);
-		piglit_report_result(PIGLIT_FAIL);
+			glGetShaderInfoLog(shader, size, NULL, saved_err_info);
+		}
 	}
 
 	if (release_text) {
 		free(shader_string);
 	}
 
+	if (!ok)
+		return;
+
 	switch (target) {
 	case GL_VERTEX_SHADER:
 		vertex_shaders[num_vertex_shaders] = shader;
@@ -745,9 +750,10 @@ link_and_use_shaders(void)
 	GLenum err;
 	GLint ok;
 
-	if ((num_vertex_shaders == 0)
-	    && (num_fragment_shaders == 0)
-	    && (num_geometry_shaders == 0))
+	if (((num_vertex_shaders == 0)
+	      && (num_fragment_shaders == 0)
+	      && (num_geometry_shaders == 0))
+	    || (first_compile_failure > 0))
 		return;
 
 	prog = glCreateProgram();
@@ -800,9 +806,9 @@ link_and_use_shaders(void)
 		GLint size;
 
 		glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
-		prog_err_info = malloc(size);
+		saved_err_info = malloc(size);
 
-		glGetProgramInfoLog(prog, size, NULL, prog_err_info);
+		glGetProgramInfoLog(prog, size, NULL, saved_err_info);
 
 		return;
 	}
@@ -816,9 +822,9 @@ link_and_use_shaders(void)
 		GLint size;
 
 		glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
-		prog_err_info = malloc(size);
+		saved_err_info = malloc(size);
 
-		glGetProgramInfoLog(prog, size, NULL, prog_err_info);
+		glGetProgramInfoLog(prog, size, NULL, saved_err_info);
 	}
 }
 
@@ -1598,6 +1604,9 @@ setup_ubos()
 {
 	int i;
 
+	if (!prog_in_use)
+		return;
+
 	if (!piglit_is_extension_supported("GL_ARB_uniform_buffer_object") &&
 	    piglit_get_gl_version() < 31) {
 		return;
@@ -1623,13 +1632,38 @@ setup_ubos()
 }
 
 void
+all_compilations_must_succeed(void)
+{
+	
+	if (first_compile_failure > 0) {
+		fprintf(stderr, "Failed to compile shader #%d:\n%s\n",
+		                first_compile_failure,
+		                saved_err_info);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+}
+
+void
+all_compilations_must_fail(void)
+{
+	
+	if (first_compile_success > 0) {
+		fprintf(stderr, "Shader #%d compiled successfully, "
+		                "but an error was expected!\n",
+		                first_compile_success);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+}
+
+void
 program_must_be_in_use(void)
 {
+	all_compilations_must_succeed();
 	if (!link_ok) {
-		fprintf(stderr, "Failed to link:\n%s\n", prog_err_info);
+		fprintf(stderr, "Failed to link:\n%s\n", saved_err_info);
 		piglit_report_result(PIGLIT_FAIL);
 	} else if (!prog_in_use) {
-		fprintf(stderr, "Failed to use program: %s\n", prog_err_info);
+		fprintf(stderr, "Failed to use program: %s\n", saved_err_info);
 		piglit_report_result(PIGLIT_FAIL);
 	}
 
@@ -1641,7 +1675,7 @@ piglit_display(void)
 	const char *line;
 	bool pass = true;
 	GLbitfield clear_bits = 0;
-	bool link_error_expected = false;
+	bool link_error_allowed = false;
 
 	if (test_start == NULL)
 		return PIGLIT_PASS;
@@ -1885,13 +1919,19 @@ piglit_display(void)
 		} else if (string_match("parameter ", line)) {
 			set_parameter(line + strlen("parameter "));
 		} else if (string_match("link error", line)) {
-			link_error_expected = true;
+			link_error_allowed = true;
 			if (link_ok) {
 				printf("shader link error expected, but it was sucessful!\n");
 				piglit_report_result(PIGLIT_FAIL);
 			}
 		} else if (string_match("link success", line)) {
 			program_must_be_in_use();
+		} else if (string_match("compile error", line)) {
+			link_error_allowed = true;
+			all_compilations_must_fail();
+		} else if (string_match("compile success", line)) {
+			link_error_allowed = true;
+			all_compilations_must_succeed();
 		} else if ((line[0] != '\n') && (line[0] != '\0')
 			   && (line[0] != '#')) {
 			printf("unknown command \"%s\"", line);
@@ -1903,7 +1943,7 @@ piglit_display(void)
 			line++;
 	}
 
-	if (!link_ok && !link_error_expected) {
+	if (!link_ok && !link_error_allowed) {
 		program_must_be_in_use();
 	}
 
-- 
1.7.10.4



More information about the Piglit mailing list