diff options
author | Nicolai Haehnle <nhaehnle@gmail.com> | 2007-03-25 20:22:56 +0200 |
---|---|---|
committer | Nicolai Haehnle <nhaehnle@gmail.com> | 2007-03-25 20:22:56 +0200 |
commit | a6bd6fcd55faf118afd17328846c697d4b115315 (patch) | |
tree | f0bb27943b38d3c9b9e8d6188c3c04bbf8fb48a9 /framework | |
parent | 42dd1e8493690273fbb00533318cbb911dabb3c2 (diff) |
Refactoring
Diffstat (limited to 'framework')
-rw-r--r-- | framework/core.py | 125 | ||||
-rw-r--r-- | framework/exectest.py | 75 | ||||
-rw-r--r-- | framework/gleantest.py | 79 |
3 files changed, 174 insertions, 105 deletions
diff --git a/framework/core.py b/framework/core.py index 8d47a0a77..1f354deae 100644 --- a/framework/core.py +++ b/framework/core.py @@ -32,10 +32,16 @@ import traceback __all__ = [ 'Environment', + 'checkDir', 'loadTestProfile', 'testPathToResultName', + 'TestrunResult', 'GroupResult', - 'TestResult' + 'TestResult', + 'TestProfile', + 'Group', + 'Test', + 'testBinDir' ] @@ -67,13 +73,13 @@ def testPathToResultName(path): pyname = 'testrun.results' + "".join(map(lambda s: "['"+s+"']", elems)) return pyname -testbin = os.path.dirname(__file__) + '/../bin/' +testBinDir = os.path.dirname(__file__) + '/../bin/' + ############################################################################# ##### Result classes ############################################################################# - class TestResult(dict): def __init__(self, *args): dict.__init__(self) @@ -132,9 +138,13 @@ class Environment: self.execute = True self.filter = [] + class Test: ignoreErrors = [] + def __init__(self): + pass + def doRun(self, env, path): # Filter if len(env.filter) > 0: @@ -205,101 +215,13 @@ class Group(dict): spath = path + '/' + spath self[sub].doRun(env, spath) -############################################################################# -##### PlainExecTest: Simply run an executable -##### Expect one line prefixed PIGLIT: in the output, which contains a -##### result dictionary. The plain output is appended to this dictionary -############################################################################# -class PlainExecTest(Test): - def __init__(self, command): - self.command = command - - def run(self): - proc = subprocess.Popen( - self.command, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE - ) - out,err = proc.communicate() - - outlines = out.split('\n') - outpiglit = map(lambda s: s[7:], filter(lambda s: s.startswith('PIGLIT:'), outlines)) - - results = TestResult() - - if len(outpiglit) > 0: - try: - results.update(eval(''.join(outpiglit), {})) - out = '\n'.join(filter(lambda s: not s.startswith('PIGLIT:'), outlines)) - except: - results['result'] = 'fail' - results['note'] = 'Failed to parse result string' - - if 'result' not in results: - results['result'] = 'fail' - - if proc.returncode != 0: - results['result'] = 'fail' - results['note'] = 'Returncode was %d' % (proc.returncode) - - self.handleErr(results, err) - - results['info'] = "@@@Returncode: %d\n\nErrors:\n%s\n\nOutput:\n%s" % (proc.returncode, err, out) - results['returncode'] = proc.returncode - - return results - +class TestProfile: + def __init__(self): + self.tests = Group() -############################################################################# -##### GleanTest: Execute a sub-test of Glean -############################################################################# -def gleanExecutable(): - return testbin + 'glean' - -def gleanResultDir(): - return "./results/glean/" - -class GleanTest(Test): - globalParams = [] - - def __init__(self, name): - self.name = name - self.env = {} - - def run(self): - results = TestResult() - - fullenv = os.environ.copy() - for e in self.env: - fullenv[e] = str(self.env[e]) - - checkDir(gleanResultDir()+self.name, False) - - glean = subprocess.Popen( - [gleanExecutable(), "-o", "-r", gleanResultDir()+self.name, - "--ignore-prereqs", - "-v", "-v", "-v", - "-t", "+"+self.name] + GleanTest.globalParams, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - env=fullenv - ) - - out, err = glean.communicate() - - results['result'] = 'pass' - if glean.returncode != 0 or out.find('FAIL') >= 0: - results['result'] = 'fail' - - results['returncode'] = glean.returncode - - self.handleErr(results, err) - - results['info'] = "@@@Returncode: %d\n\nErrors:\n%s\n\nOutput:\n%s" % (glean.returncode, err, out) - - return results - + def run(self, env): + self.tests.doRun(env, '') ############################################################################# ##### Loaders @@ -309,16 +231,9 @@ def loadTestProfile(filename): try: ns = { '__file__': filename, - '__dir__': os.path.dirname(filename), - 'testbin': testbin, - 'Test': Test, - 'Group': Group, - 'GleanTest': GleanTest, - 'gleanExecutable': gleanExecutable, - 'PlainExecTest': PlainExecTest } execfile(filename, ns) - return ns['tests'] + return ns['profile'] except: traceback.print_exc() raise Exception('Could not read tests profile') @@ -326,7 +241,7 @@ def loadTestProfile(filename): def loadTestResults(filename): try: ns = { - '__file__': filename, +# '__file__': filename, 'GroupResult': GroupResult, 'TestResult': TestResult, 'TestrunResult': TestrunResult diff --git a/framework/exectest.py b/framework/exectest.py new file mode 100644 index 000000000..43e655952 --- /dev/null +++ b/framework/exectest.py @@ -0,0 +1,75 @@ +#!/usr/bin/python +# +# 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 ALLEN AKIN 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 subprocess +import sys + +from core import * + +############################################################################# +##### PlainExecTest: Simply run an executable +##### Expect one line prefixed PIGLIT: in the output, which contains a +##### result dictionary. The plain output is appended to this dictionary +############################################################################# +class PlainExecTest(Test): + def __init__(self, command): + Test.__init__(self) + self.command = command + + def run(self): + proc = subprocess.Popen( + self.command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + out,err = proc.communicate() + + outlines = out.split('\n') + outpiglit = map(lambda s: s[7:], filter(lambda s: s.startswith('PIGLIT:'), outlines)) + + results = TestResult() + + if len(outpiglit) > 0: + try: + results.update(eval(''.join(outpiglit), {})) + out = '\n'.join(filter(lambda s: not s.startswith('PIGLIT:'), outlines)) + except: + results['result'] = 'fail' + results['note'] = 'Failed to parse result string' + + if 'result' not in results: + results['result'] = 'fail' + + if proc.returncode != 0: + results['result'] = 'fail' + results['note'] = 'Returncode was %d' % (proc.returncode) + + self.handleErr(results, err) + + results['info'] = "@@@Returncode: %d\n\nErrors:\n%s\n\nOutput:\n%s" % (proc.returncode, err, out) + results['returncode'] = proc.returncode + + return results + + diff --git a/framework/gleantest.py b/framework/gleantest.py new file mode 100644 index 000000000..a2883a3cd --- /dev/null +++ b/framework/gleantest.py @@ -0,0 +1,79 @@ +#!/usr/bin/python +# +# 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 ALLEN AKIN 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 subprocess +import sys + +from core import * + +############################################################################# +##### GleanTest: Execute a sub-test of Glean +############################################################################# +def gleanExecutable(): + return testBinDir + 'glean' + +def gleanResultDir(): + return "./results/glean/" + +class GleanTest(Test): + globalParams = [] + + def __init__(self, name): + Test.__init__(self) + self.name = name + self.env = {} + + def run(self): + results = TestResult() + + fullenv = os.environ.copy() + for e in self.env: + fullenv[e] = str(self.env[e]) + + checkDir(gleanResultDir()+self.name, False) + + glean = subprocess.Popen( + [gleanExecutable(), "-o", "-r", gleanResultDir()+self.name, + "--ignore-prereqs", + "-v", "-v", "-v", + "-t", "+"+self.name] + GleanTest.globalParams, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=fullenv + ) + + out, err = glean.communicate() + + results['result'] = 'pass' + if glean.returncode != 0 or out.find('FAIL') >= 0: + results['result'] = 'fail' + + results['returncode'] = glean.returncode + + self.handleErr(results, err) + + results['info'] = "@@@Returncode: %d\n\nErrors:\n%s\n\nOutput:\n%s" % (glean.returncode, err, out) + + return results + |