summaryrefslogtreecommitdiff
path: root/tests/glslparsertest
diff options
context:
space:
mode:
authorPaul Berry <stereotype441@gmail.com>2013-02-06 12:38:06 -0800
committerPaul Berry <stereotype441@gmail.com>2013-02-27 12:56:16 -0800
commit0247daa79fa9a93a95ba2cc3a219347631687eb5 (patch)
treee1a66c591fe550808540ec276f8646f4bc0a404e /tests/glslparsertest
parentee8e683c5de437f9758a44764899921e933414a4 (diff)
glslparsertest: Fix parsing of GL_SHADING_LANGUAGE_VERSION in GLES.
In desktop GL, glGetString(GL_SHADING_LANGUAGE_VERSION) returns a string that begins with the supported version number. But in GLES, the version number is preceded by the text "OpenGL ES GLSL ES ". This was causing glslparsertest to fail to parse the implementation's supported GLSL version, and that in turn caused parse_glsl_version() function to access uninitialized memory. This patch splits parse_glsl_version() into two functions: parse_glsl_version_number(), which parses the bare version number, and parse_glsl_version_string(), which expects the prefix "OpenGL ES GLSL ES " when compiled for GLES testing. Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Chad Versace <chad.versace@linux.intel.com> Reviewed-by: Tom Gall <tom.gall@linaro.org> v2: Use runtime detection of GLES vs desktop GL.
Diffstat (limited to 'tests/glslparsertest')
-rw-r--r--tests/glslparsertest/glslparsertest.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/tests/glslparsertest/glslparsertest.c b/tests/glslparsertest/glslparsertest.c
index 1fd75d12a..d1f934f71 100644
--- a/tests/glslparsertest/glslparsertest.c
+++ b/tests/glslparsertest/glslparsertest.c
@@ -35,12 +35,13 @@
#include "piglit-util-gl-common.h"
-static unsigned parse_glsl_version(const char *str);
+static unsigned parse_glsl_version_number(const char *str);
PIGLIT_GL_TEST_CONFIG_BEGIN
if (argc > 3) {
- const unsigned int int_version = parse_glsl_version(argv[3]);
+ const unsigned int int_version
+ = parse_glsl_version_number(argv[3]);
switch (int_version) {
case 100:
config.supports_gl_compat_version = 10;
@@ -336,7 +337,7 @@ int process_options(int argc, char **argv)
}
static unsigned
-parse_glsl_version(const char *str)
+parse_glsl_version_number(const char *str)
{
unsigned major;
unsigned minor;
@@ -345,6 +346,28 @@ parse_glsl_version(const char *str)
return (major * 100) + minor;
}
+
+static unsigned
+parse_glsl_version_string(const char *str)
+{
+ if (piglit_is_gles()) {
+ /* In GLSL ES, the string returned by
+ * glGetString(GL_SHADING_LANGUAGE_VERSION) is
+ * prefixed by some text. Verify that the expected
+ * text is there and skip it before calling
+ * parse_glsl_version_number().
+ */
+ const char *expected_prefix = "OpenGL ES GLSL ES ";
+ if (strncmp(str, expected_prefix,
+ strlen(expected_prefix)) != 0) {
+ printf("Ill-formed GLSL version string: %s\n", str);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ str += strlen(expected_prefix);
+ }
+ return parse_glsl_version_number(str);
+}
+
void
piglit_init(int argc, char**argv)
{
@@ -368,7 +391,7 @@ piglit_init(int argc, char**argv)
usage(argv[0]);
if (argc > 3)
- requested_version = parse_glsl_version(argv[3]);
+ requested_version = parse_glsl_version_number(argv[3]);
gl_version_times_10 = piglit_get_gl_version();
@@ -383,7 +406,7 @@ piglit_init(int argc, char**argv)
glGetString(GL_SHADING_LANGUAGE_VERSION);
if (glsl_version_string != NULL)
- glsl_version = parse_glsl_version(glsl_version_string);
+ glsl_version = parse_glsl_version_string(glsl_version_string);
if (requested_version == 100) {
piglit_require_extension("GL_ARB_ES2_compatibility");