ia64/xen-unstable

view tools/xm-test/lib/XmTestReport/ResultReport.py @ 7757:139aabe357a4

Various chmod a+x.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Thu Nov 10 12:00:09 2005 +0100 (2005-11-10)
parents ecb5997f7b25
children
line source
1 #!/usr/bin/python
3 """
4 ResultReport.py - Handles the gathering and xml-formatting of xm-test
5 results
7 Copyright (C) International Business Machines Corp., 2005
8 Author: Dan Smith <danms@us.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; under version 2 of the License.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 """
25 import utils
27 import re
29 class Test:
31 def __init__(self, name, state, seq):
32 self.vars = {}
33 self.vars["name"] = name
34 self.vars["state"] = state
35 self.vars["log"] = "NO LOG SUPPLIED"
36 self.vars["seq"] = str(seq)
38 def setLog(self, log):
39 self.vars["log"] = log
41 def __str__(self):
42 string = "<test>\n"
44 for k in self.vars.keys():
45 string += " " + utils.tagify(k, self.vars[k]) + "\n"
47 string += "</test>\n"
49 return string
51 class TestGroup:
53 def __init__(self, name):
54 self.name = name
55 self.tests = []
57 def addTest(self, test):
58 self.tests.append(test)
60 def __str__(self):
61 string = "<group>\n"
62 string += " <name>%s</name>\n" % self.name
64 for t in self.tests:
65 string += str(t)
67 string += "</group>\n"
69 return string
71 class ResultSet:
73 def __init__(self):
74 self.groups = []
76 def addGroup(self, group):
77 self.groups.append(group)
79 def __str__(self):
80 string = "<results>\n"
82 for g in self.groups:
83 string += str(g)
85 string += "</results>\n"
87 return string
89 class ResultParser:
91 def __init__(self):
92 self.groups = {}
93 self.resultSet = None
95 def __isImportant(self, line):
97 if re.search("^[Mm]ak(e|ing)", line):
98 return False
99 if re.search("^===", line):
100 return False
101 if re.search("^All [0-9]+ tests", line):
102 return False
103 if re.search("^[0-9]+ of [0-9]+ tests", line):
104 return False
105 if re.search("^cp [0-9]+_", line):
106 return False
107 if re.search("^chmod \+x [0-9]+_", line):
108 return False
110 return True
112 def parse(self, fileName):
113 output = file(fileName);
114 contents = output.read()
116 lines = contents.split("\n")
118 sequence = 0
119 currentLog = ""
120 for l in lines:
121 match = re.match("^(PASS|FAIL|XPASS|XFAIL|SKIP): ([0-9]+)_([^_]+)_([^\.]+)\.test$", l)
122 if match:
123 # End of current test; build object
124 testStatus = match.group(1)
125 testNumber = match.group(2)
126 testGroup = match.group(3)
127 testName = match.group(4)
129 if not testGroup in self.groups.keys():
130 self.groups[testGroup] = TestGroup(testGroup)
132 test = Test("%s_%s" % (testNumber, testName), testStatus,
133 sequence)
134 sequence += 1
135 test.setLog(currentLog)
136 self.groups[testGroup].addTest(test)
138 currentLog = ""
140 else:
141 if self.__isImportant(l):
142 currentLog += l + "\n"
144 self.resultSet = ResultSet()
146 for g in self.groups:
147 self.resultSet.addGroup(self.groups[g])
149 return self.resultSet
151 if __name__ == "__main__":
153 import sys
155 r = ResultParser()
157 print str(r.parse(sys.argv[1]))