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: source=%p/Inputs/foo.cpp \ COMPILE: mode=debug \ COMPILE: opt=none \ COMPILE: link=no \ COMPILE: output=%t.o \ COMPILE: clean=yes
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.
Oh, the joys of multiprocessing and pickling...