[Piglit] =?y?q?=5BPATCH=205/5=5D=20Add=20gles2parsertest=20to=20ease=20OpenGL=20ES=202=2E0=20test=20case=20development?=

Shuang He shuang.he at intel.com
Fri Oct 29 00:41:56 PDT 2010


---
 tests/CMakeLists.txt                    |    1 +
 tests/gles2parsertest/CMakeLists.txt    |   24 ++++
 tests/gles2parsertest/gles2parsertest.c |  192 +++++++++++++++++++++++++++++++
 3 files changed, 217 insertions(+), 0 deletions(-)
 create mode 100644 tests/gles2parsertest/CMakeLists.txt
 create mode 100644 tests/gles2parsertest/gles2parsertest.c

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 58f8070..0c936e9 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -15,6 +15,7 @@ IF(OPENGL_egl_LIBRARY)
 	add_subdirectory (egl)
 	IF(OPENGL_gles2_LIBRARY)
 		add_subdirectory (gles2)
+		add_subdirectory (gles2parsertest)
 	ENDIF(OPENGL_gles2_LIBRARY)
 ENDIF(OPENGL_egl_LIBRARY)
 
diff --git a/tests/gles2parsertest/CMakeLists.txt b/tests/gles2parsertest/CMakeLists.txt
new file mode 100644
index 0000000..4b34be8
--- /dev/null
+++ b/tests/gles2parsertest/CMakeLists.txt
@@ -0,0 +1,24 @@
+add_definitions ( -DSOURCE_DIR="${piglit_SOURCE_DIR}/" )
+
+include_directories(
+	${OPENGL_INCLUDE_PATH}
+	${piglit_SOURCE_DIR}/tests/util/
+	${piglit_SOURCE_DIR}/tests/util/eglut
+)
+
+link_directories (
+	${piglit_SOURCE_DIR}/tests/util/
+	${piglit_SOURCE_DIR}/tests/util/eglut
+)
+
+link_libraries (
+	${GLEW_glew_LIBRARY}
+	${OPENGLES_gles2_LIBRARY}
+	${OPENGL_egl_LIBRARY}
+	pigliteglut
+	piglitgles2util
+)
+
+
+add_executable (gles2parsertest gles2parsertest.c)
+target_link_libraries(gles2parsertest X11)
diff --git a/tests/gles2parsertest/gles2parsertest.c b/tests/gles2parsertest/gles2parsertest.c
new file mode 100644
index 0000000..a398d14
--- /dev/null
+++ b/tests/gles2parsertest/gles2parsertest.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright © 2009 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Shuang He <shuang.he at intel.com>
+ *
+ */
+
+/** @file glslparsertest.c
+ *
+ * Tests that compiling (but not linking or drawing with) a given
+ * shader either succeeds or fails as expected.
+ */
+
+#include <errno.h>
+#include <sys/stat.h>
+
+#include "piglit-egl-util.h"
+#include "eglut.h"
+#include <GLES2/gl2.h>
+
+#define WIN_WIDTH 200
+#define WIN_HEIGHT 100
+
+static char *filename;
+static int expected_pass;
+
+static void
+test(void)
+{
+	GLint prog;
+	GLint ok;
+	struct stat st;
+	int err;
+	GLchar *prog_string;
+	FILE *f;
+	FILE *out;
+	GLboolean pass;
+	GLchar *info;
+	GLint size;
+	GLenum type;
+
+	if (strcmp(filename + strlen(filename) - 4, "frag") == 0)
+		type = GL_FRAGMENT_SHADER;
+	else if (strcmp(filename + strlen(filename) - 4, "vert") == 0)
+		type = GL_VERTEX_SHADER;
+	else {
+		fprintf(stderr, "Couldn't determine type of program %s\n",
+			filename);
+		piglit_report_result(PIGLIT_FAILURE);
+		exit(1);
+	}
+
+	err = stat(filename, &st);
+	if (err == -1) {
+		fprintf(stderr, "Couldn't stat program %s: %s\n",
+			filename, strerror(errno));
+		exit(1);
+	}
+
+	prog_string = malloc(st.st_size + 1);
+	if (prog_string == NULL) {
+		fprintf(stderr, "malloc\n");
+		exit(1);
+	}
+
+	f = fopen(filename, "r");
+	if (f == NULL) {
+		fprintf(stderr, "Couldn't open program %s: %s\n",
+			filename, strerror(errno));
+		exit(1);
+	}
+	fread(prog_string, 1, st.st_size, f);
+	prog_string[st.st_size] = '\0';
+	fclose(f);
+
+	prog = glCreateShader(type);
+	glShaderSource(prog, 1, (const GLchar **)&prog_string, NULL);
+	glCompileShader(prog);
+	glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
+	pass = (expected_pass == (ok != 0));
+
+	if (pass)
+		out = stdout;
+	else
+		out = stderr;
+
+	glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
+	if (size != 0) {
+		info = malloc(size);
+		glGetShaderInfoLog(prog, size, NULL, info);
+	} else {
+		info = "(no compiler output)";
+	}
+
+	if (!ok) {
+		fprintf(out, "Failed to compile %s shader %s: %s\n",
+			type == GL_FRAGMENT_SHADER ? "fragment" : "vertex",
+			filename, info);
+		if (expected_pass) {
+			printf("Shader source:\n");
+			printf("%s\n", prog_string);
+		}
+	} else {
+		fprintf(out, "Successfully compiled %s shader %s: %s\n",
+			type == GL_FRAGMENT_SHADER ? "fragment" : "vertex",
+			filename, info);
+		if (!expected_pass) {
+			printf("Shader source:\n");
+			printf("%s\n", prog_string);
+		}
+	}
+
+	if (size != 0)
+		free(info);
+	free(prog_string);
+
+	glDeleteShader(prog);
+
+	piglit_report_result (pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
+}
+
+static void usage(char *name)
+{
+	printf("%s <filename.frag|filename.vert> <pass|fail> "
+	       "{minimum GLSL ES vesion}\n", name);
+	exit(1);
+}
+
+int main(int argc, char**argv)
+{
+	const char *essl_version_string;
+	float essl_version;
+	float minimum_version = 1.00;
+
+	eglutInit(argc, argv);
+	if ((argc != 3) && (argc != 4))
+		usage(argv[0]);
+
+	if (strlen(argv[1]) < 5)
+		usage(argv[0]);
+	filename = argv[1];
+
+	if (strcmp(argv[2], "pass") == 0)
+		expected_pass = 1;
+	else if (strcmp(argv[2], "fail") == 0)
+		expected_pass = 0;
+	else
+		usage(argv[0]);
+
+	if (argc > 3)
+		minimum_version = strtod(argv[3], NULL);
+
+	eglutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
+	eglutCreateWindow("gles2parsertest");
+
+	essl_version_string = (char *)
+		glGetString(GL_SHADING_LANGUAGE_VERSION);
+	essl_version = (essl_version_string == NULL)
+		? 0.0 : strtod(essl_version_string+18, NULL);
+
+	if (essl_version < minimum_version) {
+		fprintf(stderr,
+			"GLSL ES version is %f, but minimum version %f is required\n",
+			essl_version,
+			minimum_version);
+		piglit_report_result(PIGLIT_SKIP);
+	} else {
+		test();
+	}
+
+	return 0;
+}
-- 
1.7.2.3



More information about the Piglit mailing list