2018-01-05 13:34:17 +00:00
|
|
|
# Copyright 2018 the V8 project authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import sys
|
2018-01-08 12:38:00 +00:00
|
|
|
import time
|
2018-01-05 13:34:17 +00:00
|
|
|
|
|
|
|
from . import base
|
|
|
|
|
|
|
|
|
|
|
|
def print_failure_header(test):
|
|
|
|
if test.output_proc.negative:
|
|
|
|
negative_marker = '[negative] '
|
|
|
|
else:
|
|
|
|
negative_marker = ''
|
|
|
|
print "=== %(label)s %(negative)s===" % {
|
|
|
|
'label': test,
|
|
|
|
'negative': negative_marker,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ResultsTracker(base.TestProcObserver):
|
2018-10-02 13:31:32 +00:00
|
|
|
"""Tracks number of results and stops to run tests if max_failures reached."""
|
|
|
|
def __init__(self, max_failures):
|
2018-01-05 13:34:17 +00:00
|
|
|
super(ResultsTracker, self).__init__()
|
2018-01-17 10:59:24 +00:00
|
|
|
self._requirement = base.DROP_OUTPUT
|
|
|
|
|
2018-01-05 13:34:17 +00:00
|
|
|
self.failed = 0
|
|
|
|
self.remaining = 0
|
|
|
|
self.total = 0
|
2018-10-02 13:31:32 +00:00
|
|
|
self.max_failures = max_failures
|
2018-01-05 13:34:17 +00:00
|
|
|
|
|
|
|
def _on_next_test(self, test):
|
|
|
|
self.total += 1
|
|
|
|
self.remaining += 1
|
|
|
|
|
2018-01-15 08:03:48 +00:00
|
|
|
def _on_result_for(self, test, result):
|
2018-01-05 13:34:17 +00:00
|
|
|
self.remaining -= 1
|
|
|
|
if result.has_unexpected_output:
|
|
|
|
self.failed += 1
|
2018-10-02 13:31:32 +00:00
|
|
|
if self.max_failures and self.failed >= self.max_failures:
|
|
|
|
print '>>> Too many failures, exiting...'
|
|
|
|
self.stop()
|
2018-01-05 13:34:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ProgressIndicator(base.TestProcObserver):
|
|
|
|
def finished(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class SimpleProgressIndicator(ProgressIndicator):
|
|
|
|
def __init__(self):
|
|
|
|
super(SimpleProgressIndicator, self).__init__()
|
2018-01-17 10:59:24 +00:00
|
|
|
self._requirement = base.DROP_PASS_OUTPUT
|
2018-01-05 13:34:17 +00:00
|
|
|
|
|
|
|
self._failed = []
|
|
|
|
|
2018-01-15 08:03:48 +00:00
|
|
|
def _on_result_for(self, test, result):
|
|
|
|
# TODO(majeski): Support for dummy/grouped results
|
2018-01-05 13:34:17 +00:00
|
|
|
if result.has_unexpected_output:
|
2018-01-23 08:20:56 +00:00
|
|
|
self._failed.append((test, result))
|
2018-01-05 13:34:17 +00:00
|
|
|
|
|
|
|
def finished(self):
|
|
|
|
crashed = 0
|
|
|
|
print
|
2018-01-23 08:20:56 +00:00
|
|
|
for test, result in self._failed:
|
2018-01-05 13:34:17 +00:00
|
|
|
print_failure_header(test)
|
2018-01-23 08:20:56 +00:00
|
|
|
if result.output.stderr:
|
2018-01-05 13:34:17 +00:00
|
|
|
print "--- stderr ---"
|
2018-01-23 08:20:56 +00:00
|
|
|
print result.output.stderr.strip()
|
|
|
|
if result.output.stdout:
|
2018-01-05 13:34:17 +00:00
|
|
|
print "--- stdout ---"
|
2018-01-23 08:20:56 +00:00
|
|
|
print result.output.stdout.strip()
|
|
|
|
print "Command: %s" % result.cmd.to_string()
|
|
|
|
if result.output.HasCrashed():
|
|
|
|
print "exit code: %d" % result.output.exit_code
|
2018-01-05 13:34:17 +00:00
|
|
|
print "--- CRASHED ---"
|
|
|
|
crashed += 1
|
2018-01-23 08:20:56 +00:00
|
|
|
if result.output.HasTimedOut():
|
2018-01-05 13:34:17 +00:00
|
|
|
print "--- TIMEOUT ---"
|
|
|
|
if len(self._failed) == 0:
|
|
|
|
print "==="
|
|
|
|
print "=== All tests succeeded"
|
|
|
|
print "==="
|
|
|
|
else:
|
|
|
|
print
|
|
|
|
print "==="
|
|
|
|
print "=== %i tests failed" % len(self._failed)
|
|
|
|
if crashed > 0:
|
|
|
|
print "=== %i tests CRASHED" % crashed
|
|
|
|
print "==="
|
|
|
|
|
|
|
|
|
|
|
|
class VerboseProgressIndicator(SimpleProgressIndicator):
|
2018-02-20 17:23:37 +00:00
|
|
|
def __init__(self):
|
|
|
|
super(VerboseProgressIndicator, self).__init__()
|
|
|
|
self._last_printed_time = time.time()
|
|
|
|
|
|
|
|
def _print(self, text):
|
|
|
|
print text
|
|
|
|
sys.stdout.flush()
|
|
|
|
self._last_printed_time = time.time()
|
|
|
|
|
2018-01-15 08:03:48 +00:00
|
|
|
def _on_result_for(self, test, result):
|
|
|
|
super(VerboseProgressIndicator, self)._on_result_for(test, result)
|
|
|
|
# TODO(majeski): Support for dummy/grouped results
|
2018-01-05 13:34:17 +00:00
|
|
|
if result.has_unexpected_output:
|
|
|
|
if result.output.HasCrashed():
|
|
|
|
outcome = 'CRASH'
|
|
|
|
else:
|
|
|
|
outcome = 'FAIL'
|
|
|
|
else:
|
|
|
|
outcome = 'pass'
|
2019-02-07 13:03:13 +00:00
|
|
|
|
|
|
|
self._print('Done running %s %s: %s' % (
|
|
|
|
test, test.variant or 'default', outcome))
|
2018-01-05 13:34:17 +00:00
|
|
|
|
2018-01-08 12:38:00 +00:00
|
|
|
def _on_heartbeat(self):
|
2018-02-20 17:23:37 +00:00
|
|
|
if time.time() - self._last_printed_time > 30:
|
|
|
|
# Print something every 30 seconds to not get killed by an output
|
|
|
|
# timeout.
|
|
|
|
self._print('Still working...')
|
2018-01-08 12:38:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DotsProgressIndicator(SimpleProgressIndicator):
|
|
|
|
def __init__(self):
|
|
|
|
super(DotsProgressIndicator, self).__init__()
|
|
|
|
self._count = 0
|
|
|
|
|
2018-01-15 08:03:48 +00:00
|
|
|
def _on_result_for(self, test, result):
|
2019-01-23 16:02:59 +00:00
|
|
|
super(DotsProgressIndicator, self)._on_result_for(test, result)
|
2018-01-15 08:03:48 +00:00
|
|
|
# TODO(majeski): Support for dummy/grouped results
|
2018-01-08 12:38:00 +00:00
|
|
|
self._count += 1
|
|
|
|
if self._count > 1 and self._count % 50 == 1:
|
|
|
|
sys.stdout.write('\n')
|
|
|
|
if result.has_unexpected_output:
|
|
|
|
if result.output.HasCrashed():
|
|
|
|
sys.stdout.write('C')
|
|
|
|
sys.stdout.flush()
|
|
|
|
elif result.output.HasTimedOut():
|
|
|
|
sys.stdout.write('T')
|
|
|
|
sys.stdout.flush()
|
|
|
|
else:
|
|
|
|
sys.stdout.write('F')
|
|
|
|
sys.stdout.flush()
|
|
|
|
else:
|
|
|
|
sys.stdout.write('.')
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
|
|
|
|
class CompactProgressIndicator(ProgressIndicator):
|
|
|
|
def __init__(self, templates):
|
|
|
|
super(CompactProgressIndicator, self).__init__()
|
2018-01-17 10:59:24 +00:00
|
|
|
self._requirement = base.DROP_PASS_OUTPUT
|
|
|
|
|
2018-01-08 12:38:00 +00:00
|
|
|
self._templates = templates
|
|
|
|
self._last_status_length = 0
|
|
|
|
self._start_time = time.time()
|
|
|
|
|
|
|
|
self._passed = 0
|
|
|
|
self._failed = 0
|
|
|
|
|
2018-01-15 08:03:48 +00:00
|
|
|
def _on_result_for(self, test, result):
|
|
|
|
# TODO(majeski): Support for dummy/grouped results
|
2018-01-08 12:38:00 +00:00
|
|
|
if result.has_unexpected_output:
|
|
|
|
self._failed += 1
|
|
|
|
else:
|
|
|
|
self._passed += 1
|
|
|
|
|
|
|
|
self._print_progress(str(test))
|
|
|
|
if result.has_unexpected_output:
|
|
|
|
output = result.output
|
|
|
|
stdout = output.stdout.strip()
|
|
|
|
stderr = output.stderr.strip()
|
|
|
|
|
|
|
|
self._clear_line(self._last_status_length)
|
|
|
|
print_failure_header(test)
|
|
|
|
if len(stdout):
|
|
|
|
print self._templates['stdout'] % stdout
|
|
|
|
if len(stderr):
|
|
|
|
print self._templates['stderr'] % stderr
|
2018-01-17 12:29:53 +00:00
|
|
|
print "Command: %s" % result.cmd
|
2018-01-08 12:38:00 +00:00
|
|
|
if output.HasCrashed():
|
|
|
|
print "exit code: %d" % output.exit_code
|
|
|
|
print "--- CRASHED ---"
|
|
|
|
if output.HasTimedOut():
|
|
|
|
print "--- TIMEOUT ---"
|
|
|
|
|
|
|
|
def finished(self):
|
|
|
|
self._print_progress('Done')
|
|
|
|
print
|
|
|
|
|
|
|
|
def _print_progress(self, name):
|
|
|
|
self._clear_line(self._last_status_length)
|
|
|
|
elapsed = time.time() - self._start_time
|
|
|
|
status = self._templates['status_line'] % {
|
|
|
|
'passed': self._passed,
|
|
|
|
'failed': self._failed,
|
|
|
|
'test': name,
|
|
|
|
'mins': int(elapsed) / 60,
|
|
|
|
'secs': int(elapsed) % 60
|
|
|
|
}
|
|
|
|
status = self._truncate(status, 78)
|
|
|
|
self._last_status_length = len(status)
|
|
|
|
print status,
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
def _truncate(self, string, length):
|
|
|
|
if length and len(string) > (length - 3):
|
|
|
|
return string[:(length - 3)] + "..."
|
|
|
|
else:
|
|
|
|
return string
|
|
|
|
|
|
|
|
def _clear_line(self, last_length):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
|
|
|
class ColorProgressIndicator(CompactProgressIndicator):
|
|
|
|
def __init__(self):
|
|
|
|
templates = {
|
|
|
|
'status_line': ("[%(mins)02i:%(secs)02i|"
|
|
|
|
"\033[32m+%(passed) 4d\033[0m|"
|
|
|
|
"\033[31m-%(failed) 4d\033[0m]: %(test)s"),
|
|
|
|
'stdout': "\033[1m%s\033[0m",
|
|
|
|
'stderr': "\033[31m%s\033[0m",
|
|
|
|
}
|
|
|
|
super(ColorProgressIndicator, self).__init__(templates)
|
|
|
|
|
|
|
|
def _clear_line(self, last_length):
|
|
|
|
print "\033[1K\r",
|
|
|
|
|
|
|
|
|
|
|
|
class MonochromeProgressIndicator(CompactProgressIndicator):
|
|
|
|
def __init__(self):
|
|
|
|
templates = {
|
2019-01-21 07:00:32 +00:00
|
|
|
'status_line': ("[%(mins)02i:%(secs)02i|"
|
2018-01-08 12:38:00 +00:00
|
|
|
"+%(passed) 4d|-%(failed) 4d]: %(test)s"),
|
|
|
|
'stdout': '%s',
|
|
|
|
'stderr': '%s',
|
|
|
|
}
|
|
|
|
super(MonochromeProgressIndicator, self).__init__(templates)
|
|
|
|
|
|
|
|
def _clear_line(self, last_length):
|
|
|
|
print ("\r" + (" " * last_length) + "\r"),
|
|
|
|
|
|
|
|
|
2018-01-05 13:34:17 +00:00
|
|
|
class JsonTestProgressIndicator(ProgressIndicator):
|
2018-01-31 09:18:13 +00:00
|
|
|
def __init__(self, json_test_results, arch, mode):
|
2018-01-05 13:34:17 +00:00
|
|
|
super(JsonTestProgressIndicator, self).__init__()
|
2018-01-17 10:59:24 +00:00
|
|
|
# We want to drop stdout/err for all passed tests on the first try, but we
|
|
|
|
# need to get outputs for all runs after the first one. To accommodate that,
|
|
|
|
# reruns are set to keep the result no matter what requirement says, i.e.
|
|
|
|
# keep_output set to True in the RerunProc.
|
|
|
|
self._requirement = base.DROP_PASS_STDOUT
|
|
|
|
|
2018-01-05 13:34:17 +00:00
|
|
|
self.json_test_results = json_test_results
|
|
|
|
self.arch = arch
|
|
|
|
self.mode = mode
|
|
|
|
self.results = []
|
|
|
|
self.tests = []
|
|
|
|
|
2018-01-15 08:03:48 +00:00
|
|
|
def _on_result_for(self, test, result):
|
2018-01-15 12:21:54 +00:00
|
|
|
if result.is_rerun:
|
|
|
|
self.process_results(test, result.results)
|
|
|
|
else:
|
|
|
|
self.process_results(test, [result])
|
|
|
|
|
|
|
|
def process_results(self, test, results):
|
|
|
|
for run, result in enumerate(results):
|
|
|
|
# TODO(majeski): Support for dummy/grouped results
|
|
|
|
output = result.output
|
|
|
|
# Buffer all tests for sorting the durations in the end.
|
2018-01-17 12:29:53 +00:00
|
|
|
# TODO(machenbach): Running average + buffer only slowest 20 tests.
|
|
|
|
self.tests.append((test, output.duration, result.cmd))
|
2018-01-15 12:21:54 +00:00
|
|
|
|
|
|
|
# Omit tests that run as expected on the first try.
|
|
|
|
# Everything that happens after the first run is included in the output
|
|
|
|
# even if it flakily passes.
|
|
|
|
if not result.has_unexpected_output and run == 0:
|
|
|
|
continue
|
|
|
|
|
|
|
|
self.results.append({
|
|
|
|
"name": str(test),
|
2018-01-17 12:29:53 +00:00
|
|
|
"flags": result.cmd.args,
|
|
|
|
"command": result.cmd.to_string(relative=True),
|
2018-01-15 12:21:54 +00:00
|
|
|
"run": run + 1,
|
|
|
|
"stdout": output.stdout,
|
|
|
|
"stderr": output.stderr,
|
|
|
|
"exit_code": output.exit_code,
|
|
|
|
"result": test.output_proc.get_outcome(output),
|
|
|
|
"expected": test.expected_outcomes,
|
|
|
|
"duration": output.duration,
|
2018-01-31 09:18:13 +00:00
|
|
|
"random_seed": test.random_seed,
|
2018-01-15 12:21:54 +00:00
|
|
|
"target_name": test.get_shell(),
|
|
|
|
"variant": test.variant,
|
|
|
|
})
|
2018-01-05 13:34:17 +00:00
|
|
|
|
|
|
|
def finished(self):
|
|
|
|
complete_results = []
|
|
|
|
if os.path.exists(self.json_test_results):
|
|
|
|
with open(self.json_test_results, "r") as f:
|
|
|
|
# Buildbot might start out with an empty file.
|
|
|
|
complete_results = json.loads(f.read() or "[]")
|
|
|
|
|
|
|
|
duration_mean = None
|
|
|
|
if self.tests:
|
|
|
|
# Get duration mean.
|
|
|
|
duration_mean = (
|
2018-01-17 12:29:53 +00:00
|
|
|
sum(duration for (_, duration, cmd) in self.tests) /
|
2018-01-05 13:34:17 +00:00
|
|
|
float(len(self.tests)))
|
|
|
|
|
|
|
|
# Sort tests by duration.
|
2018-01-17 12:29:53 +00:00
|
|
|
self.tests.sort(key=lambda (_, duration, cmd): duration, reverse=True)
|
2018-01-05 13:34:17 +00:00
|
|
|
slowest_tests = [
|
|
|
|
{
|
|
|
|
"name": str(test),
|
2018-01-17 12:29:53 +00:00
|
|
|
"flags": cmd.args,
|
|
|
|
"command": cmd.to_string(relative=True),
|
2018-01-05 13:34:17 +00:00
|
|
|
"duration": duration,
|
|
|
|
"marked_slow": test.is_slow,
|
2018-01-17 12:29:53 +00:00
|
|
|
} for (test, duration, cmd) in self.tests[:20]
|
2018-01-05 13:34:17 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
complete_results.append({
|
|
|
|
"arch": self.arch,
|
|
|
|
"mode": self.mode,
|
|
|
|
"results": self.results,
|
|
|
|
"slowest_tests": slowest_tests,
|
|
|
|
"duration_mean": duration_mean,
|
|
|
|
"test_total": len(self.tests),
|
|
|
|
})
|
|
|
|
|
|
|
|
with open(self.json_test_results, "w") as f:
|
|
|
|
f.write(json.dumps(complete_results))
|