Skip to content

Commit ad220a2

Browse files
authored
[Utils] Add new --update-tests flag to llvm-lit (#108425)
This adds a flag to lit for detecting and updating failing tests when possible to do so automatically. The flag uses a plugin architecture where config files can add additional auto-updaters for the types of tests in the test suite. When a test fails with `--update-tests` enabled lit passes the test RUN invocation and output to each registered test updater until one of them signals that it updated the test (or all test updaters have been run). As such it is the responsibility of the test updater to only update tests where it is reasonably certain that it will actually fix the test, or come close to doing so. Initially adds support for UpdateVerifyTests and UpdateTestChecks. The flag is currently only implemented for lit's internal shell, so `--update-tests` implies `LIT_USE_INTERNAL_SHELL=1`. Builds on work in #97369 Fixes #81320
1 parent 3d55c19 commit ad220a2

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
@@ -38,6 +38,7 @@ def __init__(
3838
parallelism_groups={},
3939
per_test_coverage=False,
4040
gtest_sharding=True,
41+
update_tests=False,
4142
):
4243
# The name of the test runner.
4344
self.progname = progname
@@ -89,6 +90,8 @@ def __init__(
8990
self.parallelism_groups = parallelism_groups
9091
self.per_test_coverage = per_test_coverage
9192
self.gtest_sharding = bool(gtest_sharding)
93+
self.update_tests = update_tests
94+
self.test_updaters = []
9295

9396
@property
9497
def maxIndividualTestTime(self):

lit/TestRunner.py

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

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

11951207

lit/cl_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ def parse_args():
204204
action="store_true",
205205
help="Exit with status zero even if some tests fail",
206206
)
207+
execution_group.add_argument(
208+
"--update-tests",
209+
dest="update_tests",
210+
action="store_true",
211+
help="Try to update regression tests to reflect current behavior, if possible",
212+
)
207213
execution_test_time_group = execution_group.add_mutually_exclusive_group()
208214
execution_test_time_group.add_argument(
209215
"--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
@@ -42,6 +42,7 @@ def main(builtin_params={}):
4242
config_prefix=opts.configPrefix,
4343
per_test_coverage=opts.per_test_coverage,
4444
gtest_sharding=opts.gtest_sharding,
45+
update_tests=opts.update_tests,
4546
)
4647

4748
discovered_tests = lit.discovery.find_tests_for_inputs(

0 commit comments

Comments
 (0)