Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / results / gtest_test_results.py
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
3 # found in the LICENSE file.
4
5 import logging
6 import sys
7 import time
8
9 from telemetry.results import page_test_results
10
11
12 class GTestTestResults(page_test_results.PageTestResults):
13   def __init__(self, output_stream):
14     super(GTestTestResults, self).__init__(output_stream)
15     self._timestamp = None
16
17   def _GetMs(self):
18     return (time.time() - self._timestamp) * 1000
19
20   @property
21   def num_errors(self):
22     return len(self.errors) + len(self.failures)
23
24   def _emitFailure(self, page, err):
25     print >> self._output_stream, self._GetStringFromExcInfo(err)
26     print >> self._output_stream, '[  FAILED  ]', page.display_name, (
27         '(%0.f ms)' % self._GetMs())
28     sys.stdout.flush()
29
30   def AddError(self, page, err):
31     super(GTestTestResults, self).AddError(page, err)
32     self._emitFailure(page, err)
33
34   def AddFailure(self, page, err):
35     super(GTestTestResults, self).AddFailure(page, err)
36     self._emitFailure(page, err)
37
38   def StartTest(self, page):
39     super(GTestTestResults, self).StartTest(page)
40     print >> self._output_stream, '[ RUN      ]', (
41         page.display_name)
42     sys.stdout.flush()
43     self._timestamp = time.time()
44
45   def AddSuccess(self, page):
46     super(GTestTestResults, self).AddSuccess(page)
47     test_name = page.display_name
48     print >> self._output_stream, '[       OK ]', test_name, (
49         '(%0.f ms)' % self._GetMs())
50     sys.stdout.flush()
51
52   def AddSkip(self, page, reason):
53     super(GTestTestResults, self).AddSkip(page, reason)
54     test_name = page.display_name
55     logging.warning('===== SKIPPING TEST %s: %s =====', test_name, reason)
56     if self._timestamp == None:
57       self._timestamp = time.time()
58     print >> self._output_stream, '[       OK ]', test_name, (
59         '(%0.f ms)' % self._GetMs())
60     sys.stdout.flush()
61
62   def PrintSummary(self):
63     unit = 'test' if len(self.successes) == 1 else 'tests'
64     print >> self._output_stream, '[  PASSED  ]', (
65         '%d %s.' % (len(self.successes), unit))
66     if self.errors or self.failures:
67       all_errors = self.errors[:]
68       all_errors.extend(self.failures)
69       unit = 'test' if len(all_errors) == 1 else 'tests'
70       print >> self._output_stream, '[  FAILED  ]', (
71           '%d %s, listed below:' % (len(all_errors), unit))
72       for page, _ in all_errors:
73         print >> self._output_stream, '[  FAILED  ] ', (
74             page.display_name)
75       print >> self._output_stream
76       count = len(self.errors) + len(self.failures)
77       unit = 'TEST' if count == 1 else 'TESTS'
78       print >> self._output_stream, '%d FAILED %s' % (count, unit)
79     print >> self._output_stream
80     sys.stdout.flush()