Skip to content

Commit 04ce013

Browse files
authored
Reapply "[llvm][lit] Add option to run only the failed tests" (#171588)
This reverts commit 3847648. Relands #158043 which got auto-merged on a revision which wasn't approved. The only addition to the approved version was that we adjust how we set the time for failed tests. We used to just assign it the negative value of the elapsed time. But if the test failed with `0` seconds (which some of the new tests do), we would mark it `-0`. But the check for whether something failed checks for `time < 0`. That messed with the new `--filter-failed` option of this PR. This was only an issue on Windows CI, but presumably can happen on any platform. Happy to do this in a separate PR. ---- Original PR 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 123d4d9 commit 04ce013

File tree

13 files changed

+90
-1
lines changed

13 files changed

+90
-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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ 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+
26+
# Mark the elapsed time for failed tests as negative so LIT can distingiush failed from
27+
# successful test runs just based on the time value. For this heuristic to work for tests
28+
# whose elapsed time is '0', we set it to a small negative constant.
29+
time = min(-t.result.elapsed, -1.0e-6) if t.isFailure() else t.result.elapsed
30+
2631
# The "path" here is only used as a key into a dictionary. It is never
2732
# used as an actual path to a filesystem API, therefore we use '/' as
2833
# 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)