[Piglit] [Patch v2 9/9] glsl_parser_test.py: Only allow [A-Za-z0-9_\. ]+ in config values

Dylan Baker baker.dylan.c at gmail.com
Fri Jul 11 08:14:22 PDT 2014


This restricts all keys to this set of values, it is a little lax in
some cases, but represents the lowest common denominator for all of the
keys. This should help to limit the number of errors from authors
creating tests.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/glsl_parser_test.py             | 13 +++++-
 framework/tests/glsl_parser_test_tests.py | 72 +++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 5c0461e..e220682 100644
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -152,7 +152,8 @@ class GLSLParserTest(PiglitTest):
 
         is_header = re.compile(r'(//|/\*|\*)\s*\[end config\]')
         is_metadata = re.compile(
-            r'(//|/\*|\*)\s*(?P<key>[a-z_]*)\:\s(?P<value>[A-Za-z0-9._ ]*)')
+            r'(//|/\*|\*)\s*(?P<key>[a-z_]*)\:\s(?P<value>.*)')
+        bad_values = re.compile(r'(?![\w\. ]).*')
 
         for line in lines:
             # If strip renendered '' that means we had a blank newline,
@@ -176,6 +177,16 @@ class GLSLParserTest(PiglitTest):
                     raise GLSLParserException(
                         'Duplicate entry for key {}'.format(match.group('key')))
                 else:
+                    bad = bad_values.search(match.group('value'))
+                    # XXX: this always seems to return a match object, even
+                    # when the match is ''
+                    if bad.group():
+                        raise GLSLParserException(
+                            'Bad character "{0}" in file: "{1}", '
+                            'line: "{2}". Only alphanumerics, _, and space '
+                            'are allowed'.format(
+                                bad.group()[0], filepath, line))
+
                     # Otherwise add the key to the set of found keys, and add
                     # it to the dictionary that will be returned
                     self.__found_keys.add(match.group('key'))
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index 987ed9e..32b2cd0 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -237,3 +237,75 @@ def test_duplicate_entries():
             ''.join(x[1] for x in content), value)
 
         yield check_no_duplicates, test, name
+
+
+def check_bad_character(tfile):
+    """ Check for bad characters """
+    with nt.assert_raises(glsl.GLSLParserException) as e:
+        glsl.GLSLParserTest(tfile)
+
+        # Obviously this isn't a perfect check, but it should be close enough
+        if not e.exception.message.startswith('Bad character "'):
+            raise AssertionError(e.exception)
+
+
+ at utils.nose_generator
+def glslparser_exetensions_seperators():
+    """ GlslParserTest() can only have [A-Za-z_] as characters
+
+    This test generates a number of tests that should catch the majority of
+    errors relating to seperating extensions in the config block of a
+    glslparser test
+
+    """
+    problems = [
+        ('comma seperator', '// require_extensions: ARB_ham, ARB_turkey\n'),
+        ('semi-colon seperator', '// require_extensions: ARB_ham; ARB_turkey\n'),
+        ('trailing semi-colon', '// require_extensions: ARB_ham ARB_turkey\n;'),
+        ('Non-alpha character', '// require_extensions: ARB_$$$\n'),
+    ]
+
+    content = ('// [config]\n'
+               '// expect_result: pass\n'
+               '// glsl_version: 1.00\n'
+               '{}'
+               '// [end config]\n')
+
+    for name, value in problems:
+        test = content.format(value)
+        with utils.with_tempfile(test) as tfile:
+            check_bad_character.description = (
+                'require_extensions: {0} should raise an error'.format(name))
+            yield check_bad_character, tfile
+
+
+def check_good_extension(file_, desc):
+    """ A good extension should not raise a GLSLParserException """
+    try:
+        glsl.GLSLParserTest(file_)
+    except glsl.GLSLParserException:
+        nt.ok_(False,
+               'GLSLParserException was raised by "required_extensions: {}"'
+               ', but should not'.format(desc))
+
+
+ at utils.nose_generator
+def test_good_extensions():
+    """ Generates tests with good extensions which shouldn't raise errors """
+    content = ('// [config]\n'
+               '// expect_result: pass\n'
+               '// glsl_version: 1.00\n'
+               '// require_extensions: {}\n'
+               '// [end config]\n')
+    options = [
+        'GL_EXT_texture_array',
+        'GL_EXT_texture_array ARB_example',
+    ]
+
+    for x in options:
+        test = content.format(x)
+        check_good_extension.description = \
+            'require_extension {} is valid'.format(x)
+
+        with utils.with_tempfile(test) as tfile:
+            yield check_good_extension, tfile, x
-- 
2.0.0



More information about the Piglit mailing list