From: Julian Lettner Date: Mon, 14 Oct 2019 21:23:40 +0000 (+0000) Subject: [lit] Create Run object later and only when it is needed X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=112183e642020b0825d84fd560f1ace65a1783cc;p=llvm [lit] Create Run object later and only when it is needed Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D68843 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374823 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/lit/lit/main.py b/utils/lit/lit/main.py index e78cc72ffe4..b0151ec3cfe 100755 --- a/utils/lit/lit/main.py +++ b/utils/lit/lit/main.py @@ -88,8 +88,7 @@ def main_with_tmp(builtinParameters): echo_all_commands = opts.echoAllCommands) # Perform test discovery. - run = lit.run.Run(litConfig, - lit.discovery.find_tests_for_inputs(litConfig, opts.test_paths)) + tests = lit.discovery.find_tests_for_inputs(litConfig, opts.test_paths) # After test discovery the configuration might have changed # the maxIndividualTestTime. If we explicitly set this on the @@ -105,23 +104,23 @@ def main_with_tmp(builtinParameters): litConfig.maxIndividualTestTime = opts.maxIndividualTestTime if opts.showSuites or opts.showTests: - print_suites_or_tests(run, opts) + print_suites_or_tests(tests, opts) return # Select and order the tests. - numTotalTests = len(run.tests) + numTotalTests = len(tests) if opts.filter: - run.tests = [t for t in run.tests if opts.filter.search(t.getFullName())] + tests = [t for t in tests if opts.filter.search(t.getFullName())] - order_tests(run, opts) + order_tests(tests, opts) # Then optionally restrict our attention to a shard of the tests. if (opts.numShards is not None) or (opts.runShard is not None): - num_tests = len(run.tests) + num_tests = len(tests) # Note: user views tests and shard numbers counting from 1. test_ixs = range(opts.runShard - 1, num_tests, opts.numShards) - run.tests = [run.tests[i] for i in test_ixs] + tests = [tests[i] for i in test_ixs] # Generate a preview of the first few test indices in the shard # to accompany the arithmetic expression, for clarity. preview_len = 3 @@ -130,29 +129,29 @@ def main_with_tmp(builtinParameters): ix_preview += ", ..." litConfig.note('Selecting shard %d/%d = size %d/%d = tests #(%d*k)+%d = [%s]' % (opts.runShard, opts.numShards, - len(run.tests), num_tests, + len(tests), num_tests, opts.numShards, opts.runShard, ix_preview)) # Finally limit the number of tests, if desired. if opts.maxTests is not None: - run.tests = run.tests[:opts.maxTests] + tests = tests[:opts.maxTests] # Don't create more workers than tests. - opts.numWorkers = min(len(run.tests), opts.numWorkers) + opts.numWorkers = min(len(tests), opts.numWorkers) - testing_time = run_tests(run, litConfig, opts, numTotalTests) + testing_time = run_tests(tests, litConfig, opts, numTotalTests) if not opts.quiet: print('Testing Time: %.2fs' % (testing_time,)) # Write out the test data, if requested. if opts.output_path is not None: - write_test_results(run, litConfig, testing_time, opts.output_path) + write_test_results(tests, litConfig, testing_time, opts.output_path) # List test results organized by kind. hasFailures = False byCode = {} - for test in run.tests: + for test in tests: if test.result.code not in byCode: byCode[test.result.code] = [] byCode[test.result.code].append(test) @@ -179,10 +178,10 @@ def main_with_tmp(builtinParameters): print(' %s' % test.getFullName()) sys.stdout.write('\n') - if opts.timeTests and run.tests: + if opts.timeTests and tests: # Order by time. test_times = [(test.getFullName(), test.result.elapsed) - for test in run.tests] + for test in tests] lit.util.printHistogram(test_times, title='Tests') for name,code in (('Expected Passes ', lit.Test.PASS), @@ -200,7 +199,7 @@ def main_with_tmp(builtinParameters): print(' %s: %d' % (name,N)) if opts.xunit_output_file: - write_test_results_xunit(run, opts) + write_test_results_xunit(tests, opts) # If we encountered any additional errors, exit abnormally. if litConfig.numErrors: @@ -225,10 +224,10 @@ def create_user_parameters(builtinParameters, opts): userParams[name] = val return userParams -def print_suites_or_tests(run, opts): +def print_suites_or_tests(tests, opts): # Aggregate the tests by suite. suitesAndTests = {} - for result_test in run.tests: + for result_test in tests: if result_test.suite not in suitesAndTests: suitesAndTests[result_test.suite] = [] suitesAndTests[result_test.suite].append(result_test) @@ -254,14 +253,14 @@ def print_suites_or_tests(run, opts): for test in ts_tests: print(' %s' % (test.getFullName(),)) -def order_tests(run, opts): +def order_tests(tests, opts): if opts.shuffle: import random - random.shuffle(run.tests) + random.shuffle(tests) elif opts.incremental: - run.tests.sort(key = by_mtime, reverse = True) + tests.sort(key=by_mtime, reverse=True) else: - run.tests.sort(key = lambda t: (not t.isEarlyTest(), t.getFullName())) + tests.sort(key=lambda t: (not t.isEarlyTest(), t.getFullName())) def by_mtime(test): fname = test.getFilePath() @@ -299,11 +298,13 @@ def increase_process_limit(litConfig, opts): except: pass -def run_tests(run, litConfig, opts, numTotalTests): +def run_tests(tests, litConfig, opts, numTotalTests): increase_process_limit(litConfig, opts) - display = lit.display.create_display(opts, len(run.tests), - numTotalTests, opts.numWorkers) + run = lit.run.Run(litConfig, tests) + + display = lit.display.create_display(opts, len(tests), numTotalTests, + opts.numWorkers) def progress_callback(test): display.update(test) if opts.incremental: @@ -319,7 +320,7 @@ def run_tests(run, litConfig, opts, numTotalTests): display.finish() return testing_time -def write_test_results(run, lit_config, testing_time, output_path): +def write_test_results(tests, lit_config, testing_time, output_path): try: import json except ImportError: @@ -335,7 +336,7 @@ def write_test_results(run, lit_config, testing_time, output_path): # Encode the tests. data['tests'] = tests_data = [] - for test in run.tests: + for test in tests: test_data = { 'name' : test.getFullName(), 'code' : test.result.code.name, @@ -377,11 +378,11 @@ def write_test_results(run, lit_config, testing_time, output_path): finally: f.close() -def write_test_results_xunit(run, opts): +def write_test_results_xunit(tests, opts): from xml.sax.saxutils import quoteattr # Collect the tests, indexed by test suite by_suite = {} - for result_test in run.tests: + for result_test in tests: suite = result_test.suite.config.name if suite not in by_suite: by_suite[suite] = {