Skip to content

Commit 02bb64f

Browse files
committed
[lit] add --max-retries-per-test execution option
When packaging LLVM we've seen arbitrary tests fail. It happened sporadically and most of the times the test do work if they are run a second time on the next day. The tests themselves were always different and we didn't know ahead of time which ones we wanted to re-run. That's we filter-out a lot of `libomp` and `libarcher` tests [1]. This change allows us to set `LIT_OPTS="--max-retries-per-test=12"` when running any "check-XXX" build target. Then any lit test will at most be re-run 12 times, unless there's an `ALLOW_RETRIES:` in one of the test scripts that's specifying a different value than `12`. `12` is just an example here, any positive integer will work. Please note, that this only adds the possibility to re-run lit tests. It does not actually do it until the caller specifies `--maxRetriesPerTest=<POSITIVE_INT>` either on a call to `lit` or in `LIT_OPTS`. Also note, that one can still use `ALLOW_RETRIES:` in test scripts and it will always rule over `--max-retries-per-test`. There's a test for this that covers this. [1]: https://src.fedoraproject.org/rpms/llvm/blob/rawhide/f/llvm.spec#_2326 Downstream PR to make use of the `--max-retries-per-test` option: https://src.fedoraproject.org/rpms/llvm/pull-request/434 Downstream ticket: https://issues.redhat.com/browse/LLVM-145
1 parent 3f0a530 commit 02bb64f

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

llvm/utils/lit/lit/cl_arguments.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ def parse_args():
199199
"0 means no time limit. [Default: 0]",
200200
type=_non_negative_int,
201201
)
202+
execution_group.add_argument(
203+
"--max-retries-per-test",
204+
dest="maxRetriesPerTest",
205+
metavar="N",
206+
help="Maximum number of allowed retry attempts per test (NOTE: 'ALLOWED_RETRIES:' always takes precedence)",
207+
type=_positive_int,
208+
)
202209
execution_group.add_argument(
203210
"--max-failures",
204211
help="Stop execution after the given number of failures.",

llvm/utils/lit/lit/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def main(builtin_params={}):
7979
)
8080
lit_config.maxIndividualTestTime = opts.maxIndividualTestTime
8181

82+
if opts.maxRetriesPerTest is not None:
83+
lit_config.test_retry_attempts = opts.maxRetriesPerTest
84+
8285
determine_order(discovered_tests, opts.order)
8386

8487
selected_tests = [
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import lit.formats
2+
3+
config.name = "max_retries_per_test"
4+
config.suffixes = [".py"]
5+
config.test_format = lit.formats.ShTest()
6+
config.test_source_root = None
7+
config.test_exec_root = None
8+
9+
config.substitutions.append(("%python", lit_config.params.get("python", "")))
10+
config.substitutions.append(("%counter", lit_config.params.get("counter", "")))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# RUN: "%python" "%s" "%counter"
2+
3+
import sys
4+
import os
5+
6+
counter_file = sys.argv[1]
7+
8+
# The first time the test is run, initialize the counter to 1.
9+
if not os.path.exists(counter_file):
10+
with open(counter_file, "w") as counter:
11+
counter.write("1")
12+
13+
# Succeed if this is the fourth time we're being run.
14+
with open(counter_file, "r") as counter:
15+
num = int(counter.read())
16+
if num == 4:
17+
sys.exit(0)
18+
19+
# Otherwise, increment the counter and fail
20+
with open(counter_file, "w") as counter:
21+
counter.write(str(num + 1))
22+
sys.exit(1)

llvm/utils/lit/tests/allow-retries.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,14 @@
7070
# CHECK-TEST7: # executed command: export LLVM_PROFILE_FILE=
7171
# CHECK-TEST7-NOT: # executed command: export LLVM_PROFILE_FILE=
7272
# CHECK-TEST7: Passed With Retry: 1
73+
74+
# This test checks that a test can be re-run if the "--max-retries-per-test" is specified and otherwise
75+
# no ALLOW_RETRIES: is used in tests and no config.test_retry_attempts is adjusted in the test suite config.
76+
# This test checks that the config-wide test_retry_attempts property is used
77+
# when no ALLOW_RETRIES keyword is present.
78+
# TODO(kwk): Add test that ensures ALLOW_RETRIES: takes precedence over the --max-retries-per-test option.
79+
#
80+
# RUN: rm -f %t.counter
81+
# RUN: %{lit} %{inputs}/max_retries_per_test/test.py --max-retries-per-test=10 -Dcounter=%t.counter -Dpython=%{python} | FileCheck --check-prefix=CHECK-TEST8 %s --color --dump-input=always
82+
# CHECK-TEST8: SPECIFY ME BETTER
83+

0 commit comments

Comments
 (0)