Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Side by Side Diff: tools/telemetry/telemetry/results/gtest_progress_reporter.py

Issue 530143002: Makes sure telemetry test result report is one string (no interreuption) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comments Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 time 5 import time
6 6
7 from telemetry.results import progress_reporter 7 from telemetry.results import progress_reporter
8 from telemetry.value import failure 8 from telemetry.value import failure
9 from telemetry.value import skip 9 from telemetry.value import skip
10 10
11 11
12 class GTestProgressReporter(progress_reporter.ProgressReporter): 12 class GTestProgressReporter(progress_reporter.ProgressReporter):
13 """A progress reporter that outputs the progress report in gtest style.""" 13 """A progress reporter that outputs the progress report in gtest style.
14
15 Be careful each print should only handle one string. Otherwise, the output
16 might be interrupted by Chrome logging, and the output interpretation might
17 be incorrect. For example:
18 print >> self._output_stream, "[ OK ]", testname
19 should be written as
20 print >> self._output_stream, "[ OK ] %s" % testname
21 """
14 22
15 def __init__(self, output_stream, output_skipped_tests_summary=False): 23 def __init__(self, output_stream, output_skipped_tests_summary=False):
16 super(GTestProgressReporter, self).__init__() 24 super(GTestProgressReporter, self).__init__()
17 self._output_stream = output_stream 25 self._output_stream = output_stream
18 self._timestamp = None 26 self._timestamp = None
19 self._output_skipped_tests_summary = output_skipped_tests_summary 27 self._output_skipped_tests_summary = output_skipped_tests_summary
20 28
21 def _GetMs(self): 29 def _GetMs(self):
22 assert self._timestamp is not None, 'Did not call WillRunPage.' 30 assert self._timestamp is not None, 'Did not call WillRunPage.'
23 return (time.time() - self._timestamp) * 1000 31 return (time.time() - self._timestamp) * 1000
24 32
25 def DidAddValue(self, value): 33 def DidAddValue(self, value):
26 super(GTestProgressReporter, self).DidAddValue(value) 34 super(GTestProgressReporter, self).DidAddValue(value)
27 if isinstance(value, failure.FailureValue): 35 if isinstance(value, failure.FailureValue):
28 print >> self._output_stream, failure.GetStringFromExcInfo( 36 print >> self._output_stream, failure.GetStringFromExcInfo(
29 value.exc_info) 37 value.exc_info)
30 self._output_stream.flush() 38 self._output_stream.flush()
31 elif isinstance(value, skip.SkipValue): 39 elif isinstance(value, skip.SkipValue):
32 print >> self._output_stream, '===== SKIPPING TEST %s: %s =====' % ( 40 print >> self._output_stream, '===== SKIPPING TEST %s: %s =====' % (
33 value.page.display_name, value.reason) 41 value.page.display_name, value.reason)
34 # TODO(chrishenry): Consider outputting metric values as well. For 42 # TODO(chrishenry): Consider outputting metric values as well. For
35 # e.g., it can replace BuildbotOutputFormatter in 43 # e.g., it can replace BuildbotOutputFormatter in
36 # --output-format=html, which we used only so that users can grep 44 # --output-format=html, which we used only so that users can grep
37 # the results without opening results.html. 45 # the results without opening results.html.
38 46
39 def WillRunPage(self, page_test_results): 47 def WillRunPage(self, page_test_results):
40 super(GTestProgressReporter, self).WillRunPage(page_test_results) 48 super(GTestProgressReporter, self).WillRunPage(page_test_results)
41 print >> self._output_stream, '[ RUN ]', ( 49 print >> self._output_stream, '[ RUN ] %s' % (
42 page_test_results.current_page.display_name) 50 page_test_results.current_page.display_name)
43 self._output_stream.flush() 51 self._output_stream.flush()
44 self._timestamp = time.time() 52 self._timestamp = time.time()
45 53
46 def DidRunPage(self, page_test_results): 54 def DidRunPage(self, page_test_results):
47 super(GTestProgressReporter, self).DidRunPage(page_test_results) 55 super(GTestProgressReporter, self).DidRunPage(page_test_results)
48 page = page_test_results.current_page 56 page = page_test_results.current_page
49 if page_test_results.current_page_run.failed: 57 if page_test_results.current_page_run.failed:
50 print >> self._output_stream, '[ FAILED ]', page.display_name, ( 58 print >> self._output_stream, '[ FAILED ] %s (%0.f ms)' % (
51 '(%0.f ms)' % self._GetMs()) 59 page.display_name, self._GetMs())
52 else: 60 else:
53 print >> self._output_stream, '[ OK ]', page.display_name, ( 61 print >> self._output_stream, '[ OK ] %s (%0.f ms)' % (
54 '(%0.f ms)' % self._GetMs()) 62 page.display_name, self._GetMs())
55 self._output_stream.flush() 63 self._output_stream.flush()
56 64
57 def WillAttemptPageRun(self, page_test_results, attempt_count, max_attempts): 65 def WillAttemptPageRun(self, page_test_results, attempt_count, max_attempts):
58 super(GTestProgressReporter, self).WillAttemptPageRun( 66 super(GTestProgressReporter, self).WillAttemptPageRun(
59 page_test_results, attempt_count, max_attempts) 67 page_test_results, attempt_count, max_attempts)
60 # A failed attempt will have at least 1 value. 68 # A failed attempt will have at least 1 value.
61 if attempt_count != 1: 69 if attempt_count != 1:
62 print >> self._output_stream, ( 70 print >> self._output_stream, (
63 '===== RETRYING PAGE RUN (attempt %s out of %s allowed) =====' % ( 71 '===== RETRYING PAGE RUN (attempt %s out of %s allowed) =====' % (
64 attempt_count, max_attempts)) 72 attempt_count, max_attempts))
65 print >> self._output_stream, ( 73 print >> self._output_stream, (
66 'Page run attempt failed and will be retried. ' 74 'Page run attempt failed and will be retried. '
67 'Discarding previous results.') 75 'Discarding previous results.')
68 76
69 def DidFinishAllTests(self, page_test_results): 77 def DidFinishAllTests(self, page_test_results):
70 super(GTestProgressReporter, self).DidFinishAllTests(page_test_results) 78 super(GTestProgressReporter, self).DidFinishAllTests(page_test_results)
71 successful_runs = [] 79 successful_runs = []
72 failed_runs = [] 80 failed_runs = []
73 for run in page_test_results.all_page_runs: 81 for run in page_test_results.all_page_runs:
74 if run.failed: 82 if run.failed:
75 failed_runs.append(run) 83 failed_runs.append(run)
76 else: 84 else:
77 successful_runs.append(run) 85 successful_runs.append(run)
78 86
79 unit = 'test' if len(successful_runs) == 1 else 'tests' 87 unit = 'test' if len(successful_runs) == 1 else 'tests'
80 print >> self._output_stream, '[ PASSED ]', ( 88 print >> self._output_stream, '[ PASSED ] %d %s.' % (
81 '%d %s.' % (len(successful_runs), unit)) 89 (len(successful_runs), unit))
82 if len(failed_runs) > 0: 90 if len(failed_runs) > 0:
83 unit = 'test' if len(failed_runs) == 1 else 'tests' 91 unit = 'test' if len(failed_runs) == 1 else 'tests'
84 print >> self._output_stream, '[ FAILED ]', ( 92 print >> self._output_stream, '[ FAILED ] %d %s, listed below:' % (
85 '%d %s, listed below:' % (len(page_test_results.failures), unit)) 93 (len(page_test_results.failures), unit))
86 for failed_run in failed_runs: 94 for failed_run in failed_runs:
87 print >> self._output_stream, '[ FAILED ] ', ( 95 print >> self._output_stream, '[ FAILED ] %s' % (
88 failed_run.page.display_name) 96 failed_run.page.display_name)
89 print >> self._output_stream 97 print >> self._output_stream
90 count = len(failed_runs) 98 count = len(failed_runs)
91 unit = 'TEST' if count == 1 else 'TESTS' 99 unit = 'TEST' if count == 1 else 'TESTS'
92 print >> self._output_stream, '%d FAILED %s' % (count, unit) 100 print >> self._output_stream, '%d FAILED %s' % (count, unit)
93 print >> self._output_stream 101 print >> self._output_stream
94 102
95 if self._output_skipped_tests_summary: 103 if self._output_skipped_tests_summary:
96 if len(page_test_results.skipped_values) > 0: 104 if len(page_test_results.skipped_values) > 0:
97 print >> self._output_stream, 'Skipped pages:\n%s\n' % ('\n'.join( 105 print >> self._output_stream, 'Skipped pages:\n%s\n' % ('\n'.join(
98 v.page.display_name for v in page_test_results.skipped_values)) 106 v.page.display_name for v in page_test_results.skipped_values))
99 107
100 self._output_stream.flush() 108 self._output_stream.flush()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698