Skip to content

Commit 09b6e45

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 77e965e commit 09b6e45

File tree

11 files changed

+138
-139
lines changed

11 files changed

+138
-139
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: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,10 +1102,7 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
11021102
commands[i] = match.expand(
11031103
"echo '\\1' > nul && " if command else "echo '\\1' > nul"
11041104
)
1105-
if litConfig.echo_all_commands:
1106-
f.write("@echo on\n")
1107-
else:
1108-
f.write("@echo off\n")
1105+
f.write("@echo on\n")
11091106
f.write("\n@if %ERRORLEVEL% NEQ 0 EXIT\n".join(commands))
11101107
else:
11111108
for i, ln in enumerate(commands):
@@ -1115,8 +1112,7 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
11151112
commands[i] = match.expand(": '\\1'; \\2" if command else ": '\\1'")
11161113
if test.config.pipefail:
11171114
f.write(b"set -o pipefail;" if mode == "wb" else "set -o pipefail;")
1118-
if litConfig.echo_all_commands:
1119-
f.write(b"set -x;" if mode == "wb" else "set -x;")
1115+
f.write(b"set -x;" if mode == "wb" else "set -x;")
11201116
if sys.version_info > (3, 0) and mode == "wb":
11211117
f.write(bytes("{ " + "; } &&\n{ ".join(commands) + "; }", "utf-8"))
11221118
else:
@@ -2086,7 +2082,7 @@ def runOnce(execdir):
20862082
status = Test.FLAKYPASS
20872083

20882084
# Form the output log.
2089-
output = """Script:\n--\n%s\n--\nExit Code: %d\n""" % ("\n".join(script), exitCode)
2085+
output = f"Exit Code: {exitCode}\n"
20902086

20912087
if timeoutInfo is not None:
20922088
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:

llvm/utils/lit/tests/shtest-format.py

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,19 @@
3737

3838
# CHECK: PASS: shtest-format :: external_shell/pass.txt
3939

40-
# CHECK: FAIL: shtest-format :: fail.txt
41-
# CHECK-NEXT: *** TEST 'shtest-format :: fail.txt' FAILED ***
42-
# CHECK-NEXT: Script:
43-
# CHECK-NEXT: --
44-
# CHECK-NEXT: printf "line 1
45-
# CHECK-NEXT: false
46-
# CHECK-NEXT: --
47-
# CHECK-NEXT: Exit Code: 1
48-
#
49-
# CHECK: Command Output (stdout):
50-
# CHECK-NEXT: --
51-
# CHECK-NEXT: $ ":" "RUN: at line 1"
52-
# CHECK-NEXT: $ "printf"
53-
# CHECK-NEXT: # command output:
54-
# CHECK-NEXT: line 1: failed test output on stdout
55-
# CHECK-NEXT: line 2: failed test output on stdout
40+
# CHECK: FAIL: shtest-format :: fail.txt
41+
# CHECK-NEXT: *** TEST 'shtest-format :: fail.txt' FAILED ***
42+
# CHECK-NEXT: Exit Code: 1
43+
# CHECK-EMPTY:
44+
# CHECK-NEXT: Command Output (stdout):
45+
# CHECK-NEXT: --
46+
# CHECK-NEXT: $ ":" "RUN: at line 1"
47+
# CHECK-NEXT: $ "printf"
48+
# CHECK-NEXT: # command output:
49+
# CHECK-NEXT: line 1: failed test output on stdout
50+
# CHECK-NEXT: line 2: failed test output on stdout
51+
# CHECK-NEXT: $ ":" "RUN: at line 2"
52+
# CHECK-NEXT: $ "false"
5653

5754
# CHECK: UNRESOLVED: shtest-format :: no-test-line.txt
5855
# CHECK: PASS: shtest-format :: pass.txt
@@ -69,12 +66,15 @@
6966
# CHECK: XFAIL: shtest-format :: xfail-feature.txt
7067
# CHECK: XFAIL: shtest-format :: xfail-target.txt
7168
# CHECK: XFAIL: shtest-format :: xfail.txt
72-
# CHECK: XPASS: shtest-format :: xpass.txt
73-
# CHECK-NEXT: *** TEST 'shtest-format :: xpass.txt' FAILED ***
74-
# CHECK-NEXT: Script
75-
# CHECK-NEXT: --
76-
# CHECK-NEXT: true
77-
# CHECK-NEXT: --
69+
70+
# CHECK: XPASS: shtest-format :: xpass.txt
71+
# CHECK-NEXT: *** TEST 'shtest-format :: xpass.txt' FAILED ***
72+
# CHECK-NEXT: Exit Code: 0
73+
# CHECK-EMPTY:
74+
# CHECK-NEXT: Command Output (stdout):
75+
# CHECK-NEXT: --
76+
# CHECK-NEXT: $ ":" "RUN: at line 1"
77+
# CHECK-NEXT: $ "true"
7878

7979
# CHECK: Failed Tests (4)
8080
# CHECK: shtest-format :: external_shell/fail.txt
@@ -109,13 +109,16 @@
109109
# XUNIT: </failure>
110110
# XUNIT-NEXT: </testcase>
111111

112-
# XUNIT: <testcase classname="shtest-format.external_shell" name="fail_with_control_chars.txt" time="{{[0-9]+\.[0-9]+}}">
113-
# XUNIT-NEXT: <failure><![CDATA[Script:
114-
# XUNIT: Command Output (stdout):
115-
# XUNIT-NEXT: --
116-
# XUNIT-NEXT: a line with [2;30;41mcontrol characters[0m.
117-
# XUNIT: </failure>
118-
# XUNIT-NEXT: </testcase>
112+
# XUNIT: <testcase classname="shtest-format.external_shell" name="fail_with_control_chars.txt" time="{{[0-9]+\.[0-9]+}}">
113+
# XUNIT-NEXT: <failure><![CDATA[Exit Code: 1
114+
# XUNIT-EMPTY:
115+
# XUNIT-NEXT: Command Output (stdout):
116+
# XUNIT-NEXT: --
117+
# XUNIT-NEXT: a line with [2;30;41mcontrol characters[0m.
118+
# XUNIT-EMPTY:
119+
# XUNIT-NEXT: --
120+
# XUNIT: ]]></failure>
121+
# XUNIT-NEXT: </testcase>
119122

120123
# XUNIT: <testcase classname="shtest-format.external_shell" name="pass.txt" time="{{[0-9]+\.[0-9]+}}"/>
121124

0 commit comments

Comments
 (0)