[Piglit] [PATCH v2 1/6] Add PIGLIT_STRIP_ARG() macro for extracting args during piglit config.

Paul Berry stereotype441 at gmail.com
Fri Aug 9 11:16:16 PDT 2013


v2: Fix update of *argc.
---
 tests/util/piglit-framework-gl.c | 19 +++++++++++++++++++
 tests/util/piglit-framework-gl.h |  8 ++++++++
 2 files changed, 27 insertions(+)

diff --git a/tests/util/piglit-framework-gl.c b/tests/util/piglit-framework-gl.c
index 46325eb..85dcac0 100644
--- a/tests/util/piglit-framework-gl.c
+++ b/tests/util/piglit-framework-gl.c
@@ -176,3 +176,22 @@ piglit_set_reshape_func(void (*func)(int w, int h))
 	if (!gl_fw->set_reshape_func)
 		gl_fw->set_reshape_func(gl_fw, func);
 }
+
+
+/**
+ * Search for an argument with the given name in the argument list.
+ * If it is found, remove it and return true.
+ */
+bool
+piglit_strip_arg(int *argc, char *argv[], const char *arg)
+{
+	int i;
+	for (i = 1; i < *argc; i++) {
+		if (!strcmp(argv[i], arg)) {
+			delete_arg(argv, *argc, i);
+			*argc -= 1;
+			return true;
+		}
+	}
+	return false;
+}
diff --git a/tests/util/piglit-framework-gl.h b/tests/util/piglit-framework-gl.h
index f8f73ad..57b6325 100644
--- a/tests/util/piglit-framework-gl.h
+++ b/tests/util/piglit-framework-gl.h
@@ -249,5 +249,13 @@ void piglit_present_results();
 void piglit_post_redisplay(void);
 void piglit_set_keyboard_func(void (*func)(unsigned char key, int x, int y));
 void piglit_set_reshape_func(void (*func)(int w, int h));
+bool piglit_strip_arg(int *argc, char *argv[], const char *arg);
+
+/**
+ * Convenience macro for invoking piglit_strip_arg() from within
+ * piglit_init() or between PIGLIT_GL_TEST_CONFIG_BEGIN and
+ * PIGLIT_GL_TEST_CONFIG_END.
+ */
+#define PIGLIT_STRIP_ARG(arg) piglit_strip_arg(&argc, argv, arg)
 
 #endif /* PIGLIT_FRAMEWORK_H */
-- 
1.8.3.4



More information about the Piglit mailing list