Skip to content

Commit 951795a

Browse files
authored
[llvm][lit] Add option to run only the failed tests (#158043)
This patch adds a new `--filter-failed` option to `llvm-lit`, which when set, will only run the tests that have previously failed.
1 parent 53674e2 commit 951795a

File tree

13 files changed

+85
-1
lines changed

13 files changed

+85
-1
lines changed

llvm/docs/CommandGuide/lit.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ The timing data is stored in the `test_exec_root` in a file named
314314
place of this option, which is especially useful in environments where the
315315
call to ``lit`` is issued indirectly.
316316

317+
.. option:: --filter-failed
318+
319+
Run only those tests that previously failed. Tests that have been newly added
320+
but not yet run are not included.
321+
317322
.. option:: --xfail LIST
318323

319324
Treat those tests whose name is in the semicolon separated list ``LIST`` as

llvm/utils/lit/lit/TestTimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def record_test_times(tests, lit_config):
2222
continue
2323
if not t.suite.exec_root in times_by_suite:
2424
times_by_suite[t.suite.exec_root] = read_test_times(t.suite)
25-
time = -t.result.elapsed if t.isFailure() else t.result.elapsed
25+
time = min(-t.result.elapsed, -1.0e-6) if t.isFailure() else t.result.elapsed
2626
# The "path" here is only used as a key into a dictionary. It is never
2727
# used as an actual path to a filesystem API, therefore we use '/' as
2828
# the canonical separator so that Unix and Windows machines can share

llvm/utils/lit/lit/cl_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,12 @@ def parse_args():
423423
help="Filter out tests with paths matching the given regular expression",
424424
default=os.environ.get("LIT_FILTER_OUT", "^$"),
425425
)
426+
selection_group.add_argument(
427+
"--filter-failed",
428+
dest="filterFailed",
429+
help="Only run tests which failed in the previous run",
430+
action="store_true",
431+
)
426432
selection_group.add_argument(
427433
"--xfail",
428434
metavar="LIST",

llvm/utils/lit/lit/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ def main(builtin_params={}):
9090
and not opts.filter_out.search(t.getFullName())
9191
]
9292

93+
if opts.filterFailed:
94+
selected_tests = [t for t in selected_tests if t.previous_failure]
95+
9396
if not selected_tests:
9497
sys.stderr.write(
9598
"error: filter did not match any tests "
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RUN: false
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import lit.formats
2+
3+
config.name = "filter-failed"
4+
config.suffixes = [".txt"]
5+
config.test_format = lit.formats.ShTest()
6+
config.test_source_root = None
7+
config.test_exec_root = None
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RUN: true

llvm/utils/lit/tests/Inputs/filter-failed/unresolved.txt

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RUN: false
2+
XFAIL: *
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RUN: true
2+
XFAIL: *

0 commit comments

Comments
 (0)