Skip to content

Commit bbc56dd

Browse files
committed
[lit] Small refactoring and cleanups in main.py
* Remove outdated precautions for Python versions < 2.7 * Remove dead code related to `maxIndividualTestTime` option * Move printing of test and result summary out of main into its own function Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D68847 llvm-svn: 375046
1 parent c0e6a92 commit bbc56dd

File tree

1 file changed

+55
-69
lines changed

1 file changed

+55
-69
lines changed

llvm/utils/lit/lit/main.py

Lines changed: 55 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
See lit.pod for more information.
77
"""
88

9-
from __future__ import absolute_import
109
import os
1110
import platform
1211
import sys
@@ -59,14 +58,6 @@ def main_with_tmp(builtinParameters):
5958
return
6059

6160
userParams = create_user_parameters(builtinParameters, opts)
62-
63-
# Decide what the requested maximum indvidual test time should be
64-
if opts.maxIndividualTestTime is not None:
65-
maxIndividualTestTime = opts.maxIndividualTestTime
66-
else:
67-
# Default is zero
68-
maxIndividualTestTime = 0
69-
7061
isWindows = platform.system() == 'Windows'
7162

7263
# Create the global config object.
@@ -82,18 +73,14 @@ def main_with_tmp(builtinParameters):
8273
isWindows = isWindows,
8374
params = userParams,
8475
config_prefix = opts.configPrefix,
85-
maxIndividualTestTime = maxIndividualTestTime,
8676
maxFailures = opts.maxFailures,
87-
parallelism_groups = {},
8877
echo_all_commands = opts.echoAllCommands)
8978

9079
# Perform test discovery.
9180
tests = lit.discovery.find_tests_for_inputs(litConfig, opts.test_paths)
9281

93-
# After test discovery the configuration might have changed
94-
# the maxIndividualTestTime. If we explicitly set this on the
95-
# command line then override what was set in the test configuration
96-
if opts.maxIndividualTestTime is not None:
82+
# Command line overrides configuration for maxIndividualTestTime.
83+
if opts.maxIndividualTestTime is not None: # `not None` is important (default: 0)
9784
if opts.maxIndividualTestTime != litConfig.maxIndividualTestTime:
9885
litConfig.note(('The test suite configuration requested an individual'
9986
' test timeout of {0} seconds but a timeout of {1} seconds was'
@@ -148,55 +135,7 @@ def main_with_tmp(builtinParameters):
148135
if opts.output_path is not None:
149136
write_test_results(tests, litConfig, testing_time, opts.output_path)
150137

151-
# List test results organized by kind.
152-
hasFailures = False
153-
byCode = {}
154-
for test in tests:
155-
if test.result.code not in byCode:
156-
byCode[test.result.code] = []
157-
byCode[test.result.code].append(test)
158-
if test.result.code.isFailure:
159-
hasFailures = True
160-
161-
# Print each test in any of the failing groups.
162-
for title,code in (('Unexpected Passing Tests', lit.Test.XPASS),
163-
('Failing Tests', lit.Test.FAIL),
164-
('Unresolved Tests', lit.Test.UNRESOLVED),
165-
('Unsupported Tests', lit.Test.UNSUPPORTED),
166-
('Expected Failing Tests', lit.Test.XFAIL),
167-
('Timed Out Tests', lit.Test.TIMEOUT)):
168-
if (lit.Test.XFAIL == code and not opts.show_xfail) or \
169-
(lit.Test.UNSUPPORTED == code and not opts.show_unsupported) or \
170-
(lit.Test.UNRESOLVED == code and (opts.maxFailures is not None)):
171-
continue
172-
elts = byCode.get(code)
173-
if not elts:
174-
continue
175-
print('*'*20)
176-
print('%s (%d):' % (title, len(elts)))
177-
for test in elts:
178-
print(' %s' % test.getFullName())
179-
sys.stdout.write('\n')
180-
181-
if opts.timeTests and tests:
182-
# Order by time.
183-
test_times = [(test.getFullName(), test.result.elapsed)
184-
for test in tests]
185-
lit.util.printHistogram(test_times, title='Tests')
186-
187-
for name,code in (('Expected Passes ', lit.Test.PASS),
188-
('Passes With Retry ', lit.Test.FLAKYPASS),
189-
('Expected Failures ', lit.Test.XFAIL),
190-
('Unsupported Tests ', lit.Test.UNSUPPORTED),
191-
('Unresolved Tests ', lit.Test.UNRESOLVED),
192-
('Unexpected Passes ', lit.Test.XPASS),
193-
('Unexpected Failures', lit.Test.FAIL),
194-
('Individual Timeouts', lit.Test.TIMEOUT)):
195-
if opts.quiet and not code.isFailure:
196-
continue
197-
N = len(byCode.get(code,[]))
198-
if N:
199-
print(' %s: %d' % (name,N))
138+
hasFailures = print_summary(tests, opts)
200139

201140
if opts.xunit_output_file:
202141
write_test_results_xunit(tests, opts)
@@ -320,12 +259,58 @@ def progress_callback(test):
320259
display.finish()
321260
return testing_time
322261

323-
def write_test_results(tests, lit_config, testing_time, output_path):
324-
try:
325-
import json
326-
except ImportError:
327-
lit_config.fatal('test output unsupported with Python 2.5')
262+
def print_summary(tests, opts):
263+
hasFailures = False
264+
byCode = {}
265+
for test in tests:
266+
if test.result.code not in byCode:
267+
byCode[test.result.code] = []
268+
byCode[test.result.code].append(test)
269+
if test.result.code.isFailure:
270+
hasFailures = True
271+
272+
# Print each test in any of the failing groups.
273+
for title,code in (('Unexpected Passing Tests', lit.Test.XPASS),
274+
('Failing Tests', lit.Test.FAIL),
275+
('Unresolved Tests', lit.Test.UNRESOLVED),
276+
('Unsupported Tests', lit.Test.UNSUPPORTED),
277+
('Expected Failing Tests', lit.Test.XFAIL),
278+
('Timed Out Tests', lit.Test.TIMEOUT)):
279+
if (lit.Test.XFAIL == code and not opts.show_xfail) or \
280+
(lit.Test.UNSUPPORTED == code and not opts.show_unsupported) or \
281+
(lit.Test.UNRESOLVED == code and (opts.maxFailures is not None)):
282+
continue
283+
elts = byCode.get(code)
284+
if not elts:
285+
continue
286+
print('*'*20)
287+
print('%s (%d):' % (title, len(elts)))
288+
for test in elts:
289+
print(' %s' % test.getFullName())
290+
sys.stdout.write('\n')
291+
292+
if opts.timeTests and tests:
293+
# Order by time.
294+
test_times = [(test.getFullName(), test.result.elapsed)
295+
for test in tests]
296+
lit.util.printHistogram(test_times, title='Tests')
297+
298+
for name,code in (('Expected Passes ', lit.Test.PASS),
299+
('Passes With Retry ', lit.Test.FLAKYPASS),
300+
('Expected Failures ', lit.Test.XFAIL),
301+
('Unsupported Tests ', lit.Test.UNSUPPORTED),
302+
('Unresolved Tests ', lit.Test.UNRESOLVED),
303+
('Unexpected Passes ', lit.Test.XPASS),
304+
('Unexpected Failures', lit.Test.FAIL),
305+
('Individual Timeouts', lit.Test.TIMEOUT)):
306+
if opts.quiet and not code.isFailure:
307+
continue
308+
N = len(byCode.get(code,[]))
309+
if N:
310+
print(' %s: %d' % (name,N))
311+
return hasFailures
328312

313+
def write_test_results(tests, lit_config, testing_time, output_path):
329314
# Construct the data we will write.
330315
data = {}
331316
# Encode the current lit version as a schema version.
@@ -373,6 +358,7 @@ def write_test_results(tests, lit_config, testing_time, output_path):
373358
# Write the output.
374359
f = open(output_path, 'w')
375360
try:
361+
import json
376362
json.dump(data, f, indent=2, sort_keys=True)
377363
f.write('\n')
378364
finally:

0 commit comments

Comments
 (0)