diff --git a/llvm/docs/CommandGuide/lit.rst b/llvm/docs/CommandGuide/lit.rst --- a/llvm/docs/CommandGuide/lit.rst +++ b/llvm/docs/CommandGuide/lit.rst @@ -56,7 +56,9 @@ .. option:: -j N, --workers=N Run ``N`` tests in parallel. By default, this is automatically chosen to - match the number of detected available CPUs. + match the number of detected available CPUs. The environment variable + ``LIT_WORKERS`` can be also used in place of this option, which is especially + useful in environments where the call to ``lit`` is issued indirectly. .. option:: --config-prefix=NAME diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py --- a/llvm/utils/lit/lit/cl_arguments.py +++ b/llvm/utils/lit/lit/cl_arguments.py @@ -30,7 +30,7 @@ metavar="N", help="Number of workers used for testing", type=_positive_int, - default=lit.util.usable_core_count()) + default=os.environ.get("LIT_WORKERS", lit.util.usable_core_count())) parser.add_argument("--config-prefix", dest="configPrefix", metavar="NAME", diff --git a/llvm/utils/lit/tests/Inputs/lit-workers/lit.cfg b/llvm/utils/lit/tests/Inputs/lit-workers/lit.cfg new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/lit-workers/lit.cfg @@ -0,0 +1,6 @@ +import lit.formats +config.name = 'lit-workers' +config.suffixes = ['.txt'] +config.test_format = lit.formats.ShTest() +config.test_source_root = None +config.test_exec_root = None diff --git a/llvm/utils/lit/tests/Inputs/lit-workers/test1.txt b/llvm/utils/lit/tests/Inputs/lit-workers/test1.txt new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/lit-workers/test1.txt @@ -0,0 +1 @@ +# RUN: true diff --git a/llvm/utils/lit/tests/Inputs/lit-workers/test2.txt b/llvm/utils/lit/tests/Inputs/lit-workers/test2.txt new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/lit-workers/test2.txt @@ -0,0 +1 @@ +# RUN: true diff --git a/llvm/utils/lit/tests/Inputs/lit-workers/test3.txt b/llvm/utils/lit/tests/Inputs/lit-workers/test3.txt new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/lit-workers/test3.txt @@ -0,0 +1 @@ +# RUN: true diff --git a/llvm/utils/lit/tests/Inputs/lit-workers/test4.txt b/llvm/utils/lit/tests/Inputs/lit-workers/test4.txt new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/lit-workers/test4.txt @@ -0,0 +1 @@ +# RUN: true diff --git a/llvm/utils/lit/tests/lit-workers.py b/llvm/utils/lit/tests/lit-workers.py new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/lit-workers.py @@ -0,0 +1,12 @@ +# Check that the number of workers can be specified via the `-j` argument. +# RUN: %{lit} -s %{inputs}/lit-workers -j 4 | FileCheck %s + +# Check that the number of workers can be specified via the `LIT_WORKERS` +# environment variable. +# RUN: env LIT_WORKERS=4 %{lit} -s %{inputs}/lit-workers | FileCheck %s + +# Check that the number of workers specified via the `LIT_WORKERS` environment +# variable can be overwritten by the `-j` argument. +# RUN: env LIT_WORKERS=2 %{lit} -s %{inputs}/lit-workers -j 4 | FileCheck %s + +# CHECK: 4 workers