[all-commits] [llvm/llvm-project] 09b6e4: [lit] Drop "Script:", make -v and -a imply -vv

Joel E. Denny via All-commits all-commits at lists.llvm.org
Tue Aug 29 09:01:46 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 09b6e457d91ce84088e6e21783913e5f1e5bd227
      https://github.com/llvm/llvm-project/commit/09b6e457d91ce84088e6e21783913e5f1e5bd227
  Author: Joel E. Denny <jdenny.ornl at gmail.com>
  Date:   2023-08-29 (Tue, 29 Aug 2023)

  Changed paths:
    M llvm/docs/CommandGuide/lit.rst
    M llvm/utils/lit/lit/LitConfig.py
    M llvm/utils/lit/lit/TestRunner.py
    M llvm/utils/lit/lit/cl_arguments.py
    M llvm/utils/lit/lit/main.py
    M llvm/utils/lit/tests/Inputs/shtest-if-else/test.txt
    M llvm/utils/lit/tests/shtest-format.py
    M llvm/utils/lit/tests/shtest-inject.py
    M llvm/utils/lit/tests/shtest-not.py
    M llvm/utils/lit/tests/shtest-output-printing.py
    M llvm/utils/lit/tests/shtest-run-at-line.py

  Log Message:
  -----------
  [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


  Commit: c981c533055e14302e7bff5d6898c9308065f665
      https://github.com/llvm/llvm-project/commit/c981c533055e14302e7bff5d6898c9308065f665
  Author: Joel E. Denny <jdenny.ornl at gmail.com>
  Date:   2023-08-29 (Tue, 29 Aug 2023)

  Changed paths:
    M libcxx/utils/libcxx/test/dsl.py
    M libcxx/utils/libcxx/test/format.py
    M llvm/utils/lit/lit/TestRunner.py
    M llvm/utils/lit/tests/Inputs/lit-opts/lit.cfg
    M llvm/utils/lit/tests/Inputs/shtest-define/examples/param-subst.txt
    M llvm/utils/lit/tests/Inputs/shtest-define/expansion-order.txt
    M llvm/utils/lit/tests/Inputs/shtest-define/line-number-substitutions.txt
    M llvm/utils/lit/tests/Inputs/shtest-define/name-chars.txt
    M llvm/utils/lit/tests/Inputs/shtest-define/recursiveExpansionLimit.txt
    M llvm/utils/lit/tests/Inputs/shtest-define/value-equals.txt
    M llvm/utils/lit/tests/Inputs/shtest-define/value-escaped.txt
    M llvm/utils/lit/tests/Inputs/shtest-define/ws-and-continuations.txt
    M llvm/utils/lit/tests/Inputs/shtest-if-else/test.txt
    M llvm/utils/lit/tests/Inputs/shtest-output-printing/basic.txt
    M llvm/utils/lit/tests/Inputs/shtest-output-printing/lit.cfg
    A llvm/utils/lit/tests/Inputs/shtest-output-printing/write-a-lot.py
    A llvm/utils/lit/tests/Inputs/shtest-shell/echo-at-redirect-stderr.txt
    A llvm/utils/lit/tests/Inputs/shtest-shell/echo-at-redirect-stdin.txt
    A llvm/utils/lit/tests/Inputs/shtest-shell/echo-redirect-stderr.txt
    A llvm/utils/lit/tests/Inputs/shtest-shell/echo-redirect-stdin.txt
    M llvm/utils/lit/tests/allow-retries.py
    M llvm/utils/lit/tests/lit-opts.py
    M llvm/utils/lit/tests/shtest-define.py
    M llvm/utils/lit/tests/shtest-env.py
    M llvm/utils/lit/tests/shtest-format.py
    M llvm/utils/lit/tests/shtest-if-else.py
    M llvm/utils/lit/tests/shtest-inject.py
    M llvm/utils/lit/tests/shtest-not.py
    M llvm/utils/lit/tests/shtest-output-printing.py
    M llvm/utils/lit/tests/shtest-pushd-popd.py
    M llvm/utils/lit/tests/shtest-recursive-substitution.py
    M llvm/utils/lit/tests/shtest-run-at-line.py
    M llvm/utils/lit/tests/shtest-shell.py

  Log Message:
  -----------
  [lit] Improve test output from lit's internal shell

This patch and D154984 were discussed in
<https://discourse.llvm.org/t/rfc-improving-lits-debug-output/72839>.

Motivation
----------

D154984 removes the "Script:" section that lit prints along with a
test's output, and it makes -v and -a imply -vv.  For example, after
D154984, the "Script:" section below is never shown, but -v is enough
to produce the execution trace following it:

```
 Script:
 --
 : 'RUN: at line 1'; echo hello | FileCheck bogus.txt && echo success
 --
 Exit Code: 2

 Command Output (stdout):
 --
 $ ":" "RUN: at line 1"
 $ "echo" "hello"
 # command output:
 hello

 $ "FileCheck" "bogus.txt"
 # command stderr:
 Could not open check file 'bogus.txt': No such file or directory

 error: command failed with exit status: 2

 --
```

In the D154984 review, some reviewers point out that they have been
using the "Script:" section for copying and pasting a test's shell
commands to a terminal window.  The shell commands as printed in the
execution trace can be harder to copy and paste for the following
reasons:

- They drop redirections and break apart RUN lines at `&&`, `|`, etc.
- They add `$` at the start of every command, which makes it hard to
  copy and paste multiple commands in bulk.
- Command stdout, stderr, etc. are interleaved with the commands and
  are not clearly delineated.
- They don't always use proper shell quoting.  Instead, they blindly
  enclose all command-line arguments in double quotes.

Changes
-------

D154984 plus this patch converts the above example into:

```
 Exit Code: 2

 Command Output (stdout):
 --
 # RUN: at line 1
 echo hello | FileCheck bogus-file.txt && echo success
 # executed command: echo hello
 # .---command stdout------------
 # | hello
 # `-----------------------------
 # executed command: FileCheck bogus-file.txt
 # .---command stderr------------
 # | Could not open check file 'bogus-file.txt': No such file or directory
 # `-----------------------------
 # error: command failed with exit status: 2

 --
```

Thus, this patch addresses the above issues as follows:

- The entire execution trace can be copied and pasted in bulk to a
  terminal for correct execution of the RUN lines, which are printed
  intact as they appeared in the original RUN lines except lit
  substitutions are expanded.  Everything else in the execution trace
  appears in shell comments so it has no effect in a terminal.
- Each of the RUN line's commands is repeated (in shell comments) as
  it executes to show (1) that the command actually executed (e.g.,
  `echo success` above didn't) and (2) what stdout, stderr, non-zero
  exit status, and output files are associated with the command, if
  any.  Shell quoting in the command is now correct and minimal but is
  not necessarily the original shell quoting from the RUN line.
- The start and end of the contents of stdout, stderr, or an output
  file is now delineated clearly in the trace.

To help produce some of the above output, this patch extends lit's
internal shell with a built-in `@echo` command.  It's like `echo`
except lit suppresses the normal execution trace for `@echo` and just
prints its stdout directly.  For now, `@echo` isn't documented for use
in lit tests.

Without this patch, libcxx's custom lit test format tries to parse the
stdout from `lit.TestRunner.executeScriptInternal` (which runs lit's
internal shell) to extract the stdout and stderr produced by shell
commands, and that parse no longer works after the above changes.
This patch makes a small adjustment to
`lit.TestRunner.executeScriptInternal` so libcxx can just request
stdout and stderr without an execution trace.

(As a minor drive-by fix that came up in testing: lit's internal `not`
command now always produces a numeric exit status and never `True`.)

Caveat
------

This patch only makes the above changes for lit's internal shell.  In
most cases, we do not know how to force external shells (e.g., bash,
sh, window's `cmd`) to produce execution traces in the manner we want.

To configure a test suite to use lit's internal shell (which is
usually better for test portability than external shells anyway), add
this to the test suite's `lit.cfg` or other configuration file:

```
config.test_format = lit.formats.ShTest(execute_external=False)
```

Reviewed By: MaskRay, awarzynski

Differential Revision: https://reviews.llvm.org/D156954


Compare: https://github.com/llvm/llvm-project/compare/77e965ef454a...c981c533055e


More information about the All-commits mailing list