16 self.time = time.gmtime()
17 self.datetime = time.strftime("%Y-%m-%d %H:%M:%S +0000", self.time)
18 self.filename = "results-"+time.strftime("%Y%m%d-%H%M%S", self.time)+".html"
22 <?xml version="1.0" encoding="iso-8859-1" ?>
24 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
25 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
26 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
28 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
29 <title>OMK test report %(datetime)s</title>
36 <table cellpadding='2' border='1'>
39 tests = sorted(self.keys())
44 <h2>Outputs of tests</h2>
47 s+=self[t].toHtmlOutputs()
54 f = file(self.filename, "w+")
55 f.write(self.toHtml())
57 os.remove("results.html")
60 os.symlink(self.filename, "results.html")
61 print "Results written to "+self.filename
63 class TestCaseResult(dict):
64 def __init__(self, tcname):
68 rules = sorted(self.keys())
70 <tr><td colspan='6'><strong>%s</strong></td></tr>
76 def toHtmlOutputs(self):
77 rules = sorted(self.keys())
78 s="<h3>Testcase: %s</h3>" % self.tcname
80 s+=self[r].toHtmlOutputs()
84 def __init__(self, tcname, rules):
89 if self.exitcode == 0: color=''
91 if self.exitcode == 1: color=' bgcolor="red"'
92 elif self.exitcode == 2: color=' bgcolor="yellow"'
93 else: color=' bgcolor="silver"'
94 if self.stdout: stdoutlink="<a href='#stdout-%(tcname)s-%(rules)s'>stdout</a>" % self.__dict__
96 if self.stderr: stderrlink="<a href='#stderr-%(tcname)s-%(rules)s'>stderr</a>" % self.__dict__
101 <td>%(exitcode)d</td>
103 <td>%(time).1f s</td>
104 <td>%(stdoutlink)s</td>
105 <td>%(stderrlink)s</td>
109 'tcname' : self.rules,
110 'rules' : self.rules,
111 'exitcode' : self.exitcode,
112 'message' : self.message,
114 'stdoutlink' : stdoutlink,
115 'stderrlink' : stderrlink,
118 def toHtmlOutputs(self):
120 'tcname':self.tcname,
122 'stdout':self.stdout,
126 if self.stdout: s+="""
127 <a name='stdout-%(tcname)s-%(rules)s'/>
128 <h5>Test %(tcname)s, rules %(rules)s, stdout</h5>
129 <pre>%(stdout)s</pre>""" % vals
130 if self.stderr: s+="""
131 <a name='stderr-%(tcname)s-%(rules)s'/>
132 <h5>Test %(tcname)s, rules %(rules)s, stderr</h5>
133 <pre>%(stderr)s</pre>""" % vals
137 def __init__(self, directory):
138 self.directory = directory # Absolute directory
139 self.name = self._getName()
143 name = self.directory
144 if name.startswith(testsRoot+"/"):
145 name = name[len(testsRoot)+1:]
148 def _whichRules(self):
149 """Reads the rules file and creates the self.rules list of all
153 f = open(os.path.join(self.directory, 'rules'))
155 self.rules = rulesdef.rules.keys()
158 colonMatch = re.search('([^:]*) *: *(.*)', line)
160 if colonMatch.group(1) == "all":
162 self.rules = rulesdef.rules.keys()
163 elif colonMatch.group(1) == "snip":
165 snip = colonMatch.group(2)
166 for r in rulesdef.rules:
167 if snip in rulesdef.rules[r]:
169 elif colonMatch.group(1) == "python":
171 expr = colonMatch.group(2)
172 for r in rulesdef.rules:
173 if eval(expr, {'rules': r, 'snippets': rulesdef.rules[r]}):
177 if line in rulesdef.rules: self.rules = [ line ]
182 self.results = TestCaseResult(self.name)
183 print "Testing %s:" % self.name,
184 os.chdir(os.path.join(testsRoot, self.directory))
185 # if os.path.exists("Makefile.test"):
186 # self._exec = self._execMake
187 if os.path.exists("runtest"):
188 self._exec = self._execRuntest
190 for rules in self.rules:
191 resultEntry = ResultEntry(self.name, rules)
192 self.results[rules] = resultEntry
194 os.environ['OMK_RULES'] = rules
195 filesBefore = self._getFileSet()
196 self._copyRules(rules)
197 self._doRun(resultEntry)
198 filesAfter = self._getFileSet()
199 self._clean(filesBefore, filesAfter)
202 def _getFileSet(self):
204 for f in os.listdir("."):
208 def _clean(self, filesBefore, filesAfter):
209 remove = filesAfter - filesBefore
211 os.system("rm -rf "+f)
213 # def _execMake(self):
214 # return os.system("make -k -f Makefile.test > /dev/null 2>&1")
216 def _execRuntest(self, log):
217 startTime = time.clock()
218 pipe = subprocess.Popen("./runtest", stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
219 endTime = time.clock()
220 (output, errors) = pipe.communicate()
221 ret = pipe.returncode
223 log.time = endTime - startTime
226 if ret != 0 and os.path.exists("_error"):
227 log.message = file("_error").read()
228 else: log.message = ''
232 def _copyRules(self, rules):
233 "Copies the rules to the current directory"
234 src = os.path.join(testsRoot, "..", "rules", rules, "Makefile.rules")
235 shutil.copy(src, ".")
237 def _doRun(self, log):
238 "Runs the teset in current directory."
239 ret = self._exec(log)
243 testsRoot = os.path.dirname(os.path.abspath(__file__))
244 if not os.path.exists(os.path.join(testsRoot, "runtests.py")): raise "Can't find tests root directory!"
248 for dirpath, dirnames, filenames in os.walk(testsRoot):
249 if not ("Makefile.test" in filenames or \
250 "runtest" in filenames):
252 t = TestCase(dirpath)
254 results[t.name] = t.results
260 # compile-command: "python runtests.py"