Skip to content

Commit b3746d6

Browse files
authored
Reland "[Utils] Add new --update-tests flag to llvm-lit" (#153821)
This reverts commit llvm/llvm-project@4c6b3f4 to reland the --update-tests feature, originally landed in llvm/llvm-project#108425.
1 parent cd1934c commit b3746d6

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

lit/LitConfig.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(
3939
parallelism_groups={},
4040
per_test_coverage=False,
4141
gtest_sharding=True,
42+
update_tests=False,
4243
):
4344
# The name of the test runner.
4445
self.progname = progname
@@ -91,6 +92,8 @@ def __init__(
9192
self.parallelism_groups = parallelism_groups
9293
self.per_test_coverage = per_test_coverage
9394
self.gtest_sharding = bool(gtest_sharding)
95+
self.update_tests = update_tests
96+
self.test_updaters = []
9497

9598
@property
9699
def maxIndividualTestTime(self):

lit/TestRunner.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,18 @@ def executeScriptInternal(
11921192
str(result.timeoutReached),
11931193
)
11941194

1195+
if litConfig.update_tests:
1196+
for test_updater in litConfig.test_updaters:
1197+
try:
1198+
update_output = test_updater(result, test)
1199+
except Exception as e:
1200+
out += f"Exception occurred in test updater: {e}"
1201+
continue
1202+
if update_output:
1203+
for line in update_output.splitlines():
1204+
out += f"# {line}\n"
1205+
break
1206+
11951207
return out, err, exitCode, timeoutInfo
11961208

11971209

lit/cl_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ def parse_args():
230230
action="store_true",
231231
help="Exit with status zero even if some tests fail",
232232
)
233+
execution_group.add_argument(
234+
"--update-tests",
235+
dest="update_tests",
236+
action="store_true",
237+
help="Try to update regression tests to reflect current behavior, if possible",
238+
)
233239
execution_test_time_group = execution_group.add_mutually_exclusive_group()
234240
execution_test_time_group.add_argument(
235241
"--skip-test-time-recording",

lit/llvm/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,17 @@ def __init__(self, lit_config, config):
6464
self.with_environment("_TAG_REDIR_ERR", "TXT")
6565
self.with_environment("_CEE_RUNOPTS", "FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)")
6666

67+
if lit_config.update_tests:
68+
self.use_lit_shell = True
69+
6770
# Choose between lit's internal shell pipeline runner and a real shell.
6871
# If LIT_USE_INTERNAL_SHELL is in the environment, we use that as an
6972
# override.
7073
lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")
7174
if lit_shell_env:
7275
self.use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
76+
if not self.use_lit_shell and lit_config.update_tests:
77+
print("note: --update-tests is not supported when using external shell")
7378

7479
if not self.use_lit_shell:
7580
features.add("shell")

lit/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def main(builtin_params={}):
4343
per_test_coverage=opts.per_test_coverage,
4444
gtest_sharding=opts.gtest_sharding,
4545
maxRetriesPerTest=opts.maxRetriesPerTest,
46+
update_tests=opts.update_tests,
4647
)
4748

4849
discovered_tests = lit.discovery.find_tests_for_inputs(

0 commit comments

Comments
 (0)