| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging | |
| 6 import time | 5 import time |
| 7 | 6 |
| 8 from telemetry.results import progress_reporter | 7 from telemetry.results import progress_reporter |
| 9 from telemetry.value import failure | 8 from telemetry.value import failure |
| 10 from telemetry.value import skip | 9 from telemetry.value import skip |
| 11 | 10 |
| 12 | 11 |
| 13 class GTestProgressReporter(progress_reporter.ProgressReporter): | 12 class GTestProgressReporter(progress_reporter.ProgressReporter): |
| 14 """A progress reporter that outputs the progress report in gtest style.""" | 13 """A progress reporter that outputs the progress report in gtest style.""" |
| 15 | 14 |
| 16 def __init__(self, output_stream, output_skipped_tests_summary=False): | 15 def __init__(self, output_stream, output_skipped_tests_summary=False): |
| 17 super(GTestProgressReporter, self).__init__(output_stream) | 16 super(GTestProgressReporter, self).__init__(output_stream) |
| 18 self._timestamp = None | 17 self._timestamp = None |
| 19 self._output_skipped_tests_summary = output_skipped_tests_summary | 18 self._output_skipped_tests_summary = output_skipped_tests_summary |
| 20 | 19 |
| 21 def _GetMs(self): | 20 def _GetMs(self): |
| 21 assert self._timestamp is not None, 'Did not call WillRunPage.' |
| 22 return (time.time() - self._timestamp) * 1000 | 22 return (time.time() - self._timestamp) * 1000 |
| 23 | 23 |
| 24 def _EmitFailure(self, failure_value): | |
| 25 print >> self.output_stream, failure.GetStringFromExcInfo( | |
| 26 failure_value.exc_info) | |
| 27 display_name = failure_value.page.display_name | |
| 28 print >> self.output_stream, '[ FAILED ]', display_name, ( | |
| 29 '(%0.f ms)' % self._GetMs()) | |
| 30 self.output_stream.flush() | |
| 31 | |
| 32 def _EmitSkip(self, skip_value): | |
| 33 page = skip_value.page | |
| 34 reason = skip_value.reason | |
| 35 logging.warning('===== SKIPPING TEST %s: %s =====', | |
| 36 page.display_name, reason) | |
| 37 if self._timestamp == None: | |
| 38 self._timestamp = time.time() | |
| 39 print >> self.output_stream, '[ OK ]', page.display_name, ( | |
| 40 '(%0.f ms)' % self._GetMs()) | |
| 41 self.output_stream.flush() | |
| 42 | |
| 43 def DidAddValue(self, value): | 24 def DidAddValue(self, value): |
| 44 super(GTestProgressReporter, self).DidAddValue(value) | 25 super(GTestProgressReporter, self).DidAddValue(value) |
| 45 is_failure = isinstance(value, failure.FailureValue) | 26 if isinstance(value, failure.FailureValue): |
| 46 is_skip = isinstance(value, skip.SkipValue) | 27 print >> self.output_stream, failure.GetStringFromExcInfo( |
| 28 value.exc_info) |
| 29 self.output_stream.flush() |
| 30 elif isinstance(value, skip.SkipValue): |
| 31 print >> self.output_stream, '===== SKIPPING TEST %s: %s =====' % ( |
| 32 value.page.display_name, value.reason) |
| 33 # TODO(chrishenry): Consider outputting metric values as well. For |
| 34 # e.g., it can replace BuildbotOutputFormatter in |
| 35 # --output-format=html, which we used only so that users can grep |
| 36 # the results without opening results.html. |
| 47 | 37 |
| 48 # TODO(eakuefner/chrishenry): move emit failure/skip output to DidRunPage. | 38 def WillRunPage(self, page_test_results): |
| 49 if is_failure: | 39 super(GTestProgressReporter, self).WillRunPage(page_test_results) |
| 50 self._EmitFailure(value) | 40 print >> self.output_stream, '[ RUN ]', ( |
| 51 elif is_skip: | 41 page_test_results.current_page.display_name) |
| 52 self._EmitSkip(value) | |
| 53 | |
| 54 def WillRunPage(self, page): | |
| 55 super(GTestProgressReporter, self).WillRunPage(page) | |
| 56 print >> self.output_stream, '[ RUN ]', page.display_name | |
| 57 self.output_stream.flush() | 42 self.output_stream.flush() |
| 58 self._timestamp = time.time() | 43 self._timestamp = time.time() |
| 59 | 44 |
| 60 def DidAddSuccess(self, page): | 45 def DidRunPage(self, page_test_results): |
| 61 super(GTestProgressReporter, self).DidAddSuccess(page) | 46 super(GTestProgressReporter, self).DidRunPage(page_test_results) |
| 62 print >> self.output_stream, '[ OK ]', page.display_name, ( | 47 page = page_test_results.current_page |
| 63 '(%0.f ms)' % self._GetMs()) | 48 if page_test_results.current_page_run.failed: |
| 49 print >> self.output_stream, '[ FAILED ]', page.display_name, ( |
| 50 '(%0.f ms)' % self._GetMs()) |
| 51 else: |
| 52 print >> self.output_stream, '[ OK ]', page.display_name, ( |
| 53 '(%0.f ms)' % self._GetMs()) |
| 64 self.output_stream.flush() | 54 self.output_stream.flush() |
| 65 | 55 |
| 56 def WillAttemptPageRun(self, page_test_results, attempt_count, max_attempts): |
| 57 super(GTestProgressReporter, self).WillAttemptPageRun( |
| 58 page_test_results, attempt_count, max_attempts) |
| 59 # A failed attempt will have at least 1 value. |
| 60 if attempt_count != 1: |
| 61 print >> self.output_stream, ( |
| 62 '===== RETRYING PAGE RUN (attempt %s out of %s allowed) =====' % ( |
| 63 attempt_count, max_attempts)) |
| 64 print >> self.output_stream, ( |
| 65 'Page run attempt failed and will be retried. ' |
| 66 'Discarding previous results.') |
| 67 |
| 66 def DidFinishAllTests(self, page_test_results): | 68 def DidFinishAllTests(self, page_test_results): |
| 67 super(GTestProgressReporter, self).DidFinishAllTests(page_test_results) | 69 super(GTestProgressReporter, self).DidFinishAllTests(page_test_results) |
| 68 successful_runs = [] | 70 successful_runs = [] |
| 69 failed_runs = [] | 71 failed_runs = [] |
| 70 for run in page_test_results.all_page_runs: | 72 for run in page_test_results.all_page_runs: |
| 71 if run.failed: | 73 if run.failed: |
| 72 failed_runs.append(run) | 74 failed_runs.append(run) |
| 73 else: | 75 else: |
| 74 successful_runs.append(run) | 76 successful_runs.append(run) |
| 75 | 77 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 88 unit = 'TEST' if count == 1 else 'TESTS' | 90 unit = 'TEST' if count == 1 else 'TESTS' |
| 89 print >> self.output_stream, '%d FAILED %s' % (count, unit) | 91 print >> self.output_stream, '%d FAILED %s' % (count, unit) |
| 90 print >> self.output_stream | 92 print >> self.output_stream |
| 91 | 93 |
| 92 if self._output_skipped_tests_summary: | 94 if self._output_skipped_tests_summary: |
| 93 if len(page_test_results.skipped_values) > 0: | 95 if len(page_test_results.skipped_values) > 0: |
| 94 print >> self.output_stream, 'Skipped pages:\n%s\n' % ('\n'.join( | 96 print >> self.output_stream, 'Skipped pages:\n%s\n' % ('\n'.join( |
| 95 v.page.display_name for v in page_test_results.skipped_values)) | 97 v.page.display_name for v in page_test_results.skipped_values)) |
| 96 | 98 |
| 97 self.output_stream.flush() | 99 self.output_stream.flush() |
| OLD | NEW |