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 28import sys 29import time 30 31from . import statusfile 32 33 34REPORT_TEMPLATE = ( 35"""Total: %(total)i tests 36 * %(skipped)4d tests will be skipped 37 * %(nocrash)4d tests are expected to be flaky but not crash 38 * %(pass)4d tests are expected to pass 39 * %(fail_ok)4d tests are expected to fail that we won't fix 40 * %(fail)4d tests are expected to fail that we should fix 41 * %(crash)4d tests are expected to crash 42""") 43 44 45# TODO(majeski): Turn it into an observer. 46def PrintReport(tests): 47 total = len(tests) 48 skipped = nocrash = passes = fail_ok = fail = crash = 0 49 for t in tests: 50 if t.do_skip: 51 skipped += 1 52 elif t.is_pass_or_fail: 53 nocrash += 1 54 elif t.is_fail_ok: 55 fail_ok += 1 56 elif t.expected_outcomes == [statusfile.PASS]: 57 passes += 1 58 elif t.expected_outcomes == [statusfile.FAIL]: 59 fail += 1 60 elif t.expected_outcomes == [statusfile.CRASH]: 61 crash += 1 62 else: 63 assert False # Unreachable # TODO: check this in outcomes parsing phase. 64 65 print(REPORT_TEMPLATE % { 66 "total": total, 67 "skipped": skipped, 68 "nocrash": nocrash, 69 "pass": passes, 70 "fail_ok": fail_ok, 71 "fail": fail, 72 "crash": crash, 73 }) 74 75 76def PrintTestSource(tests): 77 for test in tests: 78 print("--- begin source: %s ---" % test) 79 if test.is_source_available(): 80 print(test.get_source()) 81 else: 82 print('(no source available)') 83 print("--- end source: %s ---" % test) 84 85 86def FormatTime(d): 87 millis = round(d * 1000) % 1000 88 return time.strftime("%M:%S.", time.gmtime(d)) + ("%03i" % millis) 89 90 91def PrintTestDurations(suites, outputs, overall_time): 92 # Write the times to stderr to make it easy to separate from the 93 # test output. 94 print() 95 sys.stderr.write("--- Total time: %s ---\n" % FormatTime(overall_time)) 96 timed_tests = [(t, outputs[t].duration) for s in suites for t in s.tests 97 if t in outputs] 98 timed_tests.sort(key=lambda test_duration: test_duration[1], reverse=True) 99 index = 1 100 for test, duration in timed_tests[:20]: 101 t = FormatTime(duration) 102 sys.stderr.write("%4i (%s) %s\n" % (index, t, test)) 103 index += 1 104