[Piglit] [PATCH 05/11] framework/test/opengl.py: add support for GL(ES) version skipping.

baker.dylan.c at gmail.com baker.dylan.c at gmail.com
Thu Nov 5 14:16:43 PST 2015


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

This patch adds support to the FasSkipMixin for skipping on GL and GLES
versions. It does this by querying wflinfo for the highest supported

This skipping only supports checking that the requirement is <= to the
maximum GL(ES) provided. There are some instances of tests that have
requirements like "GL <= 2.1", and this patch doesn't cover case. These
cases are pretty rare, so it doesn't seem like a path worth optimizing
for anyway.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/test/opengl.py        | 74 +++++++++++++++++++++++++++++++
 framework/tests/opengl_tests.py | 97 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 170 insertions(+), 1 deletion(-)

diff --git a/framework/test/opengl.py b/framework/test/opengl.py
index 3485d3a..2fe819b 100644
--- a/framework/test/opengl.py
+++ b/framework/test/opengl.py
@@ -149,6 +149,64 @@ class WflInfo(object):
 
         return {e.strip() for e in all_}
 
+    @core.lazy_property
+    def gl_version(self):
+        """Calculate the maximum opengl version.
+
+        This will try (in order): core, compat, and finally no profile,
+        stopping when it finds a profile. It assumes taht most implementations
+        will have core and compat as equals, or core as superior to compat in
+        terms of support.
+
+        """
+        ret = None
+        for profile in ['core', 'compat', 'none']:
+            try:
+                raw = self.__call_wflinfo(['--api', 'gl', '--profile', profile])
+            except StopWflinfo as e:
+                if e.reason == 'Called':
+                    continue
+                elif e.reason == 'OSError':
+                    break
+                raise
+            else:
+                ret = float(self.__getline(
+                    raw.split('\n'), 'OpenGL version string').split()[3])
+                break
+        return ret
+
+    @core.lazy_property
+    def gles_version(self):
+        """Calculate the maximum opengl es version.
+
+        The design of this function isn't 100% correct. GLES1 and GLES2+ behave
+        differently, since 2+ can be silently promoted, but 1 cannot. This
+        means that a driver can implement 2, 3, 3.1, etc, but never have 1
+        support.
+
+        I don't think this is a big deal for a couple of reasons. First, piglit
+        has a very small set of GLES1 tests, so they shouldn't have big impact
+        on runtime, and second, the design of the FastSkipMixin is
+        conservative: it would rather run a few tests that should be skipped
+        than skip a few tests that should be run.
+
+        """
+        ret = None
+        for api in ['gles3', 'gles2', 'gles1']:
+            try:
+                raw = self.__call_wflinfo(['--api', api])
+            except StopWflinfo as e:
+                if e.reason == 'Called':
+                    continue
+                elif e.reason == 'OSError':
+                    break
+                raise
+            else:
+                ret = float(self.__getline(
+                    raw.split('\n'), 'OpenGL version string').split()[5])
+                break
+        return ret
+
 
 class FastSkipMixin(object):
     """Fast test skipping for OpenGL based suites.
@@ -203,4 +261,20 @@ class FastSkipMixin(object):
                         'Test requires extension {} '
                         'which is not available'.format(extension))
 
+        if (self.__info.gl_version is not None
+                and self.gl_version is not None
+                and self.gl_version > self.__info.gl_version):
+            raise TestIsSkip(
+                'Test requires OpenGL version {}, '
+                'but only {} is available'.format(
+                    self.gl_version, self.__info.gl_version))
+
+        if (self.__info.gles_version is not None
+                and self.gles_version is not None
+                and self.gles_version > self.__info.gles_version):
+            raise TestIsSkip(
+                'Test requires OpenGL ES version {}, '
+                'but only {} is available'.format(
+                    self.gles_version, self.__info.gles_version))
+
         super(FastSkipMixin, self).is_skip()
diff --git a/framework/tests/opengl_tests.py b/framework/tests/opengl_tests.py
index aa42738..2a57a4d 100644
--- a/framework/tests/opengl_tests.py
+++ b/framework/tests/opengl_tests.py
@@ -62,8 +62,35 @@ class TestWflInfo(object):
                         mock.Mock(return_value=rv)):
             nt.eq_(expected, self._test.gl_extensions)
 
+    def test_gl_version(self):
+        """test.opengl.WflInfo.gl_version: Provides a version number"""
+        rv = (
+            'Waffle platform: gbm\n'
+            'Waffle api: gl\n'
+            'OpenGL vendor string: Intel Open Source Technology Center\n'
+            'OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile\n'
+            'OpenGL version string: 18 (Core Profile) Mesa 11.0.4\n'
+            'OpenGL context flags: 0x0\n'
+        )
+        with mock.patch('framework.test.opengl.subprocess.check_output',
+                        mock.Mock(return_value=rv)):
+            nt.eq_(18.0, self._test.gl_version)
+
+    def test_gles_version(self):
+        """test.opengl.WflInfo.gles_version: Provides a version number"""
+        rv = (
+            'Waffle platform: gbm\n'
+            'Waffle api: gles3\n'
+            'OpenGL vendor string: Intel Open Source Technology Center\n'
+            'OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile\n'
+            'OpenGL version string: OpenGL ES 7.1 Mesa 11.0.4\n'
+        )
+        with mock.patch('framework.test.opengl.subprocess.check_output',
+                        mock.Mock(return_value=rv)):
+            nt.eq_(7.1, self._test.gles_version)
+
 
-class TestWflInfoSError(object):
+class TestWflInfoOSError(object):
     """Tests for the Wflinfo functions to handle OSErrors."""
     __patchers = []
 
@@ -95,6 +122,16 @@ class TestWflInfoSError(object):
         """test.opengl.WflInfo.gl_extensions: Handles OSError "no file" gracefully"""
         self.inst.gl_extensions
 
+    @utils.not_raises(OSError)
+    def test_get_gl_version(self):
+        """test.opengl.WflInfo.get_gl_version: Handles OSError "no file" gracefully"""
+        self.inst.gl_version
+
+    @utils.not_raises(OSError)
+    def test_get_gles_version(self):
+        """test.opengl.WflInfo.get_gles_version: Handles OSError "no file" gracefully"""
+        self.inst.gles_version
+
 
 class TestWflInfoCalledProcessError(object):
     """Tests for the WflInfo functions to handle OSErrors."""
@@ -128,6 +165,16 @@ class TestWflInfoCalledProcessError(object):
         """test.opengl.WflInfo.gl_extensions: Handles CalledProcessError gracefully"""
         self.inst.gl_extensions
 
+    @utils.not_raises(subprocess.CalledProcessError)
+    def test_gl_version(self):
+        """test.opengl.WflInfo.get_gl_version: Handles CalledProcessError gracefully"""
+        self.inst.gl_version
+
+    @utils.not_raises(subprocess.CalledProcessError)
+    def test_gles_version(self):
+        """test.opengl.WflInfo.gles_version: Handles CalledProcessError gracefully"""
+        self.inst.gles_version
+
 
 class TestFastSkipMixin(object):
     """Tests for the FastSkipMixin class."""
@@ -186,3 +233,51 @@ class TestFastSkipMixin(object):
     def test_requires_empty(self):
         """test.opengl.FastSkipMixin.is_skip: if gl_requires is empty test runs"""
         self.test.is_skip()
+
+    @nt.raises(TestIsSkip)
+    def test_max_gl_version_lt(self):
+        """tefst.opengl.FastSkipMixin.is_skip: skips if gl_version > __max_gl_version"""
+        self.test.gl_version = 4.0
+        self.test.is_skip()
+
+    @utils.not_raises(TestIsSkip)
+    def test_max_gl_version_gt(self):
+        """test.opengl.FastSkipMixin.is_skip: runs if gl_version < __max_gl_version"""
+        self.test.gl_version = 1.0
+
+    @utils.not_raises(TestIsSkip)
+    def test_max_gl_version_unset(self):
+        """test.opengl.FastSkipMixin.is_skip: runs if __max_gl_version is None"""
+        self.test.gl_version = 1.0
+        with mock.patch.object(self.test._FastSkipMixin__info, 'gl_version',  # pylint: disable=no-member
+                               None):
+            self.test.is_skip()
+
+    @utils.not_raises(TestIsSkip)
+    def test_max_gl_version_set(self):
+        """test.opengl.FastSkipMixin.is_skip: runs if gl_version is None"""
+        self.test.is_skip()
+
+    @nt.raises(TestIsSkip)
+    def test_max_gles_version_lt(self):
+        """test.opengl.FastSkipMixin.is_skip: skips if gles_version > __max_gles_version"""
+        self.test.gles_version = 4.0
+        self.test.is_skip()
+
+    @utils.not_raises(TestIsSkip)
+    def test_max_gles_version_gt(self):
+        """test.opengl.FastSkipMixin.is_skip: runs if gles_version < __max_gles_version"""
+        self.test.gles_version = 1.0
+
+    @utils.not_raises(TestIsSkip)
+    def test_max_gles_version_unset(self):
+        """test.opengl.FastSkipMixin.is_skip: runs if __max_gles_version is None"""
+        self.test.gles_version = 1.0
+        with mock.patch.object(self.test._FastSkipMixin__info, 'gles_version',  # pylint: disable=no-member
+                               None):
+            self.test.is_skip()
+
+    @utils.not_raises(TestIsSkip)
+    def test_max_gles_version_set(self):
+        """test.opengl.FastSkipMixin.is_skip: runs if gles_version is None"""
+        self.test.is_skip()
-- 
2.6.2



More information about the Piglit mailing list