summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2012-04-20 01:43:09 -0700
committerKenneth Graunke <kenneth@whitecape.org>2012-04-20 01:43:09 -0700
commitefb54763df0c3baee75f7eeffe34400abc342210 (patch)
tree29879e3d5ec512b8959cffe007d8a6b488044cc1
parent6b540bf02c1dbc4be6d03bebc34ae6a1d774387a (diff)
Use XML for the test suite description. It's much nicer!
Still not sure about XML for the test list, so it's JSON for now.
-rw-r--r--framework/xsuite.py141
1 files changed, 141 insertions, 0 deletions
diff --git a/framework/xsuite.py b/framework/xsuite.py
new file mode 100644
index 0000000..f85a84f
--- /dev/null
+++ b/framework/xsuite.py
@@ -0,0 +1,141 @@
+#
+# Copyright © 2012 Intel Corporation
+#
+# 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:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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 json
+import xml.etree.ElementTree as ET
+import os.path as path
+import re
+
+#import framework.test
+
+#__all__ = ['TestSuite', 'TestKind']
+
+kinds = {}
+
+class TestSuite:
+ """
+ Description of a test suite.
+
+ For now, this contains the following information:
+ - Name
+ - Description
+ - List of registered TestKinds
+ - Absolute path to the XML test list file
+ - Dictionary of tests
+ """
+ def __init__(self, xmlFile):
+ tree = ET.parse(xmlFile)
+ xmlSuite = tree.getroot()
+
+ self.name = xmlSuite.attrib['name']
+ self.description = xmlSuite.attrib['description']
+ self.testlist_file = path.abspath(path.join(path.dirname(xmlFile.name), xmlSuite.attrib['tests']))
+ self.kinds = {}
+ for xmlKind in xmlSuite[0]:
+ self.kinds[xmlKind.attrib['tag']] = TestKind(xmlKind)
+
+ # Register the kinds...
+ kinds.update(self.kinds)
+
+ self.tests = {}
+
+class TestKind:
+ """
+ Description of a class of tests (e.g. Piglit's ExecTest, GleanTest, ...).
+
+ Robyn needs to know several facts about tests:
+ - How to invoke them
+ - How to interpret results
+ - How to pass specific flags such as platform, quick mode, and so on.
+
+ Test suites may register several different types of tests. In the
+ JSON test list, the "type" tag indicates what kind of test it is.
+ """
+ def __init__(self, xmlKind):
+ xmlResult = xmlKind.find('result')
+
+ self.default_result = xmlResult.attrib['default']
+ self.regexs = {}
+ for rx in xmlResult:
+ self.regexs[rx.attrib['status']] = re.compile(rx.text)
+
+ # XXX: parse <platforms> and <quick>
+
+ # Register this Kind so it's available
+ # XXX: may want to move this into the caller...or caller's caller
+ #assert name not in kinds
+ #kinds[name] = self
+
+ def interpretResult(self):
+ #for status, re in self.regexs.items():
+ #if re.search(out) is not None:
+ #result = status
+ #break
+ result = self.default_result
+
+def availableSuites():
+ """
+ Read the ~/.robynrc file and fetch a list of available test suites.
+
+ Returns a dictionary whose keys are suite names, and whose items are
+ absolute paths to the JSON suite description file.
+
+ Does not create TestSuite objects and populate the test suite information.
+ """
+ # XXX: load list of available suites from ~/.robynrc or such
+ return {'piglit': '/home/kwg/Projects/piglit/robyn-suite.xml'}
+
+### [str] x bool -> {str -> TestSuite}
+def loadSuiteInfo(desiredSuites, loadTests):
+ """
+ Load TestSuite descriptions for a list of requested suites.
+ """
+ suiteFiles = availableSuites()
+
+ suiteInfo = {}
+
+ for name in desiredSuites:
+ if name not in suiteFiles:
+ print('error: unknown test suite "%s".\n' % name)
+ print(' Available Suites:')
+ for s in suiteFiles.keys():
+ print(' -', s)
+ return {}
+
+ with open(suiteFiles[name], 'r') as fp:
+ suiteInfo[name] = TestSuite(fp)
+
+ if loadTests:
+ loadTestList(suiteInfo[name])
+
+ return suiteInfo
+
+### TestSuite -> None
+def loadTestList(suite):
+ """Actually load the tests."""
+
+ with open(suite.testlist_file) as fp:
+ js = json.load(fp)
+
+ suite.tests = js
+
+ return None