[Piglit] [PATCH 10/12] exectest.py: Move testBinDir and Test to exectest

Dylan Baker baker.dylan.c at gmail.com
Tue Feb 11 18:11:15 PST 2014


These are both primarily consumed by ExecTest and children, so having
them in the same module makes sense.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/core.py                         | 81 +----------------------------
 framework/exectest.py                     | 85 ++++++++++++++++++++++++++++++-
 framework/gleantest.py                    |  3 +-
 framework/glsl_parser_test.py             |  3 +-
 framework/shader_test.py                  |  4 +-
 framework/tests/glsl_parser_test_tests.py |  2 +-
 tests/es3conform.py                       |  4 +-
 tests/igt.py                              |  4 +-
 tests/oglconform.py                       |  4 +-
 9 files changed, 96 insertions(+), 94 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index ac25917..ddf6011 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -28,8 +28,6 @@ import platform
 import re
 import subprocess
 import sys
-import time
-import traceback
 from cStringIO import StringIO
 import multiprocessing
 import multiprocessing.dummy
@@ -53,9 +51,7 @@ __all__ = ['PIGLIT_CONFIG',
            'TestrunResult',
            'TestResult',
            'TestProfile',
-           'Group',
-           'Test',
-           'testBinDir']
+           'Group']
 
 
 PIGLIT_CONFIG = ConfigParser.SafeConfigParser()
@@ -214,16 +210,6 @@ def checkDir(dirname, failifexists):
         if e.errno != errno.EEXIST:
             raise
 
-if 'PIGLIT_BUILD_DIR' in os.environ:
-    testBinDir = os.path.join(os.environ['PIGLIT_BUILD_DIR'], 'bin')
-else:
-    testBinDir = os.path.normpath(os.path.join(os.path.dirname(__file__),
-                                               '../bin'))
-
-if 'PIGLIT_SOURCE_DIR' not in os.environ:
-    p = os.path
-    os.environ['PIGLIT_SOURCE_DIR'] = p.abspath(p.join(p.dirname(__file__),
-                                                       '..'))
 
 # In debug builds, Mesa will by default log GL API errors to stderr.
 # This is useful for application developers or driver developers
@@ -408,71 +394,6 @@ class Environment:
         return result
 
 
-class Test(object):
-    def __init__(self, runConcurrent=False):
-        '''
-                'runConcurrent' controls whether this test will
-                execute it's work (i.e. __doRunWork) on the calling thread
-                (i.e. the main thread) or from the ConcurrentTestPool threads.
-        '''
-        self.runConcurrent = runConcurrent
-        self.skip_test = False
-
-        # This is a hook for doing some testing on execute right before
-        # self.run is called.
-        self._test_hook_execute_run = lambda: None
-
-    def run(self):
-        raise NotImplementedError
-
-    def execute(self, env, path, log, json_writer, dmesg):
-        '''
-        Run the test.
-
-        :path:
-            Fully qualified test name as a string.  For example,
-            ``spec/glsl-1.30/preprocessor/compiler/keywords/void.frag``.
-        '''
-
-        log_current = log.get_current()
-        # Run the test
-        if env.execute:
-            try:
-                log.log()
-                time_start = time.time()
-                dmesg.update_dmesg()
-                self._test_hook_execute_run()
-                result = self.run(env)
-                result = dmesg.update_result(result)
-                time_end = time.time()
-                if 'time' not in result:
-                    result['time'] = time_end - time_start
-                if 'result' not in result:
-                    result['result'] = 'fail'
-                if not isinstance(result, TestResult):
-                    result = TestResult(result)
-                    result['result'] = 'warn'
-                    result['note'] = 'Result not returned as an instance ' \
-                                     'of TestResult'
-            except:
-                result = TestResult()
-                result['result'] = 'fail'
-                result['exception'] = str(sys.exc_info()[0]) + \
-                    str(sys.exc_info()[1])
-                result['traceback'] = \
-                    "".join(traceback.format_tb(sys.exc_info()[2]))
-
-            if 'subtest' in result and len(result['subtest'].keys()) > 1:
-                for test in result['subtest'].keys():
-                    result['result'] = result['subtest'][test]
-                    json_writer.write_dict_item(os.path.join(path, test), result)
-            else:
-                json_writer.write_dict_item(path, result)
-        else:
-            log.log()
-        log.mark_complete(log_current)
-
-
 class Group(dict):
     pass
 
diff --git a/framework/exectest.py b/framework/exectest.py
index 4f88dbc..30241de 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -24,9 +24,17 @@ import errno
 import os
 import subprocess
 import shlex
+import time
+import traceback
+import sys
 
-from .core import Test, testBinDir, TestResult
+from .core import TestResult
 
+__all__ = ['Test',
+           'ExecTest',
+           'PlainExecTest',
+           'PIGLIT_PLATFORM',
+           'testBinDir']
 
 # Platform global variables
 if 'PIGLIT_PLATFORM' in os.environ:
@@ -34,6 +42,81 @@ if 'PIGLIT_PLATFORM' in os.environ:
 else:
     PIGLIT_PLATFORM = ''
 
+if 'PIGLIT_BUILD_DIR' in os.environ:
+    testBinDir = os.path.join(os.environ['PIGLIT_BUILD_DIR'], 'bin')
+else:
+    testBinDir = os.path.normpath(os.path.join(os.path.dirname(__file__),
+                                               '../bin'))
+
+if 'PIGLIT_SOURCE_DIR' not in os.environ:
+    os.environ['PIGLIT_SOURCE_DIR'] = \
+        os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
+
+
+class Test(object):
+    def __init__(self, runConcurrent=False):
+        '''
+                'runConcurrent' controls whether this test will
+                execute it's work (i.e. __doRunWork) on the calling thread
+                (i.e. the main thread) or from the ConcurrentTestPool threads.
+        '''
+        self.runConcurrent = runConcurrent
+        self.skip_test = False
+
+        # This is a hook for doing some testing on execute right before
+        # self.run is called.
+        self._test_hook_execute_run = lambda: None
+
+    def run(self):
+        raise NotImplementedError
+
+    def execute(self, env, path, log, json_writer, dmesg):
+        '''
+        Run the test.
+
+        :path:
+            Fully qualified test name as a string.  For example,
+            ``spec/glsl-1.30/preprocessor/compiler/keywords/void.frag``.
+        '''
+
+        log_current = log.get_current()
+        # Run the test
+        if env.execute:
+            try:
+                log.log()
+                time_start = time.time()
+                dmesg.update_dmesg()
+                self._test_hook_execute_run()
+                result = self.run(env)
+                result = dmesg.update_result(result)
+                time_end = time.time()
+                if 'time' not in result:
+                    result['time'] = time_end - time_start
+                if 'result' not in result:
+                    result['result'] = 'fail'
+                if not isinstance(result, TestResult):
+                    result = TestResult(result)
+                    result['result'] = 'warn'
+                    result['note'] = 'Result not returned as an instance ' \
+                                     'of TestResult'
+            except:
+                result = TestResult()
+                result['result'] = 'fail'
+                result['exception'] = str(sys.exc_info()[0]) + \
+                    str(sys.exc_info()[1])
+                result['traceback'] = \
+                    "".join(traceback.format_tb(sys.exc_info()[2]))
+
+            if 'subtest' in result and len(result['subtest'].keys()) > 1:
+                for test in result['subtest'].keys():
+                    result['result'] = result['subtest'][test]
+                    json_writer.write_dict_item(os.path.join(path, test), result)
+            else:
+                json_writer.write_dict_item(path, result)
+        else:
+            log.log()
+        log.mark_complete(log_current)
+
 
 # ExecTest: A shared base class for tests that simply runs an executable.
 class ExecTest(Test):
diff --git a/framework/gleantest.py b/framework/gleantest.py
index 4abb54a..aad73fd 100644
--- a/framework/gleantest.py
+++ b/framework/gleantest.py
@@ -23,8 +23,7 @@
 
 import os
 
-from .core import testBinDir
-from .exectest import ExecTest
+from .exectest import ExecTest, testBinDir
 
 glean_executable = os.path.join(testBinDir, "glean")
 
diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 2b413c4..cc4c523 100644
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -27,8 +27,7 @@ import os.path as path
 import re
 from cStringIO import StringIO
 
-from .core import testBinDir
-from .exectest import PlainExecTest
+from .exectest import PlainExecTest, testBinDir
 
 
 def add_glsl_parser_test(group, filepath, test_name):
diff --git a/framework/shader_test.py b/framework/shader_test.py
index ee0dd05..4d08ae3 100644
--- a/framework/shader_test.py
+++ b/framework/shader_test.py
@@ -27,8 +27,8 @@ import os
 import os.path as path
 import re
 
-from .core import testBinDir, Group
-from .exectest import PlainExecTest
+from .core import Group
+from .exectest import testBinDir, PlainExecTest
 
 
 __all__ = ['add_shader_test', 'add_shader_test_dir']
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index d73879d..00c1bc2 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -25,7 +25,7 @@ import tempfile
 from contextlib import contextmanager
 import nose.tools as nt
 import framework.glsl_parser_test as glsl
-from framework.core import testBinDir
+from framework.exectest import testBinDir
 
 
 @contextmanager
diff --git a/tests/es3conform.py b/tests/es3conform.py
index dadebb9..d5d6a12 100644
--- a/tests/es3conform.py
+++ b/tests/es3conform.py
@@ -26,8 +26,8 @@ import sys
 
 from os import path
 from glob import glob
-from framework.core import TestProfile, testBinDir
-from framework.exectest import ExecTest
+from framework.core import TestProfile
+from framework.exectest import ExecTest, testBinDir
 
 __all__ = ['profile']
 
diff --git a/tests/igt.py b/tests/igt.py
index f80a6c4..7416b4e 100644
--- a/tests/igt.py
+++ b/tests/igt.py
@@ -28,8 +28,8 @@ import sys
 import subprocess
 
 from os import path
-from framework.core import testBinDir, TestProfile, TestResult
-from framework.exectest import ExecTest
+from framework.core import TestProfile, TestResult
+from framework.exectest import ExecTest, testBinDir
 
 __all__ = ['profile']
 
diff --git a/tests/oglconform.py b/tests/oglconform.py
index 857d0cd..c2273dc 100644
--- a/tests/oglconform.py
+++ b/tests/oglconform.py
@@ -26,8 +26,8 @@ import re
 import sys
 import subprocess
 
-from framework.core import TestProfile, testBinDir
-from framework.exectest import ExecTest
+from framework.core import TestProfile
+from framework.exectest import ExecTest, testBinDir
 from os import path
 
 __all__ = ['profile']
-- 
1.8.5.4



More information about the Piglit mailing list