[Piglit] [PATCH 2/3] glsl_parser_test.py: Add checks for duplicate keys

Dylan Baker baker.dylan.c at gmail.com
Tue Jun 24 16:54:16 PDT 2014


Recently some tests were discovered to have duplicate keys in the config
section of glsl parser tests, which resulted in undesirable behavior.
The config section is basically an ini file, which allows duplicate
sections, but only the last entry should be honored. Piglit doesn't
really want that behavior, instead treat duplicate sections as a bug and
raise an exception if they are detected

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/glsl_parser_test.py             | 16 +++++++++++++---
 framework/tests/glsl_parser_test_tests.py | 24 ++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 52b87f1..a71c167 100644
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -85,6 +85,15 @@ class GLSLParserTest(PiglitTest):
         text_io = StringIO()
         text_io.write('[config]\n')
 
+        def add_line(line):
+            """ Add line to the stringio, and validate the keys """
+            # Ensure that this is the only instance of this key
+            split = line.split(':')[0]
+            assert split not in found_keys, 'Duplicate key: "{0}"'.format(
+                split)
+            found_keys.add(split)
+            text_io.write(line)
+
         os.stat(filepath)
 
         # Parse the config file and get the config section, then write this
@@ -104,6 +113,7 @@ class GLSLParserTest(PiglitTest):
             else:
                 raise GLSLParserException("No [config] section found!")
 
+            found_keys = set()
             is_header = re.compile(r'\s*(//|/\*|\*)\s*\[end config\]')
             for line in lines:
                 # Remove all leading whitespace
@@ -120,11 +130,11 @@ class GLSLParserTest(PiglitTest):
                 # remove that and any newly revealed whitespace, then write
                 # it into the StringIO
                 elif line[:2] in ['//', '/*', '*/']:
-                    text_io.write(line[2:].lstrip() + '\n')
-                # If we have just * then we're in the middle of a C style
+                    add_line(line[2:].lstrip() + '\n')
                 # comment, do like above
                 elif line[:1] == '*':
-                    text_io.write(line[1:].lstrip() + '\n')
+                    add_line(line[1:].lstrip() + '\n')
+                # If we have just * then we're in the middle of a C style
                 else:
                     raise GLSLParserException(
                         "The config section is malformed."
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index 9794331..ebfa0ce 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -180,3 +180,27 @@ def test_glslparser_require_trailing_semicolon():
                 'require_extensions cannot be seperated with "," or ";"',
                 msg=("Exception not raised if ';' used to seperate"
                      "require_extensions"))
+
+
+ at nt.raises(AssertionError)
+def check_no_duplicates(content):
+    """ Ensure that duplicate entries raise an error """
+    _check_config(content)
+
+
+ at utils.nose_generator
+def test_duplicate_entries():
+    """ Generate tests for duplicate keys in the config block """
+    content = [
+        ('expect_result', '// expect_result: pass\n'),
+        ('glsl_version', '// glsl_version: 1.00\n'),
+        ('require_extensions', '// require_extensions: ARB_ham_sandwhich\n')
+    ]
+
+    for name, value in content:
+        check_no_duplicates.description = \
+            "duplicate values of {0} raise an exception".format(name)
+        test = '// [config]\n{0}{1}// [end config]'.format(
+            ''.join(x[1] for x in content), value)
+
+        yield check_no_duplicates, test
-- 
2.0.0



More information about the Piglit mailing list