[Piglit] [PATCH] framework/test/opengl.py: If float fails on version string pass

baker.dylan.c at gmail.com baker.dylan.c at gmail.com
Mon Dec 7 11:23:46 PST 2015


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

This will cause the fast skip system to pass when a ValueError or
IndexError when trying to parse OpenGL, OpenGL ES, GLSL, and GLSL ES
versions.

A warning will be printed if this happens.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/test/opengl.py        | 29 +++++++++++++-----
 framework/tests/opengl_tests.py | 67 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 8 deletions(-)

diff --git a/framework/test/opengl.py b/framework/test/opengl.py
index 29da2d1..25b774a 100644
--- a/framework/test/opengl.py
+++ b/framework/test/opengl.py
@@ -24,6 +24,7 @@ from __future__ import absolute_import, division, print_function
 import errno
 import os
 import subprocess
+import warnings
 
 from framework import exceptions, core
 from framework.options import OPTIONS
@@ -170,8 +171,11 @@ class WflInfo(object):
                     break
                 raise
             else:
-                ret = float(self.__getline(
-                    raw.split('\n'), 'OpenGL version string').split()[3])
+                try:
+                    ret = float(self.__getline(
+                        raw.split('\n'), 'OpenGL version string').split()[3])
+                except (ValueError, IndexError) as e:
+                    warnings.warn('cannot parse GL version\n{}'.format(e))
                 break
         return ret
 
@@ -202,8 +206,11 @@ class WflInfo(object):
                     break
                 raise
             else:
-                ret = float(self.__getline(
-                    raw.split('\n'), 'OpenGL version string').split()[5])
+                try:
+                    ret = float(self.__getline(
+                        raw.split('\n'), 'OpenGL version string').split()[5])
+                except (ValueError, IndexError) as e:
+                    warnings.warn('cannot parse GLES version\n{}'.format(e))
                 break
         return ret
 
@@ -222,8 +229,11 @@ class WflInfo(object):
                     break
                 raise
             else:
-                ret = float(self.__getline(
-                    raw.split('\n'), 'OpenGL shading language').split()[-1])
+                try:
+                    ret = float(self.__getline(
+                        raw.split('\n'), 'OpenGL shading language').split()[-1])
+                except (ValueError, IndexError) as e:
+                    warnings.warn('cannot parse GLSL version\n{}'.format(e))
                 break
         return ret
 
@@ -244,8 +254,11 @@ class WflInfo(object):
                 # GLSL ES version numbering is insane.
                 # For version >= 3 the numbers are 3.00, 3.10, etc.
                 # For version 2, they are 1.0.xx
-                ret = float(self.__getline(
-                    raw.split('\n'), 'OpenGL shading language').split()[-1][:3])
+                try:
+                    ret = float(self.__getline(
+                        raw.split('\n'), 'OpenGL shading language').split()[-1][:3])
+                except (ValueError, IndexError) as e:
+                    warnings.warn('cannot parse GLSL ES version\n{}'.format(e))
                 break
         return ret
 
diff --git a/framework/tests/opengl_tests.py b/framework/tests/opengl_tests.py
index 97daf2b..b3413f6 100644
--- a/framework/tests/opengl_tests.py
+++ b/framework/tests/opengl_tests.py
@@ -22,6 +22,7 @@
 
 from __future__ import absolute_import, division, print_function
 import subprocess
+import warnings
 
 import mock
 import nose.tools as nt
@@ -137,6 +138,72 @@ class TestWflInfo(object):
                         mock.Mock(return_value=rv)):
             nt.eq_(5.0, self._test.glsl_es_version)
 
+    def test_gl_version_bad(self):
+        """test.opengl.WflInfo.gl_version: If parsing fails version is None"""
+        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: foobar'
+            'OpenGL context flags: 0x0\n'
+        )
+        with warnings.catch_warnings():
+            warnings.simplefilter('ignore')
+            with mock.patch('framework.test.opengl.subprocess.check_output',
+                            mock.Mock(return_value=rv)):
+                nt.eq_(None, self._test.gl_version)
+
+    def test_gles_version_bad(self):
+        """test.opengl.WflInfo.gles_version: If parsing fails version is None"""
+        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: foobar'
+        )
+        with warnings.catch_warnings():
+            warnings.simplefilter('ignore')
+            with mock.patch('framework.test.opengl.subprocess.check_output',
+                            mock.Mock(return_value=rv)):
+                nt.eq_(None, self._test.gles_version)
+
+    def test_glsl_version_bad(self):
+        """test.opengl.WflInfo.glsl_version: if parsing fails value is None"""
+        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: 1.1 (Core Profile) Mesa 11.0.4\n'
+            'OpenGL context flags: 0x0\n'
+            'OpenGL shading language version string: totally broken'
+            'OpenGL extensions: this is some extension strings.\n'
+        )
+        with warnings.catch_warnings():
+            warnings.simplefilter('ignore')
+            with mock.patch('framework.test.opengl.subprocess.check_output',
+                            mock.Mock(return_value=rv)):
+                nt.eq_(None, self._test.glsl_version)
+
+    def test_glsl_es_version_bad(self):
+        """test.opengl.WflInfo.glsl_es_version: if parsing fails value is None"""
+        rv = (
+            'Waffle platform: gbm\n'
+            'Waffle api: gles2\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 3.0 Mesa 11.0.4\n'
+            'OpenGL shading language version string: Foobarboink'
+            'OpenGL extensions: this is some extension strings.\n'
+        )
+        with warnings.catch_warnings():
+            warnings.simplefilter('ignore')
+            with mock.patch('framework.test.opengl.subprocess.check_output',
+                            mock.Mock(return_value=rv)):
+                nt.eq_(None, self._test.glsl_es_version)
+
 
 class TestWflInfoOSError(object):
     """Tests for the Wflinfo functions to handle OSErrors."""
-- 
2.6.3



More information about the Piglit mailing list