[Piglit] [PATCH v2 2/3] framework/test/glsl_parser_test.py: Handle gl versions correctly

baker.dylan.c at gmail.com baker.dylan.c at gmail.com
Mon Nov 9 15:35:17 PST 2015


From: Dylan Baker <baker.dylan.c at gmail.com>

This patch fixes the behavior of glsl_parser_test in cases other that
OpenGL and OpenGL ES are available. This means that if OpenGL ES isn't
available then OpenGL ES shaders will be passed to the regular version
of glslparsertest, which can run them with an ARB_ES<ver>_compatibility
extension. When a test is for desktop OpenGL, but only OpenGL ES is
available, then the test will skip in the python layer.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/test/glsl_parser_test.py        | 48 ++++++++++++++++++++-
 framework/tests/glsl_parser_test_tests.py | 72 ++++++++++++++++++++++++++-----
 2 files changed, 108 insertions(+), 12 deletions(-)

diff --git a/framework/test/glsl_parser_test.py b/framework/test/glsl_parser_test.py
index e31f8ac..d97b00b 100644
--- a/framework/test/glsl_parser_test.py
+++ b/framework/test/glsl_parser_test.py
@@ -26,13 +26,19 @@ import os
 import re
 
 from framework import exceptions
-from .piglit_test import PiglitBaseTest
+from .base import TestIsSkip
+from .piglit_test import PiglitBaseTest, TEST_BIN_DIR
 
 __all__ = [
     'GLSLParserTest',
     'GLSLParserNoConfigError',
 ]
 
+# In different configurations piglit may have one or both of these.
+_HAS_GL_VERSION = os.path.exists(os.path.join(TEST_BIN_DIR, 'glslparsertest'))
+_HAS_GLES_VERSION = os.path.exists(os.path.join(TEST_BIN_DIR,
+                                                'glslparsertest_gles2'))
+
 
 def _is_gles_version(version):
     """Return True if version is es, otherwsie false."""
@@ -41,6 +47,7 @@ def _is_gles_version(version):
         # glslparsertest doesn't honor them.
         if version.endswith('es'):
             return True
+
         version = float(version)
 
     return version in [1.0, 3.0, 3.1, 3.2]
@@ -73,6 +80,10 @@ class GLSLParserTest(PiglitBaseTest):
     def __init__(self, filepath):
         os.stat(filepath)
 
+        # This value is set to true if a test is for desktop OpenGL, but only
+        # OpenGL ES is available.
+        self.__is_skip = False
+
         # a set that stores a list of keys that have been found already
         self.__found_keys = set()
 
@@ -88,6 +99,30 @@ class GLSLParserTest(PiglitBaseTest):
 
         super(GLSLParserTest, self).__init__(command, run_concurrent=True)
 
+    def __pick_binary(self, version):
+        """Pick the correct version of glslparsertest to use.
+
+        This will try to select glslparsertest_gles2 for OpenGL ES tests, and
+        glslparsertest for desktop OpenGL tests. However, sometimes this isn't
+        possible. In that case all tests will be assigned to the desktop
+        version.
+
+        If the test requires desktop OpenGL, but only OpenGL ES is available,
+        then the test will be skipped in the python layer.
+
+        """
+        if _is_gles_version(version):
+            if _HAS_GLES_VERSION:
+                return 'glslparsertest_gles2'
+            else:
+                return 'glslparsertest'
+
+        if _HAS_GL_VERSION:
+            return 'glslparsertest'
+        else:
+            self.__is_skip = True
+            return 'None'
+
     def __get_command(self, config, filepath):
         """ Create the command argument to pass to super()
 
@@ -106,7 +141,7 @@ class GLSLParserTest(PiglitBaseTest):
         # Create the command and pass it into a PiglitTest()
         glsl = config['glsl_version']
         command = [
-            'glslparsertest_gles2' if _is_gles_version(glsl) else 'glslparsertest',
+            self.__pick_binary(glsl),
             filepath,
             config['expect_result'],
             config['glsl_version']
@@ -194,3 +229,12 @@ class GLSLParserTest(PiglitBaseTest):
             raise GLSLParserInternalError("No [end config] section found!")
 
         return keys
+
+    def is_skip(self):
+        # Skip when a test is only for desktop OpenGL, but only OpenGL ES is
+        # available.
+        if self.__is_skip:
+            raise TestIsSkip('Test is for desktop OpenGL, but only OpenGL ES '
+                             'tests have been built')
+
+        super(GLSLParserTest, self).is_skip()
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index b3ffd0f..2e0dc76 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -24,16 +24,46 @@ from __future__ import print_function, absolute_import
 import os
 import textwrap
 
+import mock
 import nose.tools as nt
 
 from framework import exceptions
 import framework.test.glsl_parser_test as glsl
 import framework.tests.utils as utils
-from framework.test import TEST_BIN_DIR
+from framework.test import TEST_BIN_DIR, TestIsSkip
 
 # pylint: disable=line-too-long,invalid-name
 
 
+class _Setup(object):
+    """A class holding setup and teardown methods.
+
+    These methods need to share data, and a class is a nice way to encapsulate
+    that.
+
+    """
+    def __init__(self):
+        self.patchers = []
+
+        self.patchers.extend([
+            mock.patch('framework.test.glsl_parser_test._HAS_GL_VERSION', True),
+            mock.patch('framework.test.glsl_parser_test._HAS_GLES_VERSION', True),
+        ])
+
+    def setup(self):
+        for p in self.patchers:
+            p.start()
+
+    def teardown(self):
+        for p in self.patchers:
+            p.stop()
+
+
+_setup = _Setup()
+setup = _setup.setup
+teardown = _setup.teardown
+
+
 def _check_config(content):
     """ This is the test that actually checks the glsl config section """
     with utils.tempfile(content) as tfile:
@@ -332,12 +362,10 @@ def test_good_extensions():
 @utils.nose_generator
 def test_get_glslparsertest_gles2():
     """GLSLParserTest: gets gles2 binary if glsl is 1.00 or 3.00"""
-
-    @utils.no_error
-    def test(content):
+    def test(content, expected):
         with utils.tempfile(content) as f:
             t = glsl.GLSLParserTest(f)
-            nt.eq_(os.path.basename(t.command[0]), 'glslparsertest_gles2')
+            nt.eq_(os.path.basename(t.command[0]), expected)
 
     content = textwrap.dedent("""\
         /*
@@ -347,13 +375,37 @@ def test_get_glslparsertest_gles2():
          * [end config]
          */
         """)
-
-    description = ("test.glsl_parser_test.GLSLParserTest: "
-                   "gets gles2 binary if glsl is {}")
-
     versions = ['1.00', '3.00', '3.10', '3.20', '3.00 es', '3.10 es',
                 '3.20 es']
+    description = ("test.glsl_parser_test.GLSLParserTest: "
+                   "gets gles2 binary if glsl is '{}' and gles2 binary exists")
 
     for version in versions:
         test.description = description.format(version)
-        yield test, content.format(version)
+        yield test, content.format(version), 'glslparsertest_gles2'
+
+    description = ("test.glsl_parser_test.GLSLParserTest: "
+                   "gets gl binary if glsl is '{}' and gles2 binary doesn't exist")
+
+    with mock.patch('framework.test.glsl_parser_test._HAS_GLES_VERSION', False):
+        for version in versions:
+            test.description = description.format(version)
+            yield test, content.format(version), 'glslparsertest'
+
+
+ at mock.patch('framework.test.glsl_parser_test._HAS_GL_VERSION', False)
+ at nt.raises(TestIsSkip)
+def test_binary_skip():
+    """test.glsl_parser_test.GLSLParserTest.is_skip: skips OpenGL tests when not built with desktop support"""
+    content = textwrap.dedent("""\
+        /*
+         * [config]
+         * expect_result: pass
+         * glsl_version: 1.10
+         * [end config]
+         */
+        """)
+
+    with utils.tempfile(content) as f:
+        test = glsl.GLSLParserTest(f)
+        test.is_skip()
-- 
2.6.2



More information about the Piglit mailing list