This module contains the testBinDir variable and the Environment class, and is meant to hold environment settings for piglit
Signed-off-by: Dylan Baker <[email protected]> --- framework/core.py | 81 +--------------------------------- framework/environment.py | 100 ++++++++++++++++++++++++++++++++++++++++++ framework/exectest.py | 3 +- framework/gleantest.py | 3 +- framework/glsl_parser_test.py | 3 +- framework/shader_test.py | 3 +- piglit-print-commands.py | 5 ++- piglit-resume.py | 16 ++++--- piglit-run.py | 13 +++--- tests/es3conform.py | 3 +- tests/igt.py | 3 +- tests/oglconfirm.py | 3 +- 12 files changed, 135 insertions(+), 101 deletions(-) create mode 100644 framework/environment.py diff --git a/framework/core.py b/framework/core.py index 33946a7..64eda58 100644 --- a/framework/core.py +++ b/framework/core.py @@ -46,16 +46,14 @@ except ImportError: import status -__all__ = ['Environment', - 'checkDir', +__all__ = ['checkDir', 'loadTestProfile', 'TestrunResult', 'GroupResult', 'TestResult', 'TestProfile', 'Group', - 'Test', - 'testBinDir'] + 'Test'] class PiglitJSONEncoder(json.JSONEncoder): @@ -212,26 +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 -# trying to debug applications that should execute correctly. But for -# piglit we expect to generate errors regularly as part of testing, -# and for exhaustive error-generation tests (particularly some in -# khronos's conformance suite), it can end up ooming your system -# trying to parse the strings. -if 'MESA_DEBUG' not in os.environ: - os.environ['MESA_DEBUG'] = 'silent' class TestResult(dict): @@ -396,61 +374,6 @@ class TestrunResult: json.dump(raw_dict, file, indent=JSONWriter.INDENT) -class Environment: - def __init__(self, concurrent=True, execute=True, include_filter=[], - exclude_filter=[], valgrind=False, dmesg=False): - self.concurrent = concurrent - self.execute = execute - self.filter = [] - self.exclude_filter = [] - self.exclude_tests = set() - self.valgrind = valgrind - self.dmesg = dmesg - - """ - The filter lists that are read in should be a list of string objects, - however, the filters need to be a list or regex object. - - This code uses re.compile to rebuild the lists and set self.filter - """ - for each in include_filter: - self.filter.append(re.compile(each)) - for each in exclude_filter: - self.exclude_filter.append(re.compile(each)) - - def __iter__(self): - for key, values in self.__dict__.iteritems(): - # If the values are regex compiled then yield their pattern - # attribute, which is the original plaintext they were compiled - # from, otherwise yield them normally. - if key in ['filter', 'exclude_filter']: - yield (key, [x.pattern for x in values]) - else: - yield (key, values) - - def run(self, command): - try: - p = subprocess.Popen(command, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True) - (stdout, stderr) = p.communicate() - except: - return "Failed to run " + command - return stderr+stdout - - def collectData(self): - result = {} - system = platform.system() - if (system == 'Windows' or system.find("CYGWIN_NT") == 0): - result['wglinfo'] = self.run('wglinfo') - else: - result['glxinfo'] = self.run('glxinfo') - if system == 'Linux': - result['lspci'] = self.run('lspci') - return result - - class Test(object): def __init__(self, runConcurrent=False): ''' diff --git a/framework/environment.py b/framework/environment.py new file mode 100644 index 0000000..e46a6cb --- /dev/null +++ b/framework/environment.py @@ -0,0 +1,100 @@ +# 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. + + +import os +import os.path as path +import re +import subprocess +import platform + +__all__ = ['Environment', + 'testBinDir'] + +if 'PIGLIT_BUILD_DIR' in os.environ: + testBinDir = path.join(environ['PIGLIT_BUILD_DIR'], 'bin') +else: + testBinDir = path.normpath(path.join(path.dirname(__file__), '../bin')) + +if 'PIGLIT_SOURCE_DIR' not in os.environ: + os.environ['PIGLIT_SOURCE_DIR'] = path.abspath( + path.join(path.dirname(__file__), '..')) + +# In debug builds, Mesa will by default log GL API errors to stderr. +# This is useful for application developers or driver developers +# trying to debug applications that should execute correctly. But for +# piglit we expect to generate errors regularly as part of testing, +# and for exhaustive error-generation tests (particularly some in +# khronos's conformance suite), it can end up ooming your system +# trying to parse the strings. +if 'MESA_DEBUG' not in os.environ: + os.environ['MESA_DEBUG'] = 'silent' + + +class Environment: + def __init__(self, concurrent=True, execute=True, include_filter=[], + exclude_filter=[], valgrind=False, dmesg=False): + self.concurrent = concurrent + self.execute = execute + self.filter = [] + self.exclude_filter = [] + self.exclude_tests = set() + self.valgrind = valgrind + self.dmesg = dmesg + + """ + The filter lists that are read in should be a list of string objects, + however, the filters need to be a list or regex object. + + This code uses re.compile to rebuild the lists and set self.filter + """ + for each in include_filter: + self.filter.append(re.compile(each)) + for each in exclude_filter: + self.exclude_filter.append(re.compile(each)) + + def __iter__(self): + for key, values in self.__dict__.iteritems(): + # If the values are regex compiled then yield their pattern + # attribute, which is the original plaintext they were compiled + # from, otherwise yield them normally. + if key in ['filter', 'exclude_filter']: + yield (key, [x.pattern for x in values]) + else: + yield (key, values) + + def run(self, command): + try: + p = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True) + (stdout, stderr) = p.communicate() + except: + return "Failed to run " + command + return stderr+stdout + + def collectData(self): + result = {} + system = platform.system() + if (system == 'Windows' or system.find("CYGWIN_NT") == 0): + result['wglinfo'] = self.run('wglinfo') + else: + result['glxinfo'] = self.run('glxinfo') + if system == 'Linux': + result['lspci'] = self.run('lspci') + return result diff --git a/framework/exectest.py b/framework/exectest.py index 15dd966..493a57b 100644 --- a/framework/exectest.py +++ b/framework/exectest.py @@ -28,7 +28,8 @@ import shlex import types import re -from core import Test, testBinDir, TestResult +from core import Test, TestResult +from framework.environment import testBinDir # Platform global variables diff --git a/framework/gleantest.py b/framework/gleantest.py index d115c03..899bd6e 100644 --- a/framework/gleantest.py +++ b/framework/gleantest.py @@ -24,7 +24,8 @@ import os import subprocess -from core import checkDir, testBinDir, Test, TestResult +from core import checkDir, Test, TestResult +from framework.environment import testBinDir from exectest import ExecTest glean_executable = os.path.join(testBinDir, "glean") diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py index 91f59cb..e51f2f8 100755 --- a/framework/glsl_parser_test.py +++ b/framework/glsl_parser_test.py @@ -39,7 +39,8 @@ import subprocess import sys from ConfigParser import SafeConfigParser -from core import Test, testBinDir, TestResult +from core import Test, TestResult +from framework.environment import testBinDir from cStringIO import StringIO from exectest import PlainExecTest diff --git a/framework/shader_test.py b/framework/shader_test.py index aebb5d7..67ce13f 100755 --- a/framework/shader_test.py +++ b/framework/shader_test.py @@ -34,8 +34,9 @@ import re import sys import textwrap -from core import testBinDir, Group, Test, TestResult, Environment +from core import Group, Test, TestResult from exectest import PlainExecTest +from framework.environment import testBinDir, Environment """This module enables running shader tests. diff --git a/piglit-print-commands.py b/piglit-print-commands.py index c42ea6d..9dab54b 100755 --- a/piglit-print-commands.py +++ b/piglit-print-commands.py @@ -31,6 +31,7 @@ import traceback sys.path.append(path.dirname(path.realpath(sys.argv[0]))) import framework.core as core +import framework.environment as environment from framework.exectest import ExecTest from framework.gleantest import GleanTest @@ -54,8 +55,8 @@ def main(): args = parser.parse_args() # Set the environment, pass in the included and excluded tests - env = core.Environment(exclude_filter=args.exclude_tests, - include_filter=args.include_tests) + env = environment.Environment(exclude_filter=args.exclude_tests, + include_filter=args.include_tests) # Change to the piglit's path piglit_dir = path.dirname(path.realpath(sys.argv[0])) diff --git a/piglit-resume.py b/piglit-resume.py index c6b9b1e..d0bf4f7 100755 --- a/piglit-resume.py +++ b/piglit-resume.py @@ -27,6 +27,7 @@ import os.path as path import argparse import framework.core as core +import framework.environment as environment def main(): @@ -38,13 +39,14 @@ def main(): args = parser.parse_args() results = core.load_results(args.results_path) - env = core.Environment(concurrent=results.options['concurrent'], - exclude_filter=results.options['exclude_filter'], - include_filter=results.options['filter'], - execute=results.options['execute'], - valgrind=results.options['valgrind'], - dmesg=results.options['dmesg']) - + env = environment.Environment( + concurrent=results.options['concurrent'], + exclude_filter=results.options['exclude_filter'], + include_filter=results.options['filter'], + execute=results.options['execute'], + valgrind=results.options['valgrind'], + dmesg=results.options['dmesg']) + # Change working directory to the piglit directory os.chdir(path.dirname(path.realpath(sys.argv[0]))) diff --git a/piglit-run.py b/piglit-run.py index cf19073..aeb6a1f 100755 --- a/piglit-run.py +++ b/piglit-run.py @@ -31,6 +31,7 @@ import traceback sys.path.append(path.dirname(path.realpath(sys.argv[0]))) import framework.core as core +import framework.environment as environment from framework.threads import synchronized_self @@ -94,12 +95,12 @@ def main(): os.environ['PIGLIT_PLATFORM'] = args.platform # Pass arguments into Environment - env = core.Environment(concurrent=args.concurrency, - exclude_filter=args.exclude_tests, - include_filter=args.include_tests, - execute=args.execute, - valgrind=args.valgrind, - dmesg=args.dmesg) + env = environment.Environment(concurrent=args.concurrency, + exclude_filter=args.exclude_tests, + include_filter=args.include_tests, + execute=args.execute, + valgrind=args.valgrind, + dmesg=args.dmesg) # Change working directory to the root of the piglit directory piglit_dir = path.dirname(path.realpath(sys.argv[0])) diff --git a/tests/es3conform.py b/tests/es3conform.py index 1995a9c..307a3aa 100644 --- a/tests/es3conform.py +++ b/tests/es3conform.py @@ -26,7 +26,8 @@ import sys from os import path from glob import glob -from framework.core import TestProfile, testBinDir +from framework.core import TestProfile +from framework.environment import testBinDir from framework.exectest import ExecTest __all__ = ['profile'] diff --git a/tests/igt.py b/tests/igt.py index 5f52e49..c76b242 100644 --- a/tests/igt.py +++ b/tests/igt.py @@ -28,7 +28,8 @@ import sys import subprocess from os import path -from framework.core import testBinDir, TestProfile, TestResult +from framework.core import TestProfile, TestResult +from framework.environment import testBinDir from framework.exectest import ExecTest __all__ = ['profile'] diff --git a/tests/oglconfirm.py b/tests/oglconfirm.py index b9b79b8..82c6963 100644 --- a/tests/oglconfirm.py +++ b/tests/oglconfirm.py @@ -26,7 +26,8 @@ import re import sys import subprocess -from framework.core import TestProfile, testBinDir +from framework.core import TestProfile +from framework.environment import testBinDir from framework.exectest import ExecTest from os import path -- 1.8.5.3 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
