diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -640,7 +640,7 @@ procs = [] proc_not_counts = [] - default_stdin = subprocess.PIPE + default_stdin = None stderrTempFiles = [] opened_files = [] named_temp_files = [] diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py --- a/llvm/utils/lit/lit/util.py +++ b/llvm/utils/lit/lit/util.py @@ -321,7 +321,7 @@ * working directory ``cwd`` (str), use None to use the current working directory * environment ``env`` (dict), use None for none - * Input to the command ``input`` (str), use string to pass + * Input to the command ``input`` (str), use None to pass no input. * Max execution time ``timeout`` (int) seconds. Use 0 for no timeout. * ``redirect_stderr`` (bool), use True if redirect stderr to stdout @@ -339,7 +339,7 @@ input = to_bytes(input) err_out = subprocess.STDOUT if redirect_stderr else subprocess.PIPE p = subprocess.Popen(command, cwd=cwd, - stdin=subprocess.PIPE, + stdin=subprocess.PIPE if input else None, stdout=subprocess.PIPE, stderr=err_out, env=env, close_fds=kUseCloseFDs) diff --git a/llvm/utils/lit/tests/Inputs/shtest-stdin/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-stdin/lit.cfg new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-stdin/lit.cfg @@ -0,0 +1,26 @@ +# -*- Python -*- +import os +import sys + +import lit.formats + +config.name = 'shtest-stdin' + +externalShell = lit_config.params.get('external', '1') != '0' +config.test_format = lit.formats.ShTest(execute_external=externalShell) +config.suffixes = ['.py'] + +config.test_source_root = os.path.dirname(__file__) +config.test_exec_root = config.test_source_root +config.target_triple = '(unused)' +src_root = os.path.join(config.test_source_root, '..') + +pythonpath_list = [src_root] +# Ensure the user's PYTHONPATH is included. +if 'PYTHONPATH' in os.environ: + pythonpath_list.append(os.environ['PYTHONPATH']) +if 'PYTHONPATH' in config.environment: + pythonpath_list.append(config.environment['PYTHONPATH']) +config.environment['PYTHONPATH'] = os.pathsep.join(pythonpath_list) + +config.substitutions.append(('%{python}', '"%s"' % (sys.executable))) diff --git a/llvm/utils/lit/tests/Inputs/shtest-stdin/print-stdin.py b/llvm/utils/lit/tests/Inputs/shtest-stdin/print-stdin.py new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-stdin/print-stdin.py @@ -0,0 +1,5 @@ +# Checks that lit provides no input to stdin. +# RUN: %{python} %s +import sys + +print(sys.stdin.read()) \ No newline at end of file diff --git a/llvm/utils/lit/tests/shtest-stdin.py b/llvm/utils/lit/tests/shtest-stdin.py new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/shtest-stdin.py @@ -0,0 +1,28 @@ +# REQUIRES: lit-max-individual-test-time + +############################################################################### +# Check tests do not receive spurious stdin input. +############################################################################### +# RUN: not %{lit} %{inputs}/shtest-stdin/print-stdin.py \ +# RUN: --param external=0 --timeout 1 \ +# RUN: | FileCheck --check-prefix=CHECK-STDIN %s +# +# RUN: not %{lit} %{inputs}/shtest-stdin/print-stdin.py \ +# RUN: --param external=1 --timeout 1 \ +# RUN: | FileCheck --check-prefix=CHECK-STDIN %s +# +# CHECK-STDIN: TIMEOUT: shtest-stdin :: print-stdin.py + +############################################################################### +# Check tests do receive piped stdin input. +############################################################################### +# RUN: echo foobar | %{lit} %{inputs}/shtest-stdin/print-stdin.py \ +# RUN: --param external=0 -a \ +# RUN: | FileCheck --check-prefix=CHECK-PIPE %s +# +# RUN: echo foobar | %{lit} %{inputs}/shtest-stdin/print-stdin.py \ +# RUN: --param external=1 -a \ +# RUN: | FileCheck --check-prefix=CHECK-PIPE %s +# +# CHECK-PIPE: foobar + diff --git a/utils/bazel/llvm-project-overlay/llvm/utils/lit/tests/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/utils/lit/tests/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/llvm/utils/lit/tests/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/llvm/utils/lit/tests/BUILD.bazel @@ -33,5 +33,15 @@ "//llvm:not", ] + glob(["Inputs/**"]), ) - for src in glob(["*/*.py"]) + for src in glob( + include = ["**/*.py"], + exclude = [ + "Inputs/**", + # FIXME: these tests fail under bazel. + "discovery.py", + "max-time.py", + "selecting.py", + "shtest-recursive-substitution.py", + ] + ) ]