Chromium Code Reviews| 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 | |
| 29 import json | 30 import json |
| 30 import os | 31 import os |
| 31 import sys | 32 import sys |
| 32 import time | 33 import time |
| 33 | 34 |
| 34 from . import junit_output | 35 from . import junit_output |
| 35 | 36 |
| 36 | 37 |
| 37 ABS_PATH_PREFIX = os.getcwd() + os.sep | 38 ABS_PATH_PREFIX = os.getcwd() + os.sep |
| 38 | 39 |
| 39 | 40 |
| 40 def EscapeCommand(command): | 41 def EscapeCommand(command): |
| 41 parts = [] | 42 parts = [] |
| 42 for part in command: | 43 for part in command: |
| 43 if ' ' in part: | 44 if ' ' in part: |
| 44 # Escape spaces. We may need to escape more characters for this | 45 # Escape spaces. We may need to escape more characters for this |
| 45 # to work properly. | 46 # to work properly. |
| 46 parts.append('"%s"' % part) | 47 parts.append('"%s"' % part) |
| 47 else: | 48 else: |
| 48 parts.append(part) | 49 parts.append(part) |
| 49 return " ".join(parts) | 50 return " ".join(parts) |
| 50 | 51 |
| 51 | 52 |
| 52 class ProgressIndicator(object): | 53 class ProgressIndicator(object): |
| 53 | 54 |
| 54 def __init__(self): | 55 def __init__(self): |
| 55 self.runner = None | 56 self.runner = None |
| 56 | 57 |
| 58 def SetRunner(self, runner): | |
| 59 self.runner = runner | |
| 60 | |
| 57 def Starting(self): | 61 def Starting(self): |
| 58 pass | 62 pass |
| 59 | 63 |
| 60 def Done(self): | 64 def Done(self): |
| 61 pass | 65 pass |
| 62 | 66 |
| 63 def AboutToRun(self, test): | 67 def AboutToRun(self, test): |
| 64 pass | 68 pass |
| 65 | 69 |
| 66 def HasRun(self, test, has_unexpected_output): | 70 def HasRun(self, test, has_unexpected_output): |
| 67 pass | 71 pass |
| 68 | 72 |
| 69 def Heartbeat(self): | 73 def Heartbeat(self): |
| 70 pass | 74 pass |
| 71 | 75 |
| 72 def PrintFailureHeader(self, test): | 76 def PrintFailureHeader(self, test): |
| 73 if test.suite.IsNegativeTest(test): | 77 if test.suite.IsNegativeTest(test): |
| 74 negative_marker = '[negative] ' | 78 negative_marker = '[negative] ' |
| 75 else: | 79 else: |
| 76 negative_marker = '' | 80 negative_marker = '' |
| 77 print "=== %(label)s %(negative)s===" % { | 81 print "=== %(label)s %(negative)s===" % { |
| 78 'label': test.GetLabel(), | 82 'label': test.GetLabel(), |
| 79 'negative': negative_marker | 83 'negative': negative_marker |
| 80 } | 84 } |
| 81 | 85 |
| 82 | 86 |
| 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 def _Indicator_apply(func): | |
|
tandrii(chromium)
2015/06/09 13:24:45
nit: then maybe _IndicatorNotifier_apply, and even
Michael Achenbach
2015/06/09 14:09:27
Done. Even funkier...
| |
| 97 """Generic event dispatcher.""" | |
| 98 @wraps(func) | |
| 99 def functor(self, *args, **kwargs): | |
| 100 for indicator in self.indicators: | |
| 101 getattr(indicator, func.__name__)(*args, **kwargs) | |
| 102 return functor | |
| 103 | |
| 104 | |
| 105 # Forge all generic event-dispatching methods in IndicatorNotifier, which are | |
| 106 # part of the ProgressIndicator interface. | |
| 107 for func_name in ProgressIndicator.__dict__: | |
| 108 func = getattr(ProgressIndicator, func_name) | |
| 109 if not func_name.startswith('_') and callable(func): | |
| 110 setattr(IndicatorNotifier, func_name, _Indicator_apply(func)) | |
| 111 | |
| 112 | |
| 83 class SimpleProgressIndicator(ProgressIndicator): | 113 class SimpleProgressIndicator(ProgressIndicator): |
| 84 """Abstract base class for {Verbose,Dots}ProgressIndicator""" | 114 """Abstract base class for {Verbose,Dots}ProgressIndicator""" |
| 85 | 115 |
| 86 def Starting(self): | 116 def Starting(self): |
| 87 print 'Running %i tests' % self.runner.total | 117 print 'Running %i tests' % self.runner.total |
| 88 | 118 |
| 89 def Done(self): | 119 def Done(self): |
| 90 print | 120 print |
| 91 for failed in self.runner.failed: | 121 for failed in self.runner.failed: |
| 92 self.PrintFailureHeader(failed) | 122 self.PrintFailureHeader(failed) |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 'stderr': '%s', | 274 'stderr': '%s', |
| 245 } | 275 } |
| 246 super(MonochromeProgressIndicator, self).__init__(templates) | 276 super(MonochromeProgressIndicator, self).__init__(templates) |
| 247 | 277 |
| 248 def ClearLine(self, last_line_length): | 278 def ClearLine(self, last_line_length): |
| 249 print ("\r" + (" " * last_line_length) + "\r"), | 279 print ("\r" + (" " * last_line_length) + "\r"), |
| 250 | 280 |
| 251 | 281 |
| 252 class JUnitTestProgressIndicator(ProgressIndicator): | 282 class JUnitTestProgressIndicator(ProgressIndicator): |
| 253 | 283 |
| 254 def __init__(self, progress_indicator, junitout, junittestsuite): | 284 def __init__(self, junitout, junittestsuite): |
| 255 self.progress_indicator = progress_indicator | |
| 256 self.outputter = junit_output.JUnitTestOutput(junittestsuite) | 285 self.outputter = junit_output.JUnitTestOutput(junittestsuite) |
| 257 if junitout: | 286 if junitout: |
| 258 self.outfile = open(junitout, "w") | 287 self.outfile = open(junitout, "w") |
| 259 else: | 288 else: |
| 260 self.outfile = sys.stdout | 289 self.outfile = sys.stdout |
| 261 | 290 |
| 262 def Starting(self): | |
| 263 self.progress_indicator.runner = self.runner | |
| 264 self.progress_indicator.Starting() | |
| 265 | |
| 266 def Done(self): | 291 def Done(self): |
| 267 self.progress_indicator.Done() | |
| 268 self.outputter.FinishAndWrite(self.outfile) | 292 self.outputter.FinishAndWrite(self.outfile) |
| 269 if self.outfile != sys.stdout: | 293 if self.outfile != sys.stdout: |
| 270 self.outfile.close() | 294 self.outfile.close() |
| 271 | 295 |
| 272 def AboutToRun(self, test): | |
| 273 self.progress_indicator.AboutToRun(test) | |
| 274 | |
| 275 def HasRun(self, test, has_unexpected_output): | 296 def HasRun(self, test, has_unexpected_output): |
| 276 self.progress_indicator.HasRun(test, has_unexpected_output) | |
| 277 fail_text = "" | 297 fail_text = "" |
| 278 if has_unexpected_output: | 298 if has_unexpected_output: |
| 279 stdout = test.output.stdout.strip() | 299 stdout = test.output.stdout.strip() |
| 280 if len(stdout): | 300 if len(stdout): |
| 281 fail_text += "stdout:\n%s\n" % stdout | 301 fail_text += "stdout:\n%s\n" % stdout |
| 282 stderr = test.output.stderr.strip() | 302 stderr = test.output.stderr.strip() |
| 283 if len(stderr): | 303 if len(stderr): |
| 284 fail_text += "stderr:\n%s\n" % stderr | 304 fail_text += "stderr:\n%s\n" % stderr |
| 285 fail_text += "Command: %s" % EscapeCommand(self.runner.GetCommand(test)) | 305 fail_text += "Command: %s" % EscapeCommand(self.runner.GetCommand(test)) |
| 286 if test.output.HasCrashed(): | 306 if test.output.HasCrashed(): |
| 287 fail_text += "exit code: %d\n--- CRASHED ---" % test.output.exit_code | 307 fail_text += "exit code: %d\n--- CRASHED ---" % test.output.exit_code |
| 288 if test.output.HasTimedOut(): | 308 if test.output.HasTimedOut(): |
| 289 fail_text += "--- TIMEOUT ---" | 309 fail_text += "--- TIMEOUT ---" |
| 290 self.outputter.HasRunTest( | 310 self.outputter.HasRunTest( |
| 291 [test.GetLabel()] + self.runner.context.mode_flags + test.flags, | 311 [test.GetLabel()] + self.runner.context.mode_flags + test.flags, |
| 292 test.duration, | 312 test.duration, |
| 293 fail_text) | 313 fail_text) |
| 294 | 314 |
| 295 def Heartbeat(self): | |
| 296 self.progress_indicator.Heartbeat() | |
| 297 | 315 |
| 298 class JsonTestProgressIndicator(ProgressIndicator): | 316 class JsonTestProgressIndicator(ProgressIndicator): |
| 299 | 317 |
| 300 def __init__(self, progress_indicator, json_test_results, arch, mode): | 318 def __init__(self, json_test_results, arch, mode): |
| 301 self.progress_indicator = progress_indicator | |
| 302 self.json_test_results = json_test_results | 319 self.json_test_results = json_test_results |
| 303 self.arch = arch | 320 self.arch = arch |
| 304 self.mode = mode | 321 self.mode = mode |
| 305 self.results = [] | 322 self.results = [] |
| 306 self.tests = [] | 323 self.tests = [] |
| 307 | 324 |
| 308 def Starting(self): | |
| 309 self.progress_indicator.runner = self.runner | |
| 310 self.progress_indicator.Starting() | |
| 311 | |
| 312 def Done(self): | 325 def Done(self): |
| 313 self.progress_indicator.Done() | |
| 314 complete_results = [] | 326 complete_results = [] |
| 315 if os.path.exists(self.json_test_results): | 327 if os.path.exists(self.json_test_results): |
| 316 with open(self.json_test_results, "r") as f: | 328 with open(self.json_test_results, "r") as f: |
| 317 # Buildbot might start out with an empty file. | 329 # Buildbot might start out with an empty file. |
| 318 complete_results = json.loads(f.read() or "[]") | 330 complete_results = json.loads(f.read() or "[]") |
| 319 | 331 |
| 320 # Sort tests by duration. | 332 # Sort tests by duration. |
| 321 timed_tests = [t for t in self.tests if t.duration is not None] | 333 timed_tests = [t for t in self.tests if t.duration is not None] |
| 322 timed_tests.sort(lambda a, b: cmp(b.duration, a.duration)) | 334 timed_tests.sort(lambda a, b: cmp(b.duration, a.duration)) |
| 323 slowest_tests = [ | 335 slowest_tests = [ |
| 324 { | 336 { |
| 325 "name": test.GetLabel(), | 337 "name": test.GetLabel(), |
| 326 "flags": test.flags, | 338 "flags": test.flags, |
| 327 "command": EscapeCommand(self.runner.GetCommand(test)).replace( | 339 "command": EscapeCommand(self.runner.GetCommand(test)).replace( |
| 328 ABS_PATH_PREFIX, ""), | 340 ABS_PATH_PREFIX, ""), |
| 329 "duration": test.duration, | 341 "duration": test.duration, |
| 330 } for test in timed_tests[:20] | 342 } for test in timed_tests[:20] |
| 331 ] | 343 ] |
| 332 | 344 |
| 333 complete_results.append({ | 345 complete_results.append({ |
| 334 "arch": self.arch, | 346 "arch": self.arch, |
| 335 "mode": self.mode, | 347 "mode": self.mode, |
| 336 "results": self.results, | 348 "results": self.results, |
| 337 "slowest_tests": slowest_tests, | 349 "slowest_tests": slowest_tests, |
| 338 }) | 350 }) |
| 339 | 351 |
| 340 with open(self.json_test_results, "w") as f: | 352 with open(self.json_test_results, "w") as f: |
| 341 f.write(json.dumps(complete_results)) | 353 f.write(json.dumps(complete_results)) |
| 342 | 354 |
| 343 def AboutToRun(self, test): | |
| 344 self.progress_indicator.AboutToRun(test) | |
| 345 | |
| 346 def HasRun(self, test, has_unexpected_output): | 355 def HasRun(self, test, has_unexpected_output): |
| 347 self.progress_indicator.HasRun(test, has_unexpected_output) | |
| 348 # Buffer all tests for sorting the durations in the end. | 356 # Buffer all tests for sorting the durations in the end. |
| 349 self.tests.append(test) | 357 self.tests.append(test) |
| 350 if not has_unexpected_output: | 358 if not has_unexpected_output: |
| 351 # Omit tests that run as expected. Passing tests of reruns after failures | 359 # Omit tests that run as expected. Passing tests of reruns after failures |
| 352 # will have unexpected_output to be reported here has well. | 360 # will have unexpected_output to be reported here has well. |
| 353 return | 361 return |
| 354 | 362 |
| 355 self.results.append({ | 363 self.results.append({ |
| 356 "name": test.GetLabel(), | 364 "name": test.GetLabel(), |
| 357 "flags": test.flags, | 365 "flags": test.flags, |
| 358 "command": EscapeCommand(self.runner.GetCommand(test)).replace( | 366 "command": EscapeCommand(self.runner.GetCommand(test)).replace( |
| 359 ABS_PATH_PREFIX, ""), | 367 ABS_PATH_PREFIX, ""), |
| 360 "run": test.run, | 368 "run": test.run, |
| 361 "stdout": test.output.stdout, | 369 "stdout": test.output.stdout, |
| 362 "stderr": test.output.stderr, | 370 "stderr": test.output.stderr, |
| 363 "exit_code": test.output.exit_code, | 371 "exit_code": test.output.exit_code, |
| 364 "result": test.suite.GetOutcome(test), | 372 "result": test.suite.GetOutcome(test), |
| 365 "expected": list(test.outcomes or ["PASS"]), | 373 "expected": list(test.outcomes or ["PASS"]), |
| 366 "duration": test.duration, | 374 "duration": test.duration, |
| 367 }) | 375 }) |
| 368 | 376 |
| 369 def Heartbeat(self): | |
| 370 self.progress_indicator.Heartbeat() | |
| 371 | |
| 372 | 377 |
| 373 PROGRESS_INDICATORS = { | 378 PROGRESS_INDICATORS = { |
| 374 'verbose': VerboseProgressIndicator, | 379 'verbose': VerboseProgressIndicator, |
| 375 'dots': DotsProgressIndicator, | 380 'dots': DotsProgressIndicator, |
| 376 'color': ColorProgressIndicator, | 381 'color': ColorProgressIndicator, |
| 377 'mono': MonochromeProgressIndicator | 382 'mono': MonochromeProgressIndicator |
| 378 } | 383 } |
| OLD | NEW |