[Piglit] [PATCH 03/15] framework/test: refactor abstract Test and PiglitTest
Dylan Baker
baker.dylan.c at gmail.com
Fri Oct 3 17:57:44 PDT 2014
This creates two separate modules for these classes.
Making this change allows us to separate the basic building blocks of
Test classes and the concrete implementations.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/profile.py | 5 +--
framework/test/__init__.py | 6 ++-
framework/test/{exectest.py => base.py} | 53 ++--------------------
framework/test/gleantest.py | 3 +-
framework/test/glsl_parser_test.py | 2 +-
framework/test/gtest.py | 2 +-
framework/test/oclconform.py | 2 +-
framework/test/piglit_test.py | 80 +++++++++++++++++++++++++++++++++
framework/test/shader_test.py | 2 +-
framework/tests/exectest_test.py | 3 +-
tests/es3conform.py | 3 +-
tests/igt.py | 2 +-
tests/oglconform.py | 2 +-
tests/xts.py | 2 +-
14 files changed, 103 insertions(+), 64 deletions(-)
rename framework/test/{exectest.py => base.py} (87%)
create mode 100644 framework/test/piglit_test.py
diff --git a/framework/profile.py b/framework/profile.py
index 6a0f5a8..0d00e35 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -35,7 +35,7 @@ import importlib
from framework.dmesg import get_dmesg
from framework.log import LogManager
-import framework.test
+from framework.test.base import Test
__all__ = [
'TestProfile',
@@ -183,12 +183,11 @@ class TestProfile(object):
Arguments:
opts -- a core.Options instance
backend -- a results.Backend derived instance
-
"""
self._pre_run_hook()
- framework.test.Test.OPTS = opts
+ Test.OPTS = opts
chunksize = 1
diff --git a/framework/test/__init__.py b/framework/test/__init__.py
index 011416e..89801b1 100644
--- a/framework/test/__init__.py
+++ b/framework/test/__init__.py
@@ -20,7 +20,11 @@
""" Module that provides test classes and helpers """
-from .exectest import *
+# By importing every exported function from each module in the package we
+# create a general use API, but allow it to be controlled by setting the
+# __all__ in each module
+
+from .piglit_test import *
from .gleantest import *
from .glsl_parser_test import *
from .shader_test import *
diff --git a/framework/test/exectest.py b/framework/test/base.py
similarity index 87%
rename from framework/test/exectest.py
rename to framework/test/base.py
index 0d90094..348568e 100644
--- a/framework/test/exectest.py
+++ b/framework/test/base.py
@@ -34,24 +34,14 @@ import threading
import signal
import itertools
import abc
-try:
- import simplejson as json
-except ImportError:
- import json
from framework.core import Options
from framework.results import TestResult
-__all__ = ['Test',
- 'PiglitTest',
- 'TEST_BIN_DIR']
-
-if 'PIGLIT_BUILD_DIR' in os.environ:
- TEST_BIN_DIR = os.path.join(os.environ['PIGLIT_BUILD_DIR'], 'bin')
-else:
- TEST_BIN_DIR = os.path.normpath(os.path.join(os.path.dirname(__file__),
- '../bin'))
+__all__ = [
+ 'Test',
+]
class ProcessTimeout(threading.Thread):
@@ -343,40 +333,3 @@ class Test(object):
self.result['out'] = out.decode('utf-8', 'replace')
self.result['err'] = err.decode('utf-8', 'replace')
self.result['returncode'] = returncode
-
-
-class PiglitTest(Test):
- """
- PiglitTest: Run a "native" piglit test executable
-
- Expect one line prefixed PIGLIT: in the output, which contains a result
- dictionary. The plain output is appended to this dictionary
- """
- def __init__(self, *args, **kwargs):
- super(PiglitTest, self).__init__(*args, **kwargs)
-
- # Prepend TEST_BIN_DIR to the path.
- self._command[0] = os.path.join(TEST_BIN_DIR, self._command[0])
-
- def is_skip(self):
- """ Native Piglit-test specific skip checking
-
- If the platform for the run doesn't suppoprt 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
- return False
-
- def interpret_result(self):
- outlines = self.result['out'].split('\n')
- outpiglit = (s[7:] for s in outlines if s.startswith('PIGLIT:'))
-
- for piglit in outpiglit:
- self.result.recursive_update(json.loads(piglit))
- self.result['out'] = '\n'.join(
- s for s in outlines if not s.startswith('PIGLIT:'))
diff --git a/framework/test/gleantest.py b/framework/test/gleantest.py
index 7795d1f..6ec285d 100644
--- a/framework/test/gleantest.py
+++ b/framework/test/gleantest.py
@@ -23,7 +23,8 @@
""" Glean support """
import os
-from .exectest import Test, TEST_BIN_DIR
+from .base import Test
+from .piglit_test import TEST_BIN_DIR
__all__ = [
'GleanTest',
diff --git a/framework/test/glsl_parser_test.py b/framework/test/glsl_parser_test.py
index b808a61..77c3ac1 100644
--- a/framework/test/glsl_parser_test.py
+++ b/framework/test/glsl_parser_test.py
@@ -27,7 +27,7 @@ import os.path as path
import re
import sys
-from .exectest import PiglitTest
+from .piglit_test import PiglitTest
__all__ = [
'GLSLParserTest',
diff --git a/framework/test/gtest.py b/framework/test/gtest.py
index ba7926f..81dab38 100644
--- a/framework/test/gtest.py
+++ b/framework/test/gtest.py
@@ -23,7 +23,7 @@
#
import re
-from .exectest import Test
+from .base import Test
__all__ = [
'GTest',
diff --git a/framework/test/oclconform.py b/framework/test/oclconform.py
index 014df6c..9d8bcaf 100644
--- a/framework/test/oclconform.py
+++ b/framework/test/oclconform.py
@@ -30,7 +30,7 @@ from os.path import join
from sys import stderr
from framework.core import PIGLIT_CONFIG
-from .exectest import Test
+from .base import Test
__all__ = [
'OCLConform',
diff --git a/framework/test/piglit_test.py b/framework/test/piglit_test.py
new file mode 100644
index 0000000..0f1f40e
--- /dev/null
+++ b/framework/test/piglit_test.py
@@ -0,0 +1,80 @@
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation
+# files (the "Software"), to deal in the Software without
+# restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following
+# conditions:
+#
+# This permission notice shall be included in all copies or
+# substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+""" Module provides a base class for Tests """
+
+import os
+try:
+ import simplejson as json
+except ImportError:
+ import json
+
+from .base import Test
+
+
+__all__ = [
+ 'PiglitTest',
+ 'TEST_BIN_DIR'
+]
+
+if 'PIGLIT_BUILD_DIR' in os.environ:
+ TEST_BIN_DIR = os.path.join(os.environ['PIGLIT_BUILD_DIR'], 'bin')
+else:
+ TEST_BIN_DIR = os.path.normpath(os.path.join(os.path.dirname(__file__),
+ '../../bin'))
+
+
+class PiglitTest(Test):
+ """
+ PiglitTest: Run a "native" piglit test executable
+
+ Expect one line prefixed PIGLIT: in the output, which contains a result
+ dictionary. The plain output is appended to this dictionary
+ """
+ def __init__(self, *args, **kwargs):
+ super(PiglitTest, self).__init__(*args, **kwargs)
+
+ # Prepend TEST_BIN_DIR to the path.
+ self._command[0] = os.path.join(TEST_BIN_DIR, self._command[0])
+
+ def is_skip(self):
+ """ Native Piglit-test specific skip checking
+
+ If the platform for the run doesn't suppoprt 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
+ return False
+
+ def interpret_result(self):
+ outlines = self.result['out'].split('\n')
+ outpiglit = (s[7:] for s in outlines if s.startswith('PIGLIT:'))
+
+ for piglit in outpiglit:
+ self.result.recursive_update(json.loads(piglit))
+ self.result['out'] = '\n'.join(
+ s for s in outlines if not s.startswith('PIGLIT:'))
diff --git a/framework/test/shader_test.py b/framework/test/shader_test.py
index a3779d0..1ec4930 100644
--- a/framework/test/shader_test.py
+++ b/framework/test/shader_test.py
@@ -27,7 +27,7 @@ import os
import os.path as path
import re
-from .exectest import PiglitTest
+from .piglit_test import PiglitTest
__all__ = [
'ShaderTest',
diff --git a/framework/tests/exectest_test.py b/framework/tests/exectest_test.py
index a334d81..3d7e0e9 100644
--- a/framework/tests/exectest_test.py
+++ b/framework/tests/exectest_test.py
@@ -22,7 +22,8 @@
import nose.tools as nt
import framework.tests.utils as utils
-from framework.test import PiglitTest, Test
+from framework.test import PiglitTest
+from framework.test.base import Test
# Helpers
diff --git a/tests/es3conform.py b/tests/es3conform.py
index 5f7c6c2..2c7e8b8 100644
--- a/tests/es3conform.py
+++ b/tests/es3conform.py
@@ -27,7 +27,8 @@ import sys
from os import path
from glob import glob
from framework.profile import TestProfile
-from framework.test import Test, TEST_BIN_DIR
+from framework.test import TEST_BIN_DIR
+from framework.test.base import Test
__all__ = ['profile']
diff --git a/tests/igt.py b/tests/igt.py
index ae2929c..7794a6a 100644
--- a/tests/igt.py
+++ b/tests/igt.py
@@ -35,7 +35,7 @@ from datetime import datetime
from os import path
import framework.core
from framework.profile import TestProfile
-from framework.test import Test
+from framework.test.base import Test
__all__ = ['profile']
diff --git a/tests/oglconform.py b/tests/oglconform.py
index 80679e4..c7a9554 100644
--- a/tests/oglconform.py
+++ b/tests/oglconform.py
@@ -28,7 +28,7 @@ import subprocess
import framework.core
from framework.profile import TestProfile
-from framework.test import Test
+from framework.test.base import Test
from os import path
__all__ = ['profile']
diff --git a/tests/xts.py b/tests/xts.py
index 8d85674..066afdb 100644
--- a/tests/xts.py
+++ b/tests/xts.py
@@ -30,7 +30,7 @@ import subprocess
import itertools
import framework.core
from framework.profile import TestProfile
-from framework.test import Test
+from framework.test.base import Test
__all__ = ['profile']
--
2.1.2
More information about the Piglit
mailing list