1# Copyright 2012 the V8 project authors. All rights reserved.
2# Redistribution and use in source and binary forms, with or without
3# modification, are permitted provided that the following conditions are
4# met:
5#
6#     * Redistributions of source code must retain the above copyright
7#       notice, this list of conditions and the following disclaimer.
8#     * Redistributions in binary form must reproduce the above
9#       copyright notice, this list of conditions and the following
10#       disclaimer in the documentation and/or other materials provided
11#       with the distribution.
12#     * Neither the name of Google Inc. nor the names of its
13#       contributors may be used to endorse or promote products derived
14#       from this software without specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28
29import sys
30import time
31
32from . import statusfile
33
34
35REPORT_TEMPLATE = (
36"""Total: %(total)i tests
37 * %(skipped)4d tests will be skipped
38 * %(nocrash)4d tests are expected to be flaky but not crash
39 * %(pass)4d tests are expected to pass
40 * %(fail_ok)4d tests are expected to fail that we won't fix
41 * %(fail)4d tests are expected to fail that we should fix
42 * %(crash)4d tests are expected to crash
43""")
44
45
46# TODO(majeski): Turn it into an observer.
47def PrintReport(tests):
48  total = len(tests)
49  skipped = nocrash = passes = fail_ok = fail = crash = 0
50  for t in tests:
51    if t.do_skip:
52      skipped += 1
53    elif t.is_pass_or_fail:
54      nocrash += 1
55    elif t.is_fail_ok:
56      fail_ok += 1
57    elif t.expected_outcomes == [statusfile.PASS]:
58      passes += 1
59    elif t.expected_outcomes == [statusfile.FAIL]:
60      fail += 1
61    elif t.expected_outcomes == [statusfile.CRASH]:
62      crash += 1
63    else:
64      assert False # Unreachable # TODO: check this in outcomes parsing phase.
65
66  print REPORT_TEMPLATE % {
67    "total": total,
68    "skipped": skipped,
69    "nocrash": nocrash,
70    "pass": passes,
71    "fail_ok": fail_ok,
72    "fail": fail,
73    "crash": crash,
74  }
75
76
77def PrintTestSource(tests):
78  for test in tests:
79    print "--- begin source: %s ---" % test
80    if test.is_source_available():
81      print test.get_source()
82    else:
83      print '(no source available)'
84    print "--- end source: %s ---" % test
85
86
87def FormatTime(d):
88  millis = round(d * 1000) % 1000
89  return time.strftime("%M:%S.", time.gmtime(d)) + ("%03i" % millis)
90
91
92def PrintTestDurations(suites, outputs, overall_time):
93    # Write the times to stderr to make it easy to separate from the
94    # test output.
95    print
96    sys.stderr.write("--- Total time: %s ---\n" % FormatTime(overall_time))
97    timed_tests = [(t, outputs[t].duration) for s in suites for t in s.tests
98                   if t in outputs]
99    timed_tests.sort(key=lambda (_, duration): duration, reverse=True)
100    index = 1
101    for test, duration in timed_tests[:20]:
102      t = FormatTime(duration)
103      sys.stderr.write("%4i (%s) %s\n" % (index, t, test))
104      index += 1
105