Skip to content

Commit 718d68e

Browse files
ylnJulian Lettner
authored and
Julian Lettner
committed
[lit] Attempt to print test summary on CTRL+C
1 parent 506144d commit 718d68e

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

llvm/utils/lit/lit/ProgressBar.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ def update(self, percent, message):
201201
sys.stdout.flush()
202202
self.atIndex = next
203203

204-
def clear(self):
205-
if self.atIndex is not None:
204+
def clear(self, interrupted):
205+
if self.atIndex is not None and not interrupted:
206206
sys.stdout.write('\n')
207207
sys.stdout.flush()
208208
self.atIndex = None
@@ -275,11 +275,14 @@ def update(self, percent, message):
275275
if not self.term.XN:
276276
sys.stdout.flush()
277277

278-
def clear(self):
278+
def clear(self, interrupted):
279279
if not self.cleared:
280280
sys.stdout.write(self.BOL + self.term.CLEAR_EOL +
281281
self.term.UP + self.term.CLEAR_EOL +
282282
self.term.UP + self.term.CLEAR_EOL)
283+
if interrupted: # ^C creates extra line. Gobble it up!
284+
sys.stdout.write(self.term.UP + self.term.CLEAR_EOL)
285+
sys.stdout.write('^C')
283286
sys.stdout.flush()
284287
self.cleared = 1
285288

llvm/utils/lit/lit/display.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def create_display(opts, tests, total_tests, workers):
2424
class NopDisplay(object):
2525
def print_header(self): pass
2626
def update(self, test): pass
27-
def clear(self): pass
27+
def clear(self, interrupted): pass
2828

2929

3030
class Display(object):
@@ -49,7 +49,7 @@ def update(self, test):
4949
(not self.opts.quiet and not self.opts.succinct)
5050
if show_result:
5151
if self.progress_bar:
52-
self.progress_bar.clear()
52+
self.progress_bar.clear(interrupted=False)
5353
self.print_result(test)
5454

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

61-
def clear(self):
61+
def clear(self, interrupted):
6262
if self.progress_bar:
63-
self.progress_bar.clear()
64-
sys.stdout.write('\n')
63+
self.progress_bar.clear(interrupted)
6564

6665
def print_result(self, test):
6766
# Show the test result line.

llvm/utils/lit/lit/main.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def main(builtin_params = {}):
9797
run_tests(tests, litConfig, opts, numTotalTests)
9898
elapsed = time.time() - start
9999

100-
print_summary(tests, elapsed, opts)
100+
executed_tests = [t for t in tests if t.result]
101+
102+
print_summary(executed_tests, elapsed, opts)
101103

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

114-
has_failure = any(t.isFailure() for t in tests)
116+
has_failure = any(t.isFailure() for t in executed_tests)
115117
if has_failure:
116118
sys.exit(1)
117119

@@ -203,16 +205,10 @@ def progress_callback(test):
203205
display.print_header()
204206
try:
205207
execute_in_tmp_dir(run, litConfig)
208+
display.clear(interrupted=False)
206209
except KeyboardInterrupt:
207-
#TODO(yln): should we attempt to cleanup the progress bar here?
208-
sys.exit(2)
209-
# TODO(yln): display.finish_interrupted(), which shows the most recently started test
210-
# TODO(yln): change display to update when test starts, not when test completes
211-
# Ensure everything still works with SimpleProgressBar as well
212-
# finally:
213-
# display.clear()
214-
215-
display.clear()
210+
display.clear(interrupted=True)
211+
print(' [interrupted by user]')
216212

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

248244
def print_summary(tests, elapsed, opts):
249245
if not opts.quiet:
250-
print('Testing Time: %.2fs' % elapsed)
246+
print('\nTesting Time: %.2fs' % elapsed)
251247

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

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

352349
def write_test_results_xunit(tests, opts):
350+
# TODO(yln): audit: unexecuted tests
353351
from xml.sax.saxutils import quoteattr
354352
# Collect the tests, indexed by test suite
355353
by_suite = {}

0 commit comments

Comments
 (0)