[Piglit] [PATCH 2/3] piglit gl: convert gl extension checking to use an array of strings

Jordan Justen jordan.l.justen at intel.com
Sat Sep 1 10:15:37 PDT 2012


This better matches the interface of glGetStringi, which should be used
for GL >= 3.0.

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 tests/util/piglit-util-gl-common.c |   55 ++++++++++++++++++++++++++++++++----
 tests/util/piglit-util.c           |   15 ++++++++++
 tests/util/piglit-util.h           |   12 ++++++++
 3 files changed, 77 insertions(+), 5 deletions(-)

diff --git a/tests/util/piglit-util-gl-common.c b/tests/util/piglit-util-gl-common.c
index b319197..f30a2fe 100644
--- a/tests/util/piglit-util-gl-common.c
+++ b/tests/util/piglit-util-gl-common.c
@@ -32,7 +32,7 @@
  * between glBegin and glEnd, and to avoid the inefficiency of
  * redundant glGetString queries.
  */
-static const char *gl_extensions = NULL;
+static const char **gl_extensions = NULL;
 
 bool piglit_is_gles()
 {
@@ -62,13 +62,58 @@ int piglit_get_gl_version()
 	return 10*major+minor;
 }
 
-bool piglit_is_extension_supported(const char *name)
+static const char** split_string(const char *string)
 {
-	if (gl_extensions == NULL) {
-		gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
+	char *split;
+	char **strings;
+	int offset, length, words, max_words;
+	bool was_in_word, in_word;
+
+	length = strlen(string);
+	max_words = length / 2;
+	strings = malloc ((sizeof(char*) * (max_words + 1)) +
+	                  (sizeof(char) * (length + 1)));
+	split = (char*) &strings[max_words + 1];
+	assert (strings != NULL);
+
+	for (words = 0, was_in_word = false, offset = 0;
+	     offset < length;
+	     offset++) {
+		char c = string[offset];
+		in_word = (c != 0) && !isspace(c);
+		if (!in_word) {
+			split[offset] = 0;
+		} else {
+			split[offset] = c;
+			if (!was_in_word) {
+				strings[words] = &split[offset];
+				words++;
+			}
+		}
+		was_in_word = in_word;
 	}
 
-	return piglit_is_extension_in_string(gl_extensions, name);
+	strings[words] = NULL;
+
+	return (const char**) strings;
+}
+
+static void initialize_piglit_extension_support(void)
+{
+	const char *gl_extensions_string;
+
+	if (gl_extensions != NULL) {
+		return;
+	}
+
+	gl_extensions_string = (const char *) glGetString(GL_EXTENSIONS);
+	gl_extensions = split_string(gl_extensions_string);
+}
+
+bool piglit_is_extension_supported(const char *name)
+{
+	initialize_piglit_extension_support();
+	return piglit_is_extension_in_array(gl_extensions, name);
 }
 
 void piglit_require_gl_version(int required_version_times_10)
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 891ae22..411d69c 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -101,6 +101,21 @@ int asprintf(char **strp, const char *fmt, ...)
 
 #endif /* _WIN32 */
 
+bool piglit_is_extension_in_array(const char **haystack, const char *needle)
+{
+	if (needle[0] == 0)
+		return false;
+
+	while (*haystack != NULL) {
+		if (strcmp(*haystack, needle) == 0) {
+			return true;
+		}
+		haystack++;
+	}
+
+	return false;
+}
+
 bool piglit_is_extension_in_string(const char *haystack, const char *needle)
 {
 	const unsigned needle_len = strlen(needle);
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 269a590..a66cb03 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -114,6 +114,18 @@ enum piglit_result {
  */
 bool piglit_is_extension_in_string(const char *haystack, const char *needle);
 
+/**
+ * Determine if an extension is listed in an extension string array
+ *
+ * \param haystack   Array of all extensions to be searched
+ * \param needle     Extension whose presens is to be detected
+ *
+ * \precondition \c haystack is not null
+ *
+ * \sa piglit_is_extension_supported, piglit_is_glx_extension_supported
+ */
+bool piglit_is_extension_in_array(const char **haystack, const char *needle);
+
 int FindLine(const char *program, int position);
 void piglit_merge_result(enum piglit_result *all, enum piglit_result subtest);
 void piglit_report_result(enum piglit_result result);
-- 
1.7.9.5



More information about the Piglit mailing list