Skip to content

Commit 54a9b4c

Browse files
author
Julian Lettner
committed
[lit] Better/earlier errors for empty runs
Fail early, when we discover no tests at all, or filter out all of them. There is also `--allow-empty-runs` to disable test to allow workflows like `LIT_FILTER=abc ninja check-all`. Apparently `check-all` invokes lit multiple times if certain projects are enabled, which would produce unwanted "empty runs". Specify via `LIT_OPTS=--allow-empty-runs`. There are 3 causes for empty runs: 1) No tests discovered. This is always an error. Fix test suite config or command line. 2) All tests filtered out. This is an error by default, but can be suppressed via `--alow-empty-runs`. Should prevent accidentally passing empty runs, but allow the workflow above. 3) The number of shards is greater than the number of tests. Currently, this is never an error. Personally, I think we should consider making this an error by default; if this happens, you are doing something wrong. I added a warning but did not change the behavior, since this warrants more discussion. Reviewed By: atrick, jdenny Differential Revision: https://reviews.llvm.org/D70105
1 parent 83dcb34 commit 54a9b4c

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

llvm/utils/lit/lit/cl_arguments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def parse_args():
109109
dest="maxFailures",
110110
help="Stop execution after the given number of failures.",
111111
type=_positive_int)
112+
execution_group.add_argument("--allow-empty-runs",
113+
help="Do not fail the run if all tests are filtered out",
114+
action="store_true")
112115

113116
selection_group = parser.add_argument_group("Test Selection")
114117
selection_group.add_argument("--max-tests",

llvm/utils/lit/lit/main.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def main(builtin_params = {}):
4343
echo_all_commands = opts.echoAllCommands)
4444

4545
tests = lit.discovery.find_tests_for_inputs(litConfig, opts.test_paths)
46+
if not tests:
47+
sys.stderr.write('Did not disover any tests for provided path(s).\n')
48+
sys.exit(2)
4649

4750
# Command line overrides configuration for maxIndividualTestTime.
4851
if opts.maxIndividualTestTime is not None: # `not None` is important (default: 0)
@@ -63,12 +66,27 @@ def main(builtin_params = {}):
6366

6467
if opts.filter:
6568
tests = [t for t in tests if opts.filter.search(t.getFullName())]
69+
if not tests:
70+
sys.stderr.write('Filter did not match any tests '
71+
'(of %d discovered). ' % numTotalTests)
72+
if opts.allow_empty_runs:
73+
sys.stderr.write('Suppressing error because '
74+
"'--allow-empty-runs' was specified.\n")
75+
sys.exit(0)
76+
else:
77+
sys.stderr.write("Use '--allow-empty-runs' to suppress this "
78+
'error.\n')
79+
sys.exit(2)
6680

6781
determine_order(tests, opts.order)
6882

6983
if opts.shard:
7084
(run, shards) = opts.shard
7185
tests = filter_by_shard(tests, run, shards, litConfig)
86+
if not tests:
87+
sys.stderr.write('Shard does not contain any tests. Consider '
88+
'decreasing the number of shards.\n')
89+
sys.exit(0)
7290

7391
if opts.max_tests:
7492
tests = tests[:opts.max_tests]
@@ -87,7 +105,7 @@ def main(builtin_params = {}):
87105
write_test_results_xunit(tests, opts)
88106

89107
if litConfig.numErrors:
90-
sys.stderr.write('\n%d error(s), exiting.\n' % litConfig.numErrors)
108+
sys.stderr.write('\n%d error(s) in tests.\n' % litConfig.numErrors)
91109
sys.exit(2)
92110

93111
if litConfig.numWarnings:

llvm/utils/lit/lit/run.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def acquire(self): pass
1313
def release(self): pass
1414

1515
def create_run(tests, lit_config, workers, progress_callback, timeout=None):
16-
# TODO(yln) assert workers > 0
16+
assert workers > 0
1717
if workers == 1:
1818
return SerialRun(tests, lit_config, progress_callback, timeout)
1919
return ParallelRun(tests, lit_config, progress_callback, timeout, workers)
@@ -45,9 +45,6 @@ def execute(self):
4545
computed. Tests which were not actually executed (for any reason) will
4646
be given an UNRESOLVED result.
4747
"""
48-
if not self.tests:
49-
return 0.0
50-
5148
self.failure_count = 0
5249
self.hit_max_failures = False
5350

llvm/utils/lit/tests/selecting.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
# RUN: %{lit} %{inputs}/discovery | FileCheck --check-prefix=CHECK-BASIC %s
22
# CHECK-BASIC: Testing: 5 tests
33

4+
5+
# Check that we exit with an error if we do not discover any tests, even with --allow-empty-runs.
6+
#
7+
# RUN: not %{lit} %{inputs}/nonexistent 2>&1 | FileCheck --check-prefix=CHECK-BAD-PATH %s
8+
# RUN: not %{lit} %{inputs}/nonexistent --allow-empty-runs 2>&1 | FileCheck --check-prefix=CHECK-BAD-PATH %s
9+
# CHECK-BAD-PATH: Did not disover any tests for provided path(s).
10+
11+
# Check that we exit with an error if we filter out all tests, but allow it with --allow-empty-runs.
12+
#
13+
# RUN: not %{lit} --filter 'nonexistent' %{inputs}/discovery 2>&1 | FileCheck --check-prefixes=CHECK-BAD-FILTER,CHECK-BAD-FILTER-ERROR %s
14+
# RUN: %{lit} --filter 'nonexistent' --allow-empty-runs %{inputs}/discovery 2>&1 | FileCheck --check-prefixes=CHECK-BAD-FILTER,CHECK-BAD-FILTER-ALLOW %s
15+
# CHECK-BAD-FILTER: Filter did not match any tests (of 5 discovered).
16+
# CHECK-BAD-FILTER-ERROR: Use '--allow-empty-runs' to suppress this error.
17+
# CHECK-BAD-FILTER-ALLOW: Suppressing error because '--allow-empty-runs' was specified.
18+
419
# Check that regex-filtering works, is case-insensitive, and can be configured via env var.
520
#
621
# RUN: %{lit} --filter 'o[a-z]e' %{inputs}/discovery | FileCheck --check-prefix=CHECK-FILTER %s
722
# RUN: %{lit} --filter 'O[A-Z]E' %{inputs}/discovery | FileCheck --check-prefix=CHECK-FILTER %s
823
# RUN: env LIT_FILTER='o[a-z]e' %{lit} %{inputs}/discovery | FileCheck --check-prefix=CHECK-FILTER %s
924
# CHECK-FILTER: Testing: 2 of 5 tests
1025

26+
1127
# Check that maximum counts work
1228
#
1329
# RUN: %{lit} --max-tests 3 %{inputs}/discovery | FileCheck --check-prefix=CHECK-MAX %s
@@ -68,15 +84,13 @@
6884
#
6985
# RUN: %{lit} --num-shards 100 --run-shard 6 %{inputs}/discovery >%t.out 2>%t.err
7086
# RUN: FileCheck --check-prefix=CHECK-SHARD-BIG-ERR2 < %t.err %s
71-
# RUN: FileCheck --check-prefix=CHECK-SHARD-BIG-OUT2 < %t.out %s
7287
# CHECK-SHARD-BIG-ERR2: note: Selecting shard 6/100 = size 0/5 = tests #(100*k)+6 = []
73-
# CHECK-SHARD-BIG-OUT2: Testing: 0 of 5 tests
88+
# CHECK-SHARD-BIG-ERR2: Shard does not contain any tests. Consider decreasing the number of shards.
7489
#
7590
# RUN: %{lit} --num-shards 100 --run-shard 50 %{inputs}/discovery >%t.out 2>%t.err
7691
# RUN: FileCheck --check-prefix=CHECK-SHARD-BIG-ERR3 < %t.err %s
77-
# RUN: FileCheck --check-prefix=CHECK-SHARD-BIG-OUT3 < %t.out %s
7892
# CHECK-SHARD-BIG-ERR3: note: Selecting shard 50/100 = size 0/5 = tests #(100*k)+50 = []
79-
# CHECK-SHARD-BIG-OUT3: Testing: 0 of 5 tests
93+
# CHECK-SHARD-BIG-ERR3: Shard does not contain any tests. Consider decreasing the number of shards.
8094

8195

8296
# Check that range constraints are enforced

0 commit comments

Comments
 (0)