Skip to content

Commit 1495d51

Browse files
committed
[lit] Drop "Script:", make -v and -a imply -vv
This patch and D156954 were discussed in <https://discourse.llvm.org/t/rfc-improving-lits-debug-output/72839>. **Motivation**: -a shows output from all tests, and -v shows output from just failed tests. Without this patch, that output from each test includes a section called "Script:", which includes all shell commands that lit has computed from RUN directives and will attempt to run for that test. The effect of -vv (which also implies -v if neither -a or -v is specified) is to extend that output with shell commands as they are executing so you can easily see which one failed. For example, when using lit's internal shell and -vv: ``` Script: -- : 'RUN: at line 1'; echo hello world : 'RUN: at line 2'; 3c40 hello world : 'RUN: at line 3'; echo hello world -- Exit Code: 127 Command Output (stdout): -- $ ":" "RUN: at line 1" $ "echo" "hello" "world" hello world $ ":" "RUN: at line 2" $ "3c40" "hello" "world" '3c40': command not found error: command failed with exit status: 127 -- ``` Notice that all shell commands that actually execute appear in the output twice, once for "Script:" and once for -vv. Especially for tests with many RUN directives, the result is noisy. When searching through the output for a particular shell command, it is easy to get lost and mistake shell commands under "Script:" for shell commands that actually executed. **Change**: With this patch, a test's output changes in two ways. First, the "Script:" section is never shown. Second, omitting -vv no longer disables printing of shell commands as they execute. That is, -a and -v imply -vv, and so -vv is deprecated as it is just an alias for -v. **Secondary motivation**: We are also working to introduce a PYTHON directive, which can appear between RUN directives. How should PYTHON directives be represented in the "Script:" section, which has previously been just a shell script? We could probably think of something, but adding info about PYTHON directive execution in the -vv trace seems more straight-forward and more useful. (This patch also removes a confusing point in the -vv documentation: at least when using bash as an external shell, -vv echoes commands to the shell's stderr not stdout.) Reviewed By: awarzynski, Endill, ldionne, MaskRay Differential Revision: https://reviews.llvm.org/D154984
1 parent 84c899b commit 1495d51

File tree

11 files changed

+147
-150
lines changed

11 files changed

+147
-150
lines changed

llvm/docs/CommandGuide/lit.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,20 @@ OUTPUT OPTIONS
9494
Show more information on test failures, for example the entire test output
9595
instead of just the test result.
9696

97+
Each command is printed before it is executed. This can be valuable for
98+
debugging test failures, as the last printed command is the one that failed.
99+
Moreover, :program:`lit` inserts a no-op command (``:`` in the case of bash)
100+
with argument ``'RUN: at line N'`` before each command pipeline, and those
101+
no-op commands are also printed to help you locate the source line of the
102+
failed command.
103+
97104
.. option:: -vv, --echo-all-commands
98105

99-
On test failure, echo all commands to stdout as they are being executed.
100-
This can be valuable for debugging test failures, as the last echoed command
101-
will be the one which has failed.
102-
:program:`lit` normally inserts a no-op command (``:`` in the case of bash)
103-
with argument ``'RUN: at line N'`` before each command pipeline, and this
104-
option also causes those no-op commands to be echoed to stdout to help you
105-
locate the source line of the failed command.
106-
This option implies ``--verbose``.
106+
Deprecated alias for -v.
107107

108108
.. option:: -a, --show-all
109109

110-
Show more information about all tests, for example the entire test
111-
commandline and output.
110+
Enable -v, but for all tests not just failed tests.
112111

113112
.. option:: --no-progress-bar
114113

llvm/utils/lit/lit/LitConfig.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def __init__(
3636
config_prefix=None,
3737
maxIndividualTestTime=0,
3838
parallelism_groups={},
39-
echo_all_commands=False,
4039
per_test_coverage=False,
4140
):
4241
# The name of the test runner.
@@ -87,7 +86,6 @@ def __init__(
8786

8887
self.maxIndividualTestTime = maxIndividualTestTime
8988
self.parallelism_groups = parallelism_groups
90-
self.echo_all_commands = echo_all_commands
9189
self.per_test_coverage = per_test_coverage
9290

9391
@property

llvm/utils/lit/lit/TestRunner.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,10 +1095,7 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
10951095
commands[i] = match.expand(
10961096
"echo '\\1' > nul && " if command else "echo '\\1' > nul"
10971097
)
1098-
if litConfig.echo_all_commands:
1099-
f.write("@echo on\n")
1100-
else:
1101-
f.write("@echo off\n")
1098+
f.write("@echo on\n")
11021099
f.write("\n@if %ERRORLEVEL% NEQ 0 EXIT\n".join(commands))
11031100
else:
11041101
for i, ln in enumerate(commands):
@@ -1108,8 +1105,7 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
11081105
commands[i] = match.expand(": '\\1'; \\2" if command else ": '\\1'")
11091106
if test.config.pipefail:
11101107
f.write(b"set -o pipefail;" if mode == "wb" else "set -o pipefail;")
1111-
if litConfig.echo_all_commands:
1112-
f.write(b"set -x;" if mode == "wb" else "set -x;")
1108+
f.write(b"set -x;" if mode == "wb" else "set -x;")
11131109
if sys.version_info > (3, 0) and mode == "wb":
11141110
f.write(bytes("{ " + "; } &&\n{ ".join(commands) + "; }", "utf-8"))
11151111
else:
@@ -2035,14 +2031,19 @@ def parseIntegratedTestScript(test, additional_parsers=[], require_script=True):
20352031

20362032
def _runShTest(test, litConfig, useExternalSh, script, tmpBase):
20372033
def runOnce(execdir):
2034+
# script is modified below (for litConfig.per_test_coverage, and for
2035+
# %dbg expansions). runOnce can be called multiple times, but applying
2036+
# the modifications multiple times can corrupt script, so always modify
2037+
# a copy.
2038+
scriptCopy = script[:]
20382039
# Set unique LLVM_PROFILE_FILE for each run command
20392040
if litConfig.per_test_coverage:
20402041
# Extract the test case name from the test object, and remove the
20412042
# file extension.
20422043
test_case_name = test.path_in_suite[-1]
20432044
test_case_name = test_case_name.rsplit(".", 1)[0]
20442045
coverage_index = 0 # Counter for coverage file index
2045-
for i, ln in enumerate(script):
2046+
for i, ln in enumerate(scriptCopy):
20462047
match = re.fullmatch(kPdbgRegex, ln)
20472048
if match:
20482049
dbg = match.group(1)
@@ -2054,12 +2055,12 @@ def runOnce(execdir):
20542055
command = f"export LLVM_PROFILE_FILE={profile}; {command}"
20552056
if match:
20562057
command = buildPdbgCommand(dbg, command)
2057-
script[i] = command
2058+
scriptCopy[i] = command
20582059

20592060
if useExternalSh:
2060-
res = executeScript(test, litConfig, tmpBase, script, execdir)
2061+
res = executeScript(test, litConfig, tmpBase, scriptCopy, execdir)
20612062
else:
2062-
res = executeScriptInternal(test, litConfig, tmpBase, script, execdir)
2063+
res = executeScriptInternal(test, litConfig, tmpBase, scriptCopy, execdir)
20632064
if isinstance(res, lit.Test.Result):
20642065
return res
20652066

@@ -2079,14 +2080,7 @@ def runOnce(execdir):
20792080
# Re-run failed tests up to test.allowed_retries times.
20802081
execdir = os.path.dirname(test.getExecPath())
20812082
attempts = test.allowed_retries + 1
2082-
scriptInit = script
20832083
for i in range(attempts):
2084-
# runOnce modifies script, but applying the modifications again to the
2085-
# result can corrupt script, so we restore the original upon a retry.
2086-
# A cleaner solution would be for runOnce to encapsulate operating on a
2087-
# copy of script, but we actually want it to modify the original script
2088-
# so we can print the modified version under "Script:" below.
2089-
script = scriptInit[:]
20902084
res = runOnce(execdir)
20912085
if isinstance(res, lit.Test.Result):
20922086
return res
@@ -2101,7 +2095,7 @@ def runOnce(execdir):
21012095
status = Test.FLAKYPASS
21022096

21032097
# Form the output log.
2104-
output = """Script:\n--\n%s\n--\nExit Code: %d\n""" % ("\n".join(script), exitCode)
2098+
output = f"Exit Code: {exitCode}\n"
21052099

21062100
if timeoutInfo is not None:
21072101
output += """Timeout: %s\n""" % (timeoutInfo,)

llvm/utils/lit/lit/cl_arguments.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,23 @@ def parse_args():
7272
"-v",
7373
"--verbose",
7474
dest="showOutput",
75-
help="Show test output for failures",
75+
help="For failed tests, show all output. For example, each command is"
76+
" printed before it is executed, so the last printed command is the one"
77+
" that failed.",
7678
action="store_true",
7779
)
7880
format_group.add_argument(
7981
"-vv",
8082
"--echo-all-commands",
81-
dest="echoAllCommands",
83+
dest="showOutput",
84+
help="Deprecated alias for -v.",
8285
action="store_true",
83-
help="Echo all commands as they are executed to stdout. In case of "
84-
"failure, last command shown will be the failing one.",
8586
)
8687
format_group.add_argument(
8788
"-a",
8889
"--show-all",
8990
dest="showAllOutput",
90-
help="Display all commandlines and output",
91+
help="Enable -v, but for all tests not just failed tests.",
9192
action="store_true",
9293
)
9394
format_group.add_argument(
@@ -299,9 +300,6 @@ def parse_args():
299300
opts = parser.parse_args(args)
300301

301302
# Validate command line options
302-
if opts.echoAllCommands:
303-
opts.showOutput = True
304-
305303
if opts.incremental:
306304
print(
307305
"WARNING: --incremental is deprecated. Failing tests now always run first."

llvm/utils/lit/lit/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def main(builtin_params={}):
4040
order=opts.order,
4141
params=params,
4242
config_prefix=opts.configPrefix,
43-
echo_all_commands=opts.echoAllCommands,
4443
per_test_coverage=opts.per_test_coverage,
4544
)
4645

Lines changed: 84 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,148 @@
1-
# CHECK: -- Testing:{{.*}}
2-
# CHECK-NEXT: PASS: shtest-if-else :: test.txt (1 of 1)
3-
# CHECK-NEXT: Script:
4-
# CHECK-NEXT: --
1+
# CHECK: -- Testing:{{.*}}
2+
# CHECK-NEXT: PASS: shtest-if-else :: test.txt (1 of 1)
3+
# CHECK-NEXT: Exit Code: 0
4+
# CHECK-EMPTY:
5+
# CHECK-NEXT: Command Output (stdout):
6+
# CHECK-NEXT: --
57

68
# RUN: %if feature %{ echo "test-1" %}
7-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo "test-1"
9+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-1]]"
10+
# CHECK: # command output:
11+
# CHECK-NEXT: test-1
12+
# CHECK-EMPTY:
813

914
# If %else is not present it is treated like %else %{%}. Empty commands
1015
# are ignored.
1116
#
1217
# RUN: %if nofeature %{ echo "fail" %}
13-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'
14-
# CHECK-NOT: fail
18+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-1]]"
19+
# CHECK-NOT: fail
1520

1621
# RUN: %if nofeature %{ echo "fail" %} %else %{ echo "test-2" %}
17-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo "test-2"
22+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-1]]"
23+
# CHECK: # command output:
24+
# CHECK-NEXT: test-2
25+
# CHECK-EMPTY:
1826

1927
# Spaces inside curly braces are not ignored
2028
#
2129
# RUN: echo test-%if feature %{ 3 %} %else %{ fail %}-test
2230
# RUN: echo test-%if feature %{ 4 4 %} %else %{ fail %}-test
2331
# RUN: echo test-%if nofeature %{ fail %} %else %{ 5 5 %}-test
24-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo test- 3 -test
25-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo test- 4 4 -test
26-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo test- 5 5 -test
32+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-3]]"
33+
# CHECK: # command output:
34+
# CHECK-NEXT: test- 3 -test
35+
# CHECK-EMPTY:
36+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-6]]"
37+
# CHECK: # command output:
38+
# CHECK-NEXT: test- 4 4 -test
39+
# CHECK-EMPTY:
40+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-9]]"
41+
# CHECK: # command output:
42+
# CHECK-NEXT: test- 5 5 -test
43+
# CHECK-EMPTY:
2744

2845
# Escape line breaks for multi-line expressions
2946
#
3047
# RUN: %if feature \
3148
# RUN: %{ echo \
3249
# RUN: "test-5" \
3350
# RUN: %}
34-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-4]]'; echo "test-5"
51+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-4]]"
52+
# CHECK: # command output:
53+
# CHECK-NEXT: test-5
54+
# CHECK-EMPTY:
3555

3656
# RUN: %if nofeature \
3757
# RUN: %{ echo "fail" %} \
3858
# RUN: %else \
3959
# RUN: %{ echo "test-6" %}
40-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-4]]'; echo "test-6"
60+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-4]]"
61+
# CHECK: # command output:
62+
# CHECK-NEXT: test-6
63+
# CHECK-EMPTY:
4164

4265
# RUN: echo "test%if feature %{%} %else %{%}-7"
43-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo "test-7"
66+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-1]]"
67+
# CHECK: # command output:
68+
# CHECK-NEXT: test-7
69+
# CHECK-EMPTY:
4470

4571
# Escape %if. Without %if..%else context '%{' and '%}' are treated
4672
# literally.
4773
#
4874
# RUN: echo %%if feature %{ echo "test-8" %}
49-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo %if feature %{ echo "test-8" %}
75+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-1]]"
76+
# CHECK: # command output:
77+
# CHECK-NEXT: %if feature %{ echo test-8 %}
78+
# CHECK-EMPTY:
5079

5180
# Nested expressions are supported:
5281
#
5382
# RUN: echo %if feature %{ %if feature %{ %if nofeature %{"fail"%} %else %{"test-9"%} %} %}
54-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo "test-9"
83+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-1]]"
84+
# CHECK: # command output:
85+
# CHECK-NEXT: test-9
86+
# CHECK-EMPTY:
5587

5688
# Binary expression evaluation and regex match can be used as
5789
# conditions.
5890
#
5991
# RUN: echo %if feature && !nofeature %{ "test-10" %}
6092
# RUN: echo %if feature && nofeature %{ "fail" %} %else %{ "test-11" %}
6193
# RUN: echo %if {{fea.+}} %{ "test-12" %} %else %{ "fail" %}
62-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo "test-10"
63-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo "test-11"
64-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo "test-12"
94+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-3]]"
95+
# CHECK: # command output:
96+
# CHECK-NEXT: test-10
97+
# CHECK-EMPTY:
98+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-6]]"
99+
# CHECK: # command output:
100+
# CHECK-NEXT: test-11
101+
# CHECK-EMPTY:
102+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-9]]"
103+
# CHECK: # command output:
104+
# CHECK-NEXT: test-12
105+
# CHECK-EMPTY:
65106

66107
# Spaces between %if and %else are ignored. If there is no %else -
67108
# space after %if %{...%} is not ignored.
68109
#
69110
# RUN: echo XX %if feature %{YY%} ZZ
70111
# RUN: echo AA %if feature %{BB%} %else %{CC%} DD
71112
# RUN: echo AA %if nofeature %{BB%} %else %{CC%} DD
72-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo XX YY ZZ
73-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo AA BB DD
74-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo AA CC DD
113+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-3]]"
114+
# CHECK: # command output:
115+
# CHECK-NEXT: XX YY ZZ
116+
# CHECK-EMPTY:
117+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-6]]"
118+
# CHECK: # command output:
119+
# CHECK-NEXT: AA BB DD
120+
# CHECK-EMPTY:
121+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-9]]"
122+
# CHECK: # command output:
123+
# CHECK-NEXT: AA CC DD
124+
# CHECK-EMPTY:
75125

76126
# '{' and '}' can be used without escaping
77127
#
78128
# RUN: %if feature %{echo {}%}
79-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo {}
129+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-1]]"
130+
# CHECK: # command output:
131+
# CHECK-NEXT: {}
132+
# CHECK-EMPTY:
80133

81134
# Spaces are not required
82135
#
83136
# RUN: echo %if feature%{"ok"%}%else%{"fail"%}
84-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo "ok"
137+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-1]]"
138+
# CHECK: # command output:
139+
# CHECK-NEXT: ok
140+
# CHECK-EMPTY:
85141

86142
# Substitutions with braces are handled correctly
87143
#
88144
# RUN: echo %{sub} %if feature%{test-%{sub}%}%else%{"fail"%}
89-
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo ok test-ok
90-
91-
# CHECK-NEXT: --
92-
# CHECK-NEXT: Exit Code: 0
145+
# CHECK-NEXT: {{^.*"RUN}}: at line [[#@LINE-1]]"
146+
# CHECK: # command output:
147+
# CHECK-NEXT: ok test-ok
148+
# CHECK-EMPTY:

0 commit comments

Comments
 (0)