[Piglit] [PATCH 01/13 v2] glsl: Refactor some code out of shader_runner.c

Ian Romanick idr at freedesktop.org
Mon Aug 26 19:16:13 PDT 2013


From: Ian Romanick <ian.d.romanick at intel.com>

These functions will be used in another file soon.

v2: Extract string_match (suggested by Eric) and strcpy_to_space as
well.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 tests/shaders/CMakeLists.gl.txt    |  2 +-
 tests/shaders/CMakeLists.gles2.txt |  2 +-
 tests/shaders/CMakeLists.gles3.txt |  2 +-
 tests/shaders/parser_utils.c       | 71 ++++++++++++++++++++++++++++++++++++++
 tests/shaders/parser_utils.h       | 29 ++++++++++++++++
 tests/shaders/shader_runner.c      | 47 +------------------------
 6 files changed, 104 insertions(+), 49 deletions(-)
 create mode 100644 tests/shaders/parser_utils.c
 create mode 100644 tests/shaders/parser_utils.h

diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt
index 5de5b95..f71d683 100644
--- a/tests/shaders/CMakeLists.gl.txt
+++ b/tests/shaders/CMakeLists.gl.txt
@@ -138,7 +138,7 @@ piglit_add_executable (glsl-mat-attribute glsl-mat-attribute.c)
 piglit_add_executable (glsl-max-varyings glsl-max-varyings.c)
 piglit_add_executable (glsl-useprogram-displaylist glsl-useprogram-displaylist.c)
 piglit_add_executable (glsl-routing glsl-routing.c)
-piglit_add_executable (shader_runner shader_runner.c)
+piglit_add_executable (shader_runner shader_runner.c parser_utils.c)
 piglit_add_executable (glsl-vs-point-size glsl-vs-point-size.c)
 piglit_add_executable (glsl-sin glsl-sin.c)
 IF (UNIX)
diff --git a/tests/shaders/CMakeLists.gles2.txt b/tests/shaders/CMakeLists.gles2.txt
index 2fde3e3..efb8373 100644
--- a/tests/shaders/CMakeLists.gles2.txt
+++ b/tests/shaders/CMakeLists.gles2.txt
@@ -2,6 +2,6 @@ link_libraries(
 	piglitutil_${piglit_target_api}
 )
 
-piglit_add_executable(shader_runner_gles2 shader_runner.c)
+piglit_add_executable(shader_runner_gles2 shader_runner.c parser_utils.c)
 
 # vim: ft=cmake:
diff --git a/tests/shaders/CMakeLists.gles3.txt b/tests/shaders/CMakeLists.gles3.txt
index f29c4fc..4e143ae 100644
--- a/tests/shaders/CMakeLists.gles3.txt
+++ b/tests/shaders/CMakeLists.gles3.txt
@@ -2,6 +2,6 @@ link_libraries(
 	piglitutil_${piglit_target_api}
 )
 
-piglit_add_executable(shader_runner_${piglit_target_api} shader_runner.c)
+piglit_add_executable(shader_runner_${piglit_target_api} shader_runner.c parser_utils.c)
 
 # vim: ft=cmake:
diff --git a/tests/shaders/parser_utils.c b/tests/shaders/parser_utils.c
new file mode 100644
index 0000000..e534a4c
--- /dev/null
+++ b/tests/shaders/parser_utils.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2010 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.
+ */
+#include <string.h>
+#include <ctype.h>
+#include "parser_utils.h"
+
+/**
+ * Skip over whitespace upto the end of line
+ */
+const char *
+eat_whitespace(const char *src)
+{
+	while (isspace((int) *src) && (*src != '\n'))
+		src++;
+
+	return src;
+}
+
+
+/**
+ * Skip over non-whitespace upto the end of line
+ */
+const char *
+eat_text(const char *src)
+{
+	while (!isspace((int) *src) && (*src != '\0'))
+		src++;
+
+	return src;
+}
+
+
+bool
+string_match(const char *string, const char *line)
+{
+	return (strncmp(string, line, strlen(string)) == 0);
+}
+
+
+/**
+ * Copy a string until either whitespace or the end of the string
+ */
+const char *
+strcpy_to_space(char *dst, const char *src)
+{
+	while (!isspace((int) *src) && (*src != '\0'))
+		*(dst++) = *(src++);
+
+	*dst = '\0';
+	return src;
+}
diff --git a/tests/shaders/parser_utils.h b/tests/shaders/parser_utils.h
new file mode 100644
index 0000000..538fa6b
--- /dev/null
+++ b/tests/shaders/parser_utils.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2010 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.
+ */
+
+#include <stdbool.h>
+
+const char *eat_whitespace(const char *src);
+const char *eat_text(const char *src);
+bool string_match(const char *string, const char *line);
+const char *strcpy_to_space(char *dst, const char *src);
diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index 492db06..5129105 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -35,6 +35,7 @@
 #include "piglit-vbo.h"
 
 #include "shader_runner_gles_workarounds.h"
+#include "parser_utils.h"
 
 static void
 get_required_versions(const char *script_name,
@@ -185,12 +186,6 @@ version_string(struct component_version *v)
 	return v->_string;
 }
 
-static GLboolean
-string_match(const char *string, const char *line)
-{
-	return (strncmp(string, line, strlen(string)) == 0);
-}
-
 
 const char *
 target_to_short_name(GLenum target)
@@ -326,46 +321,6 @@ compile_and_bind_program(GLenum target, const char *start, int len)
 }
 
 /**
- * Copy a string until either whitespace or the end of the string
- */
-const char *
-strcpy_to_space(char *dst, const char *src)
-{
-	while (!isspace((int) *src) && (*src != '\0'))
-		*(dst++) = *(src++);
-
-	*dst = '\0';
-	return src;
-}
-
-
-/**
- * Skip over whitespace upto the end of line
- */
-const char *
-eat_whitespace(const char *src)
-{
-	while (isspace((int) *src) && (*src != '\n'))
-		src++;
-
-	return src;
-}
-
-
-/**
- * Skip over non-whitespace upto the end of line
- */
-const char *
-eat_text(const char *src)
-{
-	while (!isspace((int) *src) && (*src != '\0'))
-		src++;
-
-	return src;
-}
-
-
-/**
  * Compare two values given a specified comparison operator
  */
 bool
-- 
1.8.1.4



More information about the Piglit mailing list