diff options
-rw-r--r-- | llvm/utils/lit/lit/cl_arguments.py | 16 | ||||
-rwxr-xr-x | llvm/utils/lit/lit/main.py | 34 |
2 files changed, 28 insertions, 22 deletions
diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py index 152c51021b9..7b15041d190 100644 --- a/llvm/utils/lit/lit/cl_arguments.py +++ b/llvm/utils/lit/lit/cl_arguments.py @@ -121,10 +121,10 @@ def parse_args(): metavar="N", help="Maximum time to spend testing (in seconds)", type=_positive_int) - selection_group.add_argument("--shuffle", - help="Run tests in random order", + selection_group.add_argument("--shuffle", # TODO(yln): --order=random + help="Run tests in random order", # default or 'by-path' (+ isEarlyTest()) action="store_true") - selection_group.add_argument("-i", "--incremental", + selection_group.add_argument("-i", "--incremental", # TODO(yln): --order=failing-first help="Run modified and failing tests first (updates mtimes)", action="store_true") selection_group.add_argument("--filter", @@ -167,6 +167,14 @@ def parse_args(): if opts.echoAllCommands: opts.showOutput = True + # TODO(python3): Could be enum + if opts.shuffle: + opts.order = 'random' + elif opts.incremental: + opts.order = 'failing-first' + else: + opts.order = 'default' + if opts.numShards or opts.runShard: if not opts.numShards or not opts.runShard: parser.error("--num-shards and --run-shard must be used together") @@ -174,7 +182,7 @@ def parse_args(): parser.error("--run-shard must be between 1 and --num-shards (inclusive)") opts.shard = (opts.runShard, opts.numShards) else: - opts.shard = None + opts.shard = None return opts diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py index 6c38c5db7de..1276fdaf273 100755 --- a/llvm/utils/lit/lit/main.py +++ b/llvm/utils/lit/lit/main.py @@ -63,7 +63,7 @@ def main(builtin_params = {}): if opts.filter: tests = [t for t in tests if opts.filter.search(t.getFullName())] - determine_order(tests, opts) + determine_order(tests, opts.order) if opts.shard: (run, shards) = opts.shard @@ -132,19 +132,23 @@ def print_suites_or_tests(tests, opts): for test in ts_tests: print(' %s' % (test.getFullName(),)) -def determine_order(tests, opts): - if opts.shuffle: + +def determine_order(tests, order): + assert order in ['default', 'random', 'failing-first'] + if order == 'default': + tests.sort(key=lambda t: (not t.isEarlyTest(), t.getFullName())) + elif order == 'random': import random random.shuffle(tests) - elif opts.incremental: + else: def by_mtime(test): - try: - return os.path.getmtime(test.getFilePath()) - except: - return 0 + return os.path.getmtime(test.getFilePath()) tests.sort(key=by_mtime, reverse=True) - else: - tests.sort(key=lambda t: (not t.isEarlyTest(), t.getFullName())) + + +def touch_file(test): + if test.result.code.isFailure: + os.utime(test.getFilePath(), None) def filter_by_shard(tests, run, shards, litConfig): test_ixs = range(run - 1, len(tests), shards) @@ -164,19 +168,13 @@ def filter_by_shard(tests, run, shards, litConfig): litConfig.note(msg) return selected_tests -def update_incremental_cache(test): - if not test.result.code.isFailure: - return - fname = test.getFilePath() - os.utime(fname, None) - def run_tests(tests, litConfig, opts, numTotalTests): display = lit.display.create_display(opts, len(tests), numTotalTests, opts.numWorkers) def progress_callback(test): display.update(test) - if opts.incremental: - update_incremental_cache(test) + if opts.order == 'failing-first': + touch_file(test) run = lit.run.create_run(tests, litConfig, opts.numWorkers, progress_callback, opts.timeout) |