Skip to content

Commit

Permalink
[lit] Attempt to print test summary on CTRL+C
Browse files Browse the repository at this point in the history
  • Loading branch information
yln authored and Julian Lettner committed Nov 22, 2019
1 parent 506144d commit 718d68e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
9 changes: 6 additions & 3 deletions llvm/utils/lit/lit/ProgressBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def update(self, percent, message):
sys.stdout.flush()
self.atIndex = next

def clear(self):
if self.atIndex is not None:
def clear(self, interrupted):
if self.atIndex is not None and not interrupted:
sys.stdout.write('\n')
sys.stdout.flush()
self.atIndex = None
Expand Down Expand Up @@ -275,11 +275,14 @@ def update(self, percent, message):
if not self.term.XN:
sys.stdout.flush()

def clear(self):
def clear(self, interrupted):
if not self.cleared:
sys.stdout.write(self.BOL + self.term.CLEAR_EOL +
self.term.UP + self.term.CLEAR_EOL +
self.term.UP + self.term.CLEAR_EOL)
if interrupted: # ^C creates extra line. Gobble it up!
sys.stdout.write(self.term.UP + self.term.CLEAR_EOL)
sys.stdout.write('^C')
sys.stdout.flush()
self.cleared = 1

Expand Down
9 changes: 4 additions & 5 deletions llvm/utils/lit/lit/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create_display(opts, tests, total_tests, workers):
class NopDisplay(object):
def print_header(self): pass
def update(self, test): pass
def clear(self): pass
def clear(self, interrupted): pass


class Display(object):
Expand All @@ -49,7 +49,7 @@ def update(self, test):
(not self.opts.quiet and not self.opts.succinct)
if show_result:
if self.progress_bar:
self.progress_bar.clear()
self.progress_bar.clear(interrupted=False)
self.print_result(test)

if self.progress_bar:
Expand All @@ -58,10 +58,9 @@ def update(self, test):
percent = float(self.completed) / self.tests
self.progress_bar.update(percent, test.getFullName())

def clear(self):
def clear(self, interrupted):
if self.progress_bar:
self.progress_bar.clear()
sys.stdout.write('\n')
self.progress_bar.clear(interrupted)

def print_result(self, test):
# Show the test result line.
Expand Down
22 changes: 10 additions & 12 deletions llvm/utils/lit/lit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def main(builtin_params = {}):
run_tests(tests, litConfig, opts, numTotalTests)
elapsed = time.time() - start

print_summary(tests, elapsed, opts)
executed_tests = [t for t in tests if t.result]

print_summary(executed_tests, elapsed, opts)

if opts.output_path:
write_test_results(tests, litConfig, elapsed, opts.output_path)
Expand All @@ -111,7 +113,7 @@ def main(builtin_params = {}):
if litConfig.numWarnings:
sys.stderr.write('\n%d warning(s) in tests.\n' % litConfig.numWarnings)

has_failure = any(t.isFailure() for t in tests)
has_failure = any(t.isFailure() for t in executed_tests)
if has_failure:
sys.exit(1)

Expand Down Expand Up @@ -203,16 +205,10 @@ def progress_callback(test):
display.print_header()
try:
execute_in_tmp_dir(run, litConfig)
display.clear(interrupted=False)
except KeyboardInterrupt:
#TODO(yln): should we attempt to cleanup the progress bar here?
sys.exit(2)
# TODO(yln): display.finish_interrupted(), which shows the most recently started test
# TODO(yln): change display to update when test starts, not when test completes
# Ensure everything still works with SimpleProgressBar as well
# finally:
# display.clear()

display.clear()
display.clear(interrupted=True)
print(' [interrupted by user]')

def execute_in_tmp_dir(run, litConfig):
# Create a temp directory inside the normal temp directory so that we can
Expand Down Expand Up @@ -247,7 +243,7 @@ def execute_in_tmp_dir(run, litConfig):

def print_summary(tests, elapsed, opts):
if not opts.quiet:
print('Testing Time: %.2fs' % elapsed)
print('\nTesting Time: %.2fs' % elapsed)

byCode = {}
for test in tests:
Expand Down Expand Up @@ -296,6 +292,7 @@ def print_summary(tests, elapsed, opts):
print(' %s: %d' % (name,N))

def write_test_results(tests, lit_config, elapsed, output_path):
# TODO(yln): audit: unexecuted tests
# Construct the data we will write.
data = {}
# Encode the current lit version as a schema version.
Expand Down Expand Up @@ -350,6 +347,7 @@ def write_test_results(tests, lit_config, elapsed, output_path):
f.close()

def write_test_results_xunit(tests, opts):
# TODO(yln): audit: unexecuted tests
from xml.sax.saxutils import quoteattr
# Collect the tests, indexed by test suite
by_suite = {}
Expand Down

0 comments on commit 718d68e

Please sign in to comment.