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",
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")
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
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
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)
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)