Skip to content

Commit afa8903

Browse files
committed
[lit] Small cleanups in main.py
* Extract separate function for running tests from main * Push single-usage imports to point of usage * Remove unnecessary sys.exit(0) calls Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D68836 llvm-svn: 374602
1 parent ac36daf commit afa8903

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

llvm/utils/lit/lit/main.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99
from __future__ import absolute_import
1010
import os
1111
import platform
12-
import random
1312
import sys
1413
import time
15-
import tempfile
16-
import shutil
17-
from xml.sax.saxutils import quoteattr
1814

1915
import lit.cl_arguments
2016
import lit.discovery
@@ -32,6 +28,7 @@ def main(builtinParameters = {}):
3228
# the buildbot level.
3329
lit_tmp = None
3430
if 'LIT_PRESERVES_TMP' not in os.environ:
31+
import tempfile
3532
lit_tmp = tempfile.mkdtemp(prefix="lit_tmp_")
3633
os.environ.update({
3734
'TMPDIR': lit_tmp,
@@ -48,6 +45,7 @@ def main(builtinParameters = {}):
4845
finally:
4946
if lit_tmp:
5047
try:
48+
import shutil
5149
shutil.rmtree(lit_tmp)
5250
except:
5351
# FIXME: Re-try after timeout on Windows.
@@ -142,23 +140,7 @@ def main_with_tmp(builtinParameters):
142140
# Don't create more workers than tests.
143141
opts.numWorkers = min(len(run.tests), opts.numWorkers)
144142

145-
increase_process_limit(litConfig, opts)
146-
147-
display = lit.display.create_display(opts, len(run.tests),
148-
numTotalTests, opts.numWorkers)
149-
def progress_callback(test):
150-
display.update(test)
151-
if opts.incremental:
152-
update_incremental_cache(test)
153-
154-
startTime = time.time()
155-
try:
156-
run.execute_tests(progress_callback, opts.numWorkers, opts.maxTime)
157-
except KeyboardInterrupt:
158-
sys.exit(2)
159-
testing_time = time.time() - startTime
160-
161-
display.finish()
143+
testing_time = run_tests(run, litConfig, opts, numTotalTests)
162144

163145
if not opts.quiet:
164146
print('Testing Time: %.2fs' % (testing_time,))
@@ -231,7 +213,6 @@ def progress_callback(test):
231213

232214
if hasFailures:
233215
sys.exit(1)
234-
sys.exit(0)
235216

236217

237218
def create_user_parameters(builtinParameters, opts):
@@ -273,11 +254,9 @@ def print_suites_or_tests(run, opts):
273254
for test in ts_tests:
274255
print(' %s' % (test.getFullName(),))
275256

276-
# Exit.
277-
sys.exit(0)
278-
279257
def order_tests(run, opts):
280258
if opts.shuffle:
259+
import random
281260
random.shuffle(run.tests)
282261
elif opts.incremental:
283262
run.tests.sort(key = by_mtime, reverse = True)
@@ -320,6 +299,26 @@ def increase_process_limit(litConfig, opts):
320299
except:
321300
pass
322301

302+
def run_tests(run, litConfig, opts, numTotalTests):
303+
increase_process_limit(litConfig, opts)
304+
305+
display = lit.display.create_display(opts, len(run.tests),
306+
numTotalTests, opts.numWorkers)
307+
def progress_callback(test):
308+
display.update(test)
309+
if opts.incremental:
310+
update_incremental_cache(test)
311+
312+
startTime = time.time()
313+
try:
314+
run.execute_tests(progress_callback, opts.numWorkers, opts.maxTime)
315+
except KeyboardInterrupt:
316+
sys.exit(2)
317+
testing_time = time.time() - startTime
318+
319+
display.finish()
320+
return testing_time
321+
323322
def write_test_results(run, lit_config, testing_time, output_path):
324323
try:
325324
import json
@@ -379,6 +378,7 @@ def write_test_results(run, lit_config, testing_time, output_path):
379378
f.close()
380379

381380
def write_test_results_xunit(run, opts):
381+
from xml.sax.saxutils import quoteattr
382382
# Collect the tests, indexed by test suite
383383
by_suite = {}
384384
for result_test in run.tests:

0 commit comments

Comments
 (0)