verbose.py 3.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# Copyright 2012 the V8 project authors. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
#     * Neither the name of Google Inc. nor the names of its
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

28 29
# for py2/py3 compatibility
from __future__ import print_function
30 31 32 33 34 35 36 37 38 39 40 41 42

import sys
import time

from . import statusfile


REPORT_TEMPLATE = (
"""Total: %(total)i tests
 * %(skipped)4d tests will be skipped
 * %(nocrash)4d tests are expected to be flaky but not crash
 * %(pass)4d tests are expected to pass
 * %(fail_ok)4d tests are expected to fail that we won't fix
43 44 45
 * %(fail)4d tests are expected to fail that we should fix
 * %(crash)4d tests are expected to crash
""")
46 47


48
# TODO(majeski): Turn it into an observer.
49 50
def PrintReport(tests):
  total = len(tests)
51
  skipped = nocrash = passes = fail_ok = fail = crash = 0
52
  for t in tests:
53
    if t.do_skip:
54
      skipped += 1
55
    elif t.is_pass_or_fail:
56
      nocrash += 1
57
    elif t.is_fail_ok:
58
      fail_ok += 1
59 60 61
    elif t.expected_outcomes == [statusfile.PASS]:
      passes += 1
    elif t.expected_outcomes == [statusfile.FAIL]:
62
      fail += 1
63 64 65 66
    elif t.expected_outcomes == [statusfile.CRASH]:
      crash += 1
    else:
      assert False # Unreachable # TODO: check this in outcomes parsing phase.
67

68
  print(REPORT_TEMPLATE % {
69 70 71 72 73
    "total": total,
    "skipped": skipped,
    "nocrash": nocrash,
    "pass": passes,
    "fail_ok": fail_ok,
74 75
    "fail": fail,
    "crash": crash,
76
  })
77 78 79 80


def PrintTestSource(tests):
  for test in tests:
81
    print("--- begin source: %s ---" % test)
82
    if test.is_source_available():
83
      print(test.get_source())
84
    else:
85 86
      print('(no source available)')
    print("--- end source: %s ---" % test)
87 88 89 90 91 92 93


def FormatTime(d):
  millis = round(d * 1000) % 1000
  return time.strftime("%M:%S.", time.gmtime(d)) + ("%03i" % millis)


94
def PrintTestDurations(suites, outputs, overall_time):
95 96
    # Write the times to stderr to make it easy to separate from the
    # test output.
97
    print()
98
    sys.stderr.write("--- Total time: %s ---\n" % FormatTime(overall_time))
99 100
    timed_tests = [(t, outputs[t].duration) for s in suites for t in s.tests
                   if t in outputs]
101
    timed_tests.sort(key=lambda test_duration: test_duration[1], reverse=True)
102
    index = 1
103 104
    for test, duration in timed_tests[:20]:
      t = FormatTime(duration)
105
      sys.stderr.write("%4i (%s) %s\n" % (index, t, test))
106
      index += 1