aboutsummaryrefslogtreecommitdiff
path: root/utils/lit/lit/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/lit/lit/main.py')
-rwxr-xr-xutils/lit/lit/main.py50
1 files changed, 44 insertions, 6 deletions
diff --git a/utils/lit/lit/main.py b/utils/lit/lit/main.py
index ac3066eea725..689a2d55bcea 100755
--- a/utils/lit/lit/main.py
+++ b/utils/lit/lit/main.py
@@ -259,6 +259,14 @@ def main_with_tmp(builtinParameters):
help=("Only run tests with paths matching the given "
"regular expression"),
action="store", default=None)
+ selection_group.add_argument("--num-shards", dest="numShards", metavar="M",
+ help="Split testsuite into M pieces and only run one",
+ action="store", type=int,
+ default=os.environ.get("LIT_NUM_SHARDS"))
+ selection_group.add_argument("--run-shard", dest="runShard", metavar="N",
+ help="Run shard #N of the testsuite",
+ action="store", type=int,
+ default=os.environ.get("LIT_RUN_SHARD"))
debug_group = parser.add_argument_group("Debug and Experimental Options")
debug_group.add_argument("--debug",
@@ -270,12 +278,15 @@ def main_with_tmp(builtinParameters):
debug_group.add_argument("--show-tests", dest="showTests",
help="Show all discovered tests",
action="store_true", default=False)
- debug_group.add_argument("--use-processes", dest="useProcesses",
+ debug_group.add_argument("--use-process-pool", dest="executionStrategy",
+ help="Run tests in parallel with a process pool",
+ action="store_const", const="PROCESS_POOL")
+ debug_group.add_argument("--use-processes", dest="executionStrategy",
help="Run tests in parallel with processes (not threads)",
- action="store_true", default=True)
- debug_group.add_argument("--use-threads", dest="useProcesses",
+ action="store_const", const="PROCESSES")
+ debug_group.add_argument("--use-threads", dest="executionStrategy",
help="Run tests in parallel with threads (not processes)",
- action="store_false", default=True)
+ action="store_const", const="THREADS")
opts = parser.parse_args()
args = opts.test_paths
@@ -290,6 +301,9 @@ def main_with_tmp(builtinParameters):
if opts.numThreads is None:
opts.numThreads = lit.util.detectCPUs()
+ if opts.executionStrategy is None:
+ opts.executionStrategy = 'PROCESS_POOL'
+
if opts.maxFailures == 0:
parser.error("Setting --max-failures to 0 does not have any effect.")
@@ -327,7 +341,8 @@ def main_with_tmp(builtinParameters):
params = userParams,
config_prefix = opts.configPrefix,
maxIndividualTestTime = maxIndividualTestTime,
- maxFailures = opts.maxFailures)
+ maxFailures = opts.maxFailures,
+ parallelism_groups = {})
# Perform test discovery.
run = lit.run.Run(litConfig,
@@ -399,6 +414,29 @@ def main_with_tmp(builtinParameters):
else:
run.tests.sort(key = lambda t: (not t.isEarlyTest(), t.getFullName()))
+ # Then optionally restrict our attention to a shard of the tests.
+ if (opts.numShards is not None) or (opts.runShard is not None):
+ if (opts.numShards is None) or (opts.runShard is None):
+ parser.error("--num-shards and --run-shard must be used together")
+ if opts.numShards <= 0:
+ parser.error("--num-shards must be positive")
+ if (opts.runShard < 1) or (opts.runShard > opts.numShards):
+ parser.error("--run-shard must be between 1 and --num-shards (inclusive)")
+ num_tests = len(run.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]
+ # Generate a preview of the first few test indices in the shard
+ # to accompany the arithmetic expression, for clarity.
+ preview_len = 3
+ ix_preview = ", ".join([str(i+1) for i in test_ixs[:preview_len]])
+ if len(test_ixs) > preview_len:
+ 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,
+ 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]
@@ -449,7 +487,7 @@ def main_with_tmp(builtinParameters):
display = TestingProgressDisplay(opts, len(run.tests), progressBar)
try:
run.execute_tests(display, opts.numThreads, opts.maxTime,
- opts.useProcesses)
+ opts.executionStrategy)
except KeyboardInterrupt:
sys.exit(2)
display.finish()