OLD | NEW |
1 # Copyright 2012 the V8 project authors. All rights reserved. | 1 # Copyright 2012 the V8 project authors. All rights reserved. |
2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
4 # met: | 4 # met: |
5 # | 5 # |
6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
11 # with the distribution. | 11 # with the distribution. |
12 # * Neither the name of Google Inc. nor the names of its | 12 # * Neither the name of Google Inc. nor the names of its |
13 # contributors may be used to endorse or promote products derived | 13 # contributors may be used to endorse or promote products derived |
14 # from this software without specific prior written permission. | 14 # from this software without specific prior written permission. |
15 # | 15 # |
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 | 28 |
29 from functools import wraps | |
30 import json | 29 import json |
31 import os | 30 import os |
32 import sys | 31 import sys |
33 import time | 32 import time |
34 | 33 |
35 from . import junit_output | 34 from . import junit_output |
36 | 35 |
37 | 36 |
38 ABS_PATH_PREFIX = os.getcwd() + os.sep | 37 ABS_PATH_PREFIX = os.getcwd() + os.sep |
39 | 38 |
40 | 39 |
41 def EscapeCommand(command): | 40 def EscapeCommand(command): |
42 parts = [] | 41 parts = [] |
43 for part in command: | 42 for part in command: |
44 if ' ' in part: | 43 if ' ' in part: |
45 # Escape spaces. We may need to escape more characters for this | 44 # Escape spaces. We may need to escape more characters for this |
46 # to work properly. | 45 # to work properly. |
47 parts.append('"%s"' % part) | 46 parts.append('"%s"' % part) |
48 else: | 47 else: |
49 parts.append(part) | 48 parts.append(part) |
50 return " ".join(parts) | 49 return " ".join(parts) |
51 | 50 |
52 | 51 |
53 class ProgressIndicator(object): | 52 class ProgressIndicator(object): |
54 | 53 |
55 def __init__(self): | 54 def __init__(self): |
56 self.runner = None | 55 self.runner = None |
57 | 56 |
58 def SetRunner(self, runner): | |
59 self.runner = runner | |
60 | |
61 def Starting(self): | 57 def Starting(self): |
62 pass | 58 pass |
63 | 59 |
64 def Done(self): | 60 def Done(self): |
65 pass | 61 pass |
66 | 62 |
67 def AboutToRun(self, test): | 63 def AboutToRun(self, test): |
68 pass | 64 pass |
69 | 65 |
70 def HasRun(self, test, has_unexpected_output): | 66 def HasRun(self, test, has_unexpected_output): |
71 pass | 67 pass |
72 | 68 |
73 def Heartbeat(self): | 69 def Heartbeat(self): |
74 pass | 70 pass |
75 | 71 |
76 def PrintFailureHeader(self, test): | 72 def PrintFailureHeader(self, test): |
77 if test.suite.IsNegativeTest(test): | 73 if test.suite.IsNegativeTest(test): |
78 negative_marker = '[negative] ' | 74 negative_marker = '[negative] ' |
79 else: | 75 else: |
80 negative_marker = '' | 76 negative_marker = '' |
81 print "=== %(label)s %(negative)s===" % { | 77 print "=== %(label)s %(negative)s===" % { |
82 'label': test.GetLabel(), | 78 'label': test.GetLabel(), |
83 'negative': negative_marker | 79 'negative': negative_marker |
84 } | 80 } |
85 | 81 |
86 | 82 |
87 class IndicatorNotifier(object): | |
88 """Holds a list of progress indicators and notifies them all on events.""" | |
89 def __init__(self): | |
90 self.indicators = [] | |
91 | |
92 def Register(self, indicator): | |
93 self.indicators.append(indicator) | |
94 | |
95 | |
96 # Forge all generic event-dispatching methods in IndicatorNotifier, which are | |
97 # part of the ProgressIndicator interface. | |
98 for func_name in ProgressIndicator.__dict__: | |
99 func = getattr(ProgressIndicator, func_name) | |
100 if callable(func) and not func.__name__.startswith('_'): | |
101 def wrap_functor(f): | |
102 @wraps(f) | |
103 def functor(self, *args, **kwargs): | |
104 """Generic event dispatcher.""" | |
105 for indicator in self.indicators: | |
106 getattr(indicator, f.__name__)(*args, **kwargs) | |
107 return functor | |
108 setattr(IndicatorNotifier, func_name, wrap_functor(func)) | |
109 | |
110 | |
111 class SimpleProgressIndicator(ProgressIndicator): | 83 class SimpleProgressIndicator(ProgressIndicator): |
112 """Abstract base class for {Verbose,Dots}ProgressIndicator""" | 84 """Abstract base class for {Verbose,Dots}ProgressIndicator""" |
113 | 85 |
114 def Starting(self): | 86 def Starting(self): |
115 print 'Running %i tests' % self.runner.total | 87 print 'Running %i tests' % self.runner.total |
116 | 88 |
117 def Done(self): | 89 def Done(self): |
118 print | 90 print |
119 for failed in self.runner.failed: | 91 for failed in self.runner.failed: |
120 self.PrintFailureHeader(failed) | 92 self.PrintFailureHeader(failed) |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 'stderr': '%s', | 244 'stderr': '%s', |
273 } | 245 } |
274 super(MonochromeProgressIndicator, self).__init__(templates) | 246 super(MonochromeProgressIndicator, self).__init__(templates) |
275 | 247 |
276 def ClearLine(self, last_line_length): | 248 def ClearLine(self, last_line_length): |
277 print ("\r" + (" " * last_line_length) + "\r"), | 249 print ("\r" + (" " * last_line_length) + "\r"), |
278 | 250 |
279 | 251 |
280 class JUnitTestProgressIndicator(ProgressIndicator): | 252 class JUnitTestProgressIndicator(ProgressIndicator): |
281 | 253 |
282 def __init__(self, junitout, junittestsuite): | 254 def __init__(self, progress_indicator, junitout, junittestsuite): |
| 255 self.progress_indicator = progress_indicator |
283 self.outputter = junit_output.JUnitTestOutput(junittestsuite) | 256 self.outputter = junit_output.JUnitTestOutput(junittestsuite) |
284 if junitout: | 257 if junitout: |
285 self.outfile = open(junitout, "w") | 258 self.outfile = open(junitout, "w") |
286 else: | 259 else: |
287 self.outfile = sys.stdout | 260 self.outfile = sys.stdout |
288 | 261 |
| 262 def Starting(self): |
| 263 self.progress_indicator.runner = self.runner |
| 264 self.progress_indicator.Starting() |
| 265 |
289 def Done(self): | 266 def Done(self): |
| 267 self.progress_indicator.Done() |
290 self.outputter.FinishAndWrite(self.outfile) | 268 self.outputter.FinishAndWrite(self.outfile) |
291 if self.outfile != sys.stdout: | 269 if self.outfile != sys.stdout: |
292 self.outfile.close() | 270 self.outfile.close() |
293 | 271 |
| 272 def AboutToRun(self, test): |
| 273 self.progress_indicator.AboutToRun(test) |
| 274 |
294 def HasRun(self, test, has_unexpected_output): | 275 def HasRun(self, test, has_unexpected_output): |
| 276 self.progress_indicator.HasRun(test, has_unexpected_output) |
295 fail_text = "" | 277 fail_text = "" |
296 if has_unexpected_output: | 278 if has_unexpected_output: |
297 stdout = test.output.stdout.strip() | 279 stdout = test.output.stdout.strip() |
298 if len(stdout): | 280 if len(stdout): |
299 fail_text += "stdout:\n%s\n" % stdout | 281 fail_text += "stdout:\n%s\n" % stdout |
300 stderr = test.output.stderr.strip() | 282 stderr = test.output.stderr.strip() |
301 if len(stderr): | 283 if len(stderr): |
302 fail_text += "stderr:\n%s\n" % stderr | 284 fail_text += "stderr:\n%s\n" % stderr |
303 fail_text += "Command: %s" % EscapeCommand(self.runner.GetCommand(test)) | 285 fail_text += "Command: %s" % EscapeCommand(self.runner.GetCommand(test)) |
304 if test.output.HasCrashed(): | 286 if test.output.HasCrashed(): |
305 fail_text += "exit code: %d\n--- CRASHED ---" % test.output.exit_code | 287 fail_text += "exit code: %d\n--- CRASHED ---" % test.output.exit_code |
306 if test.output.HasTimedOut(): | 288 if test.output.HasTimedOut(): |
307 fail_text += "--- TIMEOUT ---" | 289 fail_text += "--- TIMEOUT ---" |
308 self.outputter.HasRunTest( | 290 self.outputter.HasRunTest( |
309 [test.GetLabel()] + self.runner.context.mode_flags + test.flags, | 291 [test.GetLabel()] + self.runner.context.mode_flags + test.flags, |
310 test.duration, | 292 test.duration, |
311 fail_text) | 293 fail_text) |
312 | 294 |
| 295 def Heartbeat(self): |
| 296 self.progress_indicator.Heartbeat() |
313 | 297 |
314 class JsonTestProgressIndicator(ProgressIndicator): | 298 class JsonTestProgressIndicator(ProgressIndicator): |
315 | 299 |
316 def __init__(self, json_test_results, arch, mode): | 300 def __init__(self, progress_indicator, json_test_results, arch, mode): |
| 301 self.progress_indicator = progress_indicator |
317 self.json_test_results = json_test_results | 302 self.json_test_results = json_test_results |
318 self.arch = arch | 303 self.arch = arch |
319 self.mode = mode | 304 self.mode = mode |
320 self.results = [] | 305 self.results = [] |
321 self.tests = [] | 306 self.tests = [] |
322 | 307 |
| 308 def Starting(self): |
| 309 self.progress_indicator.runner = self.runner |
| 310 self.progress_indicator.Starting() |
| 311 |
323 def Done(self): | 312 def Done(self): |
| 313 self.progress_indicator.Done() |
324 complete_results = [] | 314 complete_results = [] |
325 if os.path.exists(self.json_test_results): | 315 if os.path.exists(self.json_test_results): |
326 with open(self.json_test_results, "r") as f: | 316 with open(self.json_test_results, "r") as f: |
327 # Buildbot might start out with an empty file. | 317 # Buildbot might start out with an empty file. |
328 complete_results = json.loads(f.read() or "[]") | 318 complete_results = json.loads(f.read() or "[]") |
329 | 319 |
330 # Sort tests by duration. | 320 # Sort tests by duration. |
331 timed_tests = [t for t in self.tests if t.duration is not None] | 321 timed_tests = [t for t in self.tests if t.duration is not None] |
332 timed_tests.sort(lambda a, b: cmp(b.duration, a.duration)) | 322 timed_tests.sort(lambda a, b: cmp(b.duration, a.duration)) |
333 slowest_tests = [ | 323 slowest_tests = [ |
334 { | 324 { |
335 "name": test.GetLabel(), | 325 "name": test.GetLabel(), |
336 "flags": test.flags, | 326 "flags": test.flags, |
337 "command": EscapeCommand(self.runner.GetCommand(test)).replace( | 327 "command": EscapeCommand(self.runner.GetCommand(test)).replace( |
338 ABS_PATH_PREFIX, ""), | 328 ABS_PATH_PREFIX, ""), |
339 "duration": test.duration, | 329 "duration": test.duration, |
340 } for test in timed_tests[:20] | 330 } for test in timed_tests[:20] |
341 ] | 331 ] |
342 | 332 |
343 complete_results.append({ | 333 complete_results.append({ |
344 "arch": self.arch, | 334 "arch": self.arch, |
345 "mode": self.mode, | 335 "mode": self.mode, |
346 "results": self.results, | 336 "results": self.results, |
347 "slowest_tests": slowest_tests, | 337 "slowest_tests": slowest_tests, |
348 }) | 338 }) |
349 | 339 |
350 with open(self.json_test_results, "w") as f: | 340 with open(self.json_test_results, "w") as f: |
351 f.write(json.dumps(complete_results)) | 341 f.write(json.dumps(complete_results)) |
352 | 342 |
| 343 def AboutToRun(self, test): |
| 344 self.progress_indicator.AboutToRun(test) |
| 345 |
353 def HasRun(self, test, has_unexpected_output): | 346 def HasRun(self, test, has_unexpected_output): |
| 347 self.progress_indicator.HasRun(test, has_unexpected_output) |
354 # Buffer all tests for sorting the durations in the end. | 348 # Buffer all tests for sorting the durations in the end. |
355 self.tests.append(test) | 349 self.tests.append(test) |
356 if not has_unexpected_output: | 350 if not has_unexpected_output: |
357 # Omit tests that run as expected. Passing tests of reruns after failures | 351 # Omit tests that run as expected. Passing tests of reruns after failures |
358 # will have unexpected_output to be reported here has well. | 352 # will have unexpected_output to be reported here has well. |
359 return | 353 return |
360 | 354 |
361 self.results.append({ | 355 self.results.append({ |
362 "name": test.GetLabel(), | 356 "name": test.GetLabel(), |
363 "flags": test.flags, | 357 "flags": test.flags, |
364 "command": EscapeCommand(self.runner.GetCommand(test)).replace( | 358 "command": EscapeCommand(self.runner.GetCommand(test)).replace( |
365 ABS_PATH_PREFIX, ""), | 359 ABS_PATH_PREFIX, ""), |
366 "run": test.run, | 360 "run": test.run, |
367 "stdout": test.output.stdout, | 361 "stdout": test.output.stdout, |
368 "stderr": test.output.stderr, | 362 "stderr": test.output.stderr, |
369 "exit_code": test.output.exit_code, | 363 "exit_code": test.output.exit_code, |
370 "result": test.suite.GetOutcome(test), | 364 "result": test.suite.GetOutcome(test), |
371 "expected": list(test.outcomes or ["PASS"]), | 365 "expected": list(test.outcomes or ["PASS"]), |
372 "duration": test.duration, | 366 "duration": test.duration, |
373 }) | 367 }) |
374 | 368 |
| 369 def Heartbeat(self): |
| 370 self.progress_indicator.Heartbeat() |
| 371 |
375 | 372 |
376 PROGRESS_INDICATORS = { | 373 PROGRESS_INDICATORS = { |
377 'verbose': VerboseProgressIndicator, | 374 'verbose': VerboseProgressIndicator, |
378 'dots': DotsProgressIndicator, | 375 'dots': DotsProgressIndicator, |
379 'color': ColorProgressIndicator, | 376 'color': ColorProgressIndicator, |
380 'mono': MonochromeProgressIndicator | 377 'mono': MonochromeProgressIndicator |
381 } | 378 } |
OLD | NEW |