[Piglit] [PATCH 12/15] piglit_test.py: Add arguments for platform restrictions to PiglitGLTest

Dylan Baker baker.dylan.c at gmail.com
Fri Oct 3 17:57:53 PDT 2014


This adds two new keyword arguments to the PiglitGLTest,
require_platform and exclude_platforms. These two arguments are mutually
exclusive and provide a mechanism to fast filter tests that have
platform restrictions.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/test/piglit_test.py        | 48 ++++++++++++++++++++++++++++++++----
 framework/tests/piglit_test_tests.py | 38 ++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 5 deletions(-)

diff --git a/framework/test/piglit_test.py b/framework/test/piglit_test.py
index c742271..9a301c2 100644
--- a/framework/test/piglit_test.py
+++ b/framework/test/piglit_test.py
@@ -29,6 +29,7 @@ except ImportError:
     import json
 
 from .base import Test, WindowResizeMixin
+import framework.core as core
 
 
 __all__ = [
@@ -73,19 +74,56 @@ class PiglitGLTest(WindowResizeMixin, PiglitBaseTest):
     This Subclass provides provides an is_skip() implementation that skips glx
     tests on non-glx platforms
 
+    This class also provides two additional keyword arguments, require_platform
+    and exclude_platforms. require_platforms may be set to a list of platforms
+    which the test requires to run. This should be resereved for platform
+    specific tests, such as GLX specific tests, or EGL specific tests. Multiple
+    platforms are allowed because EGL can be fulfilled by multiple platforms.
+    exclude_platforms is a list of platforms a test should not be run on, this
+    is useful for tests that are valid on more than one platform, but not on
+    all of them. This will probably be mainly used to exclude gbm. These
+    options are mutually exclusive.
+
     """
+    def __init__(self, command, require_platforms=None, exclude_platforms=None,
+                 **kwargs):
+        # TODO: There is a design flaw in python2, keyword args can be
+        # fulfilled as positional arguments. This sounds really great, until
+        # you realize that because of it you cannot use the splat operator with
+        # args and create new keyword arguments.
+        # What we really want is __init__(self, *args, new_arg=None, **kwargs),
+        # but this doesn't work in python2. In python3 thanks to PEP3102, you
+        # can in fact do just that
+        # The work around is to explicitely pass the arguments down.
+        super(PiglitGLTest, self).__init__(command, **kwargs)
+
+        assert not (require_platforms and exclude_platforms)
+
+        if not require_platforms or set(require_platforms).issubset(
+                set(core.PLATFORMS)):
+            self.__require_platforms = require_platforms or []
+        else:
+            raise Exception("Error: require_platform is not valid")
+
+        if (not exclude_platforms or
+                set(exclude_platforms).issubset(set(core.PLATFORMS))):
+            self.__exclude_platforms = exclude_platforms or []
+        else:
+            raise Exception("Error: exclude_platforms is not valid")
+
     def is_skip(self):
         """ Native Piglit-test specific skip checking
 
-        If the platform for the run doesn't suppoprt glx (either directly as
+        If the platform for the run doesn't support glx (either directly as
         glx or through the hybrid glx/x11_egl setup that is default), then skip
         any glx specific tests.
 
         """
-        if self.OPTS.env['PIGLIT_PLATFORM'] not in ['glx', 'mixed_glx_egl']:
-            split_command = os.path.split(self._command[0])[1]
-            if split_command.startswith('glx-'):
-                return True
+        platform = self.OPTS.env['PIGLIT_PLATFORM']
+        if self.__require_platforms and platform not in self.__require_platforms:
+            return True
+        elif self.__exclude_platforms and platform in self.__exclude_platforms:
+            return True
         return False
 
     @PiglitBaseTest.command.getter
diff --git a/framework/tests/piglit_test_tests.py b/framework/tests/piglit_test_tests.py
index 102b5ef..4dfe855 100644
--- a/framework/tests/piglit_test_tests.py
+++ b/framework/tests/piglit_test_tests.py
@@ -21,6 +21,8 @@
 """ Tests for the exectest module """
 
 import nose.tools as nt
+
+import framework.tests.utils as utils
 from framework.test.piglit_test import (PiglitBaseTest, PiglitGLTest,
                                         PiglitCLTest)
 
@@ -83,3 +85,39 @@ def test_piglittest_command_getter_concurrent():
     test = PiglitGLTest('foo', run_concurrent=True)
     nt.assert_in('-auto', test.command)
     nt.assert_in('-fbo', test.command)
+
+
+def test_PiglitGLTest_include_and_exclude():
+    """PiglitGLTest.is_skip() raises if include and exclude are given."""
+    with nt.assert_raises(AssertionError):
+        PiglitGLTest('foo',
+                     require_platforms=['glx'],
+                     exclude_platforms=['gbm'])
+
+
+def test_PiglitGLTest_platform_in_require():
+    """PiglitGLTest.is_skip() does not skip if platform is in require_platforms."""
+    PiglitGLTest.OPTS.env['PIGLIT_PLATFORM'] = 'glx'
+    test = PiglitGLTest('foo', require_platforms=['glx'])
+    nt.assert_false(test.is_skip())
+
+
+def test_PiglitGLTest_platform_not_in_require():
+    """PiglitGLTest.is_skip() skips if platform is not in require_platforms."""
+    PiglitGLTest.OPTS.env['PIGLIT_PLATFORM'] = 'gbm'
+    test = PiglitGLTest('foo', require_platforms=['glx'])
+    nt.assert_true(test.is_skip())
+
+
+def test_PiglitGLTest_platform_in_exclude():
+    """PiglitGLTest.is_skip() skips if platform is in exclude_platforms.."""
+    PiglitGLTest.OPTS.env['PIGLIT_PLATFORM'] = 'glx'
+    test = PiglitGLTest('foo', exclude_platforms=['glx'])
+    nt.assert_true(test.is_skip())
+
+
+def test_PiglitGLTest_platform_not_in_exclude():
+    """PiglitGLTest.is_skip() does not skip if platform is in exclude_platforms."""
+    PiglitGLTest.OPTS.env['PIGLIT_PLATFORM'] = 'gbm'
+    test = PiglitGLTest('foo', exclude_platforms=['glx'])
+    nt.assert_false(test.is_skip())
-- 
2.1.2



More information about the Piglit mailing list