[Lldb-commits] [PATCH] D54731: [lit] Enable the use of custom user-defined lit commands

Zachary Turner via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 19 15:36:01 PST 2018


zturner created this revision.
zturner added reviewers: labath, stella.stamenova, davide, rnk, aprantl, friss.
Herald added a subscriber: delcypher.

Currently lit supports running shell commands through the use of the `RUN: ` prefix.  This patch allows individual test suites to install their own run handlers that can do things other than run shell commands.  `RUN` commands still work as they always do, just that now if a different kind of command appears it will be appropriately sequenced along with the run command.

The commands the user installs can execute arbitrary Python code.  As such, they can in theory write directly to stdout or stderr, but a well-behaved command should return its stdout and stderr from the function so that this can be reported to the user in a manner consistent with output from `RUN` lines.

The motivating use case for this is being able to provide a richer and more powerful syntax by which to compile test programs in LLDB tests.  Currently everything is based off of substitutions and explicitly shell commands, but this is problematic when you get into interesting compilation scenarios.

For example, one could imagine wanting to write a test that tested the behavior of the debugger with optimized code.  Each driver has different sets of flags that control the optimization behavior.

Another example is in cross-compilation scenarios.  Certain types of PDB tests don't need to run a process, so the tests can be run anywhere, but they need to be linked with special flags to avoid pulling in system libraries.

We can try to make substitutions for all of these cases, but it will quickly become unwieldy and you will end up with a command line like: `RUN: %cxx %debug %opt %norun`, and this still isn't as flexible as you'd like.

With this patch, we could (in theory) do the compilation directly from Python.  Instead of a shell command like above, we could write something like:

  COMPILE: mode=debug \
                   opt=none \
                   link=no
                   output=%t.o
                   clean=yes
                   source=%p/Inputs/foo.cpp

and let the function figure out how best to do this for each platform.  This is similar in spirit to how lldb's `dotest.py` already works with its platform specific builders, but the mechanism here is general enough that it can be used for anything a test suite wants, not just compiling.


https://reviews.llvm.org/D54731

Files:
  llvm/utils/lit/lit/LitConfig.py
  llvm/utils/lit/lit/ShCommands.py
  llvm/utils/lit/lit/TestRunner.py
  llvm/utils/lit/tests/Inputs/shtest-keyword-command/keyword-command.txt
  llvm/utils/lit/tests/Inputs/shtest-keyword-command/keyword_helper.py
  llvm/utils/lit/tests/Inputs/shtest-keyword-command/lit.cfg
  llvm/utils/lit/tests/shtest-keyword-command.py

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54731.174691.patch
Type: text/x-patch
Size: 14673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20181119/f4af8895/attachment.bin>


More information about the lldb-commits mailing list