Skip to content

Commit 6918314

Browse files
authored
[lit] show retry attempts (#142413)
If a test took more than one attempt to complete, show the number of attempts and the maximum allowed attempts as `2 of 4 attempts` inside the `<progress info>` (see [TEST RUN OUTPUT FORMAT](https://llvm.org/docs/CommandGuide/lit.html#test-run-output-format)). NOTE: Additionally this is a fixup for #141851 where the tests were not quite right. `max-retries-per-test/allow-retries-test_retry_attempts/test.py` was added but never used there. Now we're calling it. To correlate better between the test output and the test script I've used higher numbers of max allowed retries.
1 parent 470f456 commit 6918314

File tree

8 files changed

+46
-15
lines changed

8 files changed

+46
-15
lines changed

llvm/docs/CommandGuide/lit.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,14 @@ newline.
688688
The ``<progress info>`` field can be used to report progress information such
689689
as (1/300) or can be empty, but even when empty the parentheses are required.
690690

691+
Should a test be allowed retries (see ``ALLOW_RETRIES:`` annotation) and it
692+
needed more than one attempt to succeed, then ``<progress info>`` is extended
693+
by this information:
694+
695+
.. code-block:: none
696+
697+
, <num_attempts_made> of <max_allowed_attempts> attempts
698+
691699
Each test result may include additional (multiline) log information in the
692700
following format:
693701

llvm/utils/lit/lit/Test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ def toMetricValue(value):
151151
class Result(object):
152152
"""Wrapper for the results of executing an individual test."""
153153

154-
def __init__(self, code, output="", elapsed=None):
154+
def __init__(
155+
self, code, output="", elapsed=None, attempts=1, max_allowed_attempts=None
156+
):
155157
# The result code.
156158
self.code = code
157159
# The test output.
@@ -164,6 +166,10 @@ def __init__(self, code, output="", elapsed=None):
164166
self.metrics = {}
165167
# The micro-test results reported by this test.
166168
self.microResults = {}
169+
# How often was the test run?
170+
self.attempts = attempts
171+
# How many attempts were allowed for this test
172+
self.max_allowed_attempts = max_allowed_attempts
167173

168174
def addMetric(self, name, value):
169175
"""

llvm/utils/lit/lit/TestRunner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,9 @@ def runOnce(
22922292
if err:
22932293
output += """Command Output (stderr):\n--\n%s\n--\n""" % (err,)
22942294

2295-
return lit.Test.Result(status, output)
2295+
return lit.Test.Result(
2296+
status, output, attempts=i + 1, max_allowed_attempts=attempts
2297+
)
22962298

22972299

22982300
def executeShTest(

llvm/utils/lit/lit/display.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,20 @@ def clear(self, interrupted):
117117
def print_result(self, test):
118118
# Show the test result line.
119119
test_name = test.getFullName()
120+
121+
extra_info = ""
122+
if test.result.attempts > 1:
123+
extra_info = f", {test.result.attempts} of {test.result.max_allowed_attempts} attempts"
124+
120125
print(
121-
"%s: %s (%d of %d)"
122-
% (test.result.code.name, test_name, self.completed, self.num_tests)
126+
"%s: %s (%d of %d%s)"
127+
% (
128+
test.result.code.name,
129+
test_name,
130+
self.completed,
131+
self.num_tests,
132+
extra_info,
133+
)
123134
)
124135

125136
# Show the test failure output, if requested.

llvm/utils/lit/tests/Inputs/max-retries-per-test/allow-retries-no-test_retry_attempts/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ALLOW_RETRIES: 3
1+
# ALLOW_RETRIES: 8
22
# RUN: "%python" "%s" "%counter"
33

44
import sys

llvm/utils/lit/tests/Inputs/max-retries-per-test/allow-retries-test_retry_attempts/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ALLOW_RETRIES: 3
1+
# ALLOW_RETRIES: 10
22
# RUN: "%python" "%s" "%counter"
33

44
import sys

llvm/utils/lit/tests/Inputs/max-retries-per-test/no-allow-retries-test_retry_attempts/lit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ config.test_exec_root = None
99
config.substitutions.append(("%python", lit_config.params.get("python", "")))
1010
config.substitutions.append(("%counter", lit_config.params.get("counter", "")))
1111

12-
config.test_retry_attempts = 3
12+
config.test_retry_attempts = 9

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# RUN: not %{lit} %{inputs}/allow-retries/does-not-succeed-within-limit.py -v |\
2323
# RUN: FileCheck --check-prefix=CHECK-TEST3 -match-full-lines %s
2424
#
25-
# CHECK-TEST3: FAIL: allow-retries :: does-not-succeed-within-limit.py (1 of 1)
25+
# CHECK-TEST3: FAIL: allow-retries :: does-not-succeed-within-limit.py (1 of 1, 4 of 4 attempts)
2626
# CHECK-TEST3-NEXT: {{\**}} TEST 'allow-retries :: does-not-succeed-within-limit.py' FAILED {{\**}}
2727
# CHECK-TEST3-NEXT: Exit Code: 1
2828
# CHECK-TEST3-EMPTY:
@@ -72,49 +72,53 @@
7272
# CHECK-TEST7: Passed With Retry: 1
7373

7474
# This test only passes on the 4th try. Here we check that a test can be re-run when:
75-
# * The "--max-retries-per-test" is specified high enough (3).
75+
# * The "--max-retries-per-test" is specified high enough (7).
7676
# * No ALLOW_RETRIES keyword is used in the test script.
7777
# * No config.test_retry_attempts is adjusted in the test suite config file.
7878
# RUN: rm -f %t.counter
7979
# RUN: %{lit} %{inputs}/max-retries-per-test/no-allow-retries-no-test_retry_attempts/test.py \
80-
# RUN: --max-retries-per-test=3 \
80+
# RUN: --max-retries-per-test=7 \
8181
# RUN: -Dcounter=%t.counter \
8282
# RUN: -Dpython=%{python} \
8383
# RUN: | FileCheck --check-prefix=CHECK-TEST8 %s
84+
# CHECK-TEST8: FLAKYPASS: no-allow-retries-no-test_retry_attempts :: test.py (1 of 1, 4 of 8 attempts)
8485
# CHECK-TEST8: Passed With Retry: 1
8586

8687
# This test only passes on the 4th try. Here we check that a test can be re-run when:
8788
# * The "--max-retries-per-test" is specified too low (2).
88-
# * ALLOW_RETRIES is specified high enough (3)
89+
# * ALLOW_RETRIES is specified high enough (8)
8990
# * No config.test_retry_attempts is adjusted in the test suite config file.
9091
# RUN: rm -f %t.counter
9192
# RUN: %{lit} %{inputs}/max-retries-per-test/allow-retries-no-test_retry_attempts/test.py \
9293
# RUN: --max-retries-per-test=2 \
9394
# RUN: -Dcounter=%t.counter \
9495
# RUN: -Dpython=%{python} \
9596
# RUN: | FileCheck --check-prefix=CHECK-TEST9 %s
97+
# CHECK-TEST9: FLAKYPASS: allow-retries-no-test_retry_attempts :: test.py (1 of 1, 4 of 9 attempts)
9698
# CHECK-TEST9: Passed With Retry: 1
9799

98100
# This test only passes on the 4th try. Here we check that a test can be re-run when:
99101
# * The "--max-retries-per-test" is specified too low (2).
100102
# * No ALLOW_RETRIES keyword is used in the test script.
101-
# * config.test_retry_attempts is set high enough (3).
103+
# * config.test_retry_attempts is set high enough (9).
102104
# RUN: rm -f %t.counter
103105
# RUN: %{lit} %{inputs}/max-retries-per-test/no-allow-retries-test_retry_attempts/test.py \
104106
# RUN: --max-retries-per-test=2 \
105107
# RUN: -Dcounter=%t.counter \
106108
# RUN: -Dpython=%{python} \
107109
# RUN: | FileCheck --check-prefix=CHECK-TEST10 %s
110+
# CHECK-TEST10: FLAKYPASS: no-allow-retries-test_retry_attempts :: test.py (1 of 1, 4 of 10 attempts)
108111
# CHECK-TEST10: Passed With Retry: 1
109112

110113
# This test only passes on the 4th try. Here we check that a test can be re-run when:
111114
# * The "--max-retries-per-test" is specified too low (1).
112-
# * ALLOW_RETRIES keyword set high enough (3).
113-
# * config.test_retry_attempts is set too low enough (2).
115+
# * ALLOW_RETRIES keyword is set high enough (10)
116+
# * config.test_retry_attempts is set too low (2).
114117
# RUN: rm -f %t.counter
115-
# RUN: %{lit} %{inputs}/max-retries-per-test/no-allow-retries-test_retry_attempts/test.py \
118+
# RUN: %{lit} %{inputs}/max-retries-per-test/allow-retries-test_retry_attempts/test.py \
116119
# RUN: --max-retries-per-test=1 \
117120
# RUN: -Dcounter=%t.counter \
118121
# RUN: -Dpython=%{python} \
119122
# RUN: | FileCheck --check-prefix=CHECK-TEST11 %s
123+
# CHECK-TEST11: FLAKYPASS: allow-retries-test_retry_attempts :: test.py (1 of 1, 4 of 11 attempts)
120124
# CHECK-TEST11: Passed With Retry: 1

0 commit comments

Comments
 (0)