[Piglit] [PATCH 11/12] framework/exectest.py: Mark several Test methods as not API

Dylan Baker baker.dylan.c at gmail.com
Fri Apr 25 09:58:59 PDT 2014


Python doesn't have private or protected methods or members, instead it
subscribes to the "we're all consenting adults" theory of programming.
However, it does have conventions for marking methods as "don't use
these, they are subject to change". Any method marked with a leading
underscore is marked as "This is not a safe API, it's not guaranteed to
not change". These methods act as a sort of pseudo-private method.

This patch changes Test.interpret_result to Test._interpret_result,
Test.check_for_skip_scenario() to Test._check_for_skip_scenario(), and
Test.get_command_result to Test._run_command(). These methods shouldn't
be called externally. It also changes the PIGLIT_PLATFORM constant to
_PIGLIT_PLATFORM, again marking that it is meant for use in the module
exclusively.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/exectest.py | 46 ++++++++++++++++++++++++++++------------------
 framework/gtest.py    |  2 +-
 tests/es3conform.py   |  2 +-
 tests/igt.py          |  2 +-
 tests/oglconform.py   |  2 +-
 tests/xts.py          |  2 +-
 6 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/framework/exectest.py b/framework/exectest.py
index 71b6a37..a6892e9 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -20,6 +20,21 @@
 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
+""" Implements classes and helpers for running "native" piglit tests
+
+This module provides the abstract Test class which should be used as the base
+class for all tests for piglit integration. It provides two direct children
+PiglitTest and GleanTest, and two additional children of PiglitTest, ShaderTest
+and GLSLParserTest. Finally it provides custom exceptions for use with
+GLSLParesrTest and ShaderTest.
+
+In addition it provides helper methods for adding ShaderTest and
+GLSLParserTests to the profile modules.
+
+Test provides three methods for running tests, each one offering more features.
+
+"""
+
 import errno
 import os
 import os.path as path
@@ -48,11 +63,7 @@ __all__ = ['Test',
            'add_shader_test_dir',
            'TEST_BIN_DIR']
 
-# Platform global variables
-if 'PIGLIT_PLATFORM' in os.environ:
-    PIGLIT_PLATFORM = os.environ['PIGLIT_PLATFORM']
-else:
-    PIGLIT_PLATFORM = ''
+_PIGLIT_PLATFORM = os.environ.get('PIGLIT_PLATFORM', '')
 
 if 'PIGLIT_BUILD_DIR' in os.environ:
     TEST_BIN_DIR = os.path.join(os.environ['PIGLIT_BUILD_DIR'], 'bin')
@@ -144,7 +155,7 @@ class Test(object):
         self._command = value
 
     @abc.abstractmethod
-    def interpret_result(self):
+    def _interpret_result(self):
         pass
 
     def run(self):
@@ -161,7 +172,7 @@ class Test(object):
         self.result['environment'] = " ".join(
             '{0}="{1}"'.format(k, v) for k, v in  self.env.iteritems())
 
-        if self.check_for_skip_scenario():
+        if self._check_for_skip_scenario():
             self.result['result'] = 'skip'
             self.result['out'] = ""
             self.result['err'] = ""
@@ -171,12 +182,11 @@ class Test(object):
         # https://bugzilla.gnome.org/show_bug.cgi?id=680214 is affecting many
         # developers. If we catch it happening, try just re-running the test.
         for _ in xrange(5):
-            self.get_command_result()
+            self._run_command()
             if "Got spurious window resize" not in self.result['out']:
                 break
 
-        self.result['result'] = 'fail'
-        self.interpret_result()
+        self._interpret_result()
 
         crash_codes = [
             # Unix: terminated by a signal
@@ -209,7 +219,7 @@ class Test(object):
                 # Test passed but has valgrind errors.
                 self.result['result'] = 'fail'
 
-    def check_for_skip_scenario(self):
+    def _check_for_skip_scenario(self):
         """ Application specific check for skip
 
         If this function returns a truthy value then the current test will be
@@ -218,7 +228,7 @@ class Test(object):
         """
         return False
 
-    def get_command_result(self):
+    def _run_command(self):
         fullenv = os.environ.copy()
         for key, value in self.env.iteritems():
             fullenv[key] = str(value)
@@ -278,19 +288,19 @@ class PiglitTest(Test):
         # Prepend TEST_BIN_DIR to the path.
         self._command[0] = os.path.join(TEST_BIN_DIR, self._command[0])
 
-    def check_for_skip_scenario(self):
+    def _check_for_skip_scenario(self):
         """ Native Piglit-test specific skip checking
 
         If we are running on gbm don't run glean or glx- tests
 
         """
-        if PIGLIT_PLATFORM == 'gbm':
+        if _PIGLIT_PLATFORM == 'gbm':
             split_command = os.path.split(self._command[0])[1]
             if split_command.startswith('glx-'):
                 return True
         return False
 
-    def interpret_result(self):
+    def _interpret_result(self):
         outlines = self.result['out'].split('\n')
         outpiglit = (s[7:] for s in outlines if s.startswith('PIGLIT:'))
 
@@ -317,12 +327,12 @@ class GleanTest(Test):
     def command(self):
         return super(GleanTest, self).command + self.GLOBAL_PARAMS
 
-    def check_for_skip_scenario(self):
-        if PIGLIT_PLATFORM == 'gbm':
+    def _check_for_skip_scenario(self):
+        if _PIGLIT_PLATFORM == 'gbm':
             return True
         return False
 
-    def interpret_result(self):
+    def _interpret_result(self):
         if 'FAIL' in self.result['out'] or self.result['returncode'] != 0:
             self.result['result'] = 'fail'
         else:
diff --git a/framework/gtest.py b/framework/gtest.py
index 34902b1..983e216 100644
--- a/framework/gtest.py
+++ b/framework/gtest.py
@@ -29,7 +29,7 @@ import re
 from framework.exectest import Test
 
 class GTest(Test):
-    def interpret_result(self):
+    def _interpret_result(self):
         # Since gtests can have several subtets, if any of the subtests fail
         # then we need to report fail.
         out = self.result['out']
diff --git a/tests/es3conform.py b/tests/es3conform.py
index b94cb06..0120ce9 100644
--- a/tests/es3conform.py
+++ b/tests/es3conform.py
@@ -55,7 +55,7 @@ class GTFTest(Test):
                                        '-minfmt', '-width=113', '-height=47',
                                        '-run=' + testpath])
 
-    def interpret_result(self):
+    def _interpret_result(self):
         mo = self.pass_re.search(self.result['out'])
         if mo is not None and int(mo.group('passed')) > 0:
             self.result['result'] = 'pass'
diff --git a/tests/igt.py b/tests/igt.py
index 4db321e..92d7ed0 100644
--- a/tests/igt.py
+++ b/tests/igt.py
@@ -78,7 +78,7 @@ class IGTTest(Test):
         super(IGTTest, self).__init__(
             [path.join(igtTestRoot, binary)] + arguments)
 
-    def interpret_result(self):
+    def _interpret_result(self):
         if not igtEnvironmentOk:
             return
 
diff --git a/tests/oglconform.py b/tests/oglconform.py
index 1d40d2a..e6a3787 100644
--- a/tests/oglconform.py
+++ b/tests/oglconform.py
@@ -52,7 +52,7 @@ class OGLCTest(Test):
         super(OGLCTest, self).__init__([bin_oglconform, '-minFmt', '-v', '4',
                                         '-test', category, subtest])
 
-    def interpret_result(self):
+    def _interpret_result(self):
         if self.skip_re.search(self.result['out']) is not None:
             self.result['result'] = 'skip'
         elif re.search('Total Passed : 1', self.result['out']) is not None:
diff --git a/tests/xts.py b/tests/xts.py
index c9710fa..75f4f3f 100644
--- a/tests/xts.py
+++ b/tests/xts.py
@@ -129,7 +129,7 @@ class XTSTest(Test):
 
         return images
 
-    def interpret_result(self):
+    def _interpret_result(self):
         try:
             with open(self.test_results_file, 'r') as rfile:
                 log = rfile.read()
-- 
2.0.0.rc0



More information about the Piglit mailing list