[Piglit] [PATCH 3/6] Add --check-link option to glslparsertest.
Paul Berry
stereotype441 at gmail.com
Sun Sep 4 11:34:30 PDT 2011
This option tells glslparsertest to treat link errors the same as
compile errors. For tests that expect a result of "pass", this causes
glslparsertest to verify that the shader both compiles and links
without error. For tests that expect a result of "fail", this causes
glslparsertest to treat a link-time error as passing the test, just as
it would a compile-time error.
---
framework/glsl_parser_test.py | 8 +++
tests/glslparsertest/glslparsertest.c | 88 +++++++++++++++++++++++----------
2 files changed, 70 insertions(+), 26 deletions(-)
diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 118df13..0d97986 100755
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -132,6 +132,10 @@ class GLSLParserTest(PlainExecTest):
* require_extensions: List of GL extensions. If an extension is not
supported, the test is skipped. Each extension name must begin
with GL and elements are separated by whitespace.
+ * check_link: Either ``true`` or ``false``. A true value passes the
+ --check-link option to be supplied to glslparsertest, which
+ causes it to detect link failures as well as compilation
+ failures.
Examples
--------
@@ -159,6 +163,7 @@ class GLSLParserTest(PlainExecTest):
[config]
glsl_version: 1.30
expect_result: pass
+ check_link: true
[end config]
*/
@@ -183,6 +188,7 @@ class GLSLParserTest(PlainExecTest):
__config_defaults = {
'require_extensions' : '',
+ 'check_link' : 'false',
}
def __init__(self, filepath, runConcurrent = True):
@@ -366,6 +372,8 @@ class GLSLParserTest(PlainExecTest):
self.config.get('config', 'expect_result'),
self.config.get('config', 'glsl_version')
]
+ if self.config.get('config', 'check_link').lower() == 'true':
+ command.append('--check-link')
command += self.config.get('config', 'require_extensions').split()
return command
diff --git a/tests/glslparsertest/glslparsertest.c b/tests/glslparsertest/glslparsertest.c
index a1c3913..bcd9407 100644
--- a/tests/glslparsertest/glslparsertest.c
+++ b/tests/glslparsertest/glslparsertest.c
@@ -42,6 +42,7 @@
static char *filename;
static int expected_pass;
static int gl_major_version = 0;
+static int check_link = 0;
static GLint
get_shader_compile_status(GLuint shader)
@@ -97,6 +98,7 @@ test(void)
GLchar *info;
GLint size;
GLenum type;
+ char *failing_stage = NULL;
if (strcmp(filename + strlen(filename) - 4, "frag") == 0)
type = GL_FRAGMENT_SHADER;
@@ -140,12 +142,6 @@ test(void)
piglit_ShaderSource(prog, 1, (const GLchar **)&prog_string, NULL);
piglit_CompileShader(prog);
ok = get_shader_compile_status(prog);
- pass = (expected_pass == ok);
-
- if (pass)
- out = stdout;
- else
- out = stderr;
size = get_shader_info_log_length(prog);
if (size != 0) {
@@ -156,7 +152,36 @@ test(void)
}
if (!ok) {
- fprintf(out, "Failed to compile %s shader %s: %s\n",
+ failing_stage = "compile";
+ } else {
+ /* Try linking the shader if it compiled. We do this
+ * even if --check-link wasn't specified, to increase
+ * coverage of linker code.
+ */
+ GLuint shader_prog;
+
+ shader_prog = piglit_CreateProgram();
+ piglit_AttachShader(shader_prog, prog);
+ piglit_LinkProgram(shader_prog);
+ if (check_link) {
+ ok = piglit_link_check_status_quiet(shader_prog);
+ if (!ok) {
+ failing_stage = "link";
+ }
+ }
+ piglit_DeleteProgram(shader_prog);
+ }
+
+ pass = (expected_pass == ok);
+
+ if (pass)
+ out = stdout;
+ else
+ out = stderr;
+
+ if (!ok) {
+ fprintf(out, "Failed to %s %s shader %s: %s\n",
+ failing_stage,
type == GL_FRAGMENT_SHADER ? "fragment" : "vertex",
filename, info);
if (expected_pass) {
@@ -164,7 +189,8 @@ test(void)
printf("%s\n", prog_string);
}
} else {
- fprintf(out, "Successfully compiled %s shader %s: %s\n",
+ fprintf(out, "Successfully %s %s shader %s: %s\n",
+ check_link ? "compiled and linked" : "compiled",
type == GL_FRAGMENT_SHADER ? "fragment" : "vertex",
filename, info);
if (!expected_pass) {
@@ -173,23 +199,6 @@ test(void)
}
}
- /* Try linking the shader if it compiled. We don't care about
- * the success or failure of linking for the purposes of
- * parser tests, we're just trying to increase coverage of
- * that code. It also means that drivers that do a compile at
- * link time (to determine limits) get a chance to expose
- * their codegen to the parser tests, even if we don't ever
- * execute it.
- */
- if (ok) {
- GLuint shader_prog;
-
- shader_prog = piglit_CreateProgram();
- piglit_AttachShader(shader_prog, prog);
- piglit_LinkProgram(shader_prog);
- piglit_DeleteProgram(shader_prog);
- }
-
if (size != 0)
free(info);
free(prog_string);
@@ -199,11 +208,37 @@ test(void)
static void usage(char *name)
{
- printf("%s <filename.frag|filename.vert> <pass|fail> "
+ printf("%s {options} <filename.frag|filename.vert> <pass|fail> "
"{requested GLSL vesion} {list of required GL extensions}\n", name);
+ printf("\nSupported options:\n");
+ printf(" --check-link: also detect link failures\n");
exit(1);
}
+/**
+ * Process any options and remove them from the argv array. Return
+ * the new argc.
+ */
+int process_options(int argc, char **argv)
+{
+ int i = 1;
+ int new_argc = 1;
+ while (i < argc) {
+ if (argv[i][0] == '-') {
+ if (strcmp(argv[i], "--check-link") == 0)
+ check_link = 1;
+ else
+ usage(argv[0]);
+ /* do not retain the option; we've processed it */
+ i++;
+ } else {
+ /* retain the option in the argv array */
+ argv[new_argc++] = argv[i++];
+ }
+ }
+ return new_argc;
+}
+
int main(int argc, char**argv)
{
const char *glsl_version_string;
@@ -212,6 +247,7 @@ int main(int argc, char**argv)
int i;
piglit_glutInit(argc, argv);
+ argc = process_options(argc, argv);
if (argc < 3)
usage(argv[0]);
--
1.7.6
More information about the Piglit
mailing list