[libcxx-commits] [libcxx] [libc++] Make sure we forward stdin through executors (PR #67064)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 21 14:06:26 PDT 2023


https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/67064

This allows running tests like the ones for std::cin even on SSH executors. This was originally reported as https://github.com/llvm/llvm-project/pull/66842#issuecomment-1728701639.

>From c891ff6dae3cc3e5e6790769f6a060177df7c6fd Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 21 Sep 2023 16:38:06 -0400
Subject: [PATCH] [libc++] Make sure we forward stdin through executors

This allows running tests like the ones for std::cin even on SSH executors.
This was originally reported as https://github.com/llvm/llvm-project/pull/66842#issuecomment-1728701639.
---
 .../libcxx/selftest/stdin-is-piped.sh.cpp     | 22 +++++++++++++++++++
 .../narrow.stream.objects/cin.sh.cpp          |  4 ----
 .../wide.stream.objects/wcin-imbue.sh.cpp     |  4 ----
 .../wide.stream.objects/wcin.sh.cpp           |  4 ----
 libcxx/utils/ssh.py                           |  9 +++++---
 5 files changed, 28 insertions(+), 15 deletions(-)
 create mode 100644 libcxx/test/libcxx/selftest/stdin-is-piped.sh.cpp

diff --git a/libcxx/test/libcxx/selftest/stdin-is-piped.sh.cpp b/libcxx/test/libcxx/selftest/stdin-is-piped.sh.cpp
new file mode 100644
index 000000000000000..ffd10631c6a67d4
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/stdin-is-piped.sh.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Make sure that the executor pipes standard input to the test-executable being run.
+
+// RUN: %{build}
+// RUN: echo "abc" | %{exec} %t.exe
+
+#include <cstdio>
+
+int main(int, char**) {
+  int input[] = {std::getchar(), std::getchar(), std::getchar()};
+
+  if (input[0] == 'a' && input[1] == 'b' && input[2] == 'c')
+    return 0;
+  return 1;
+}
diff --git a/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cin.sh.cpp b/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cin.sh.cpp
index 8fe98f9064d2ee6..b39cd57ab212f1d 100644
--- a/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cin.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cin.sh.cpp
@@ -9,10 +9,6 @@
 // TODO: Investigate
 // UNSUPPORTED: LIBCXX-AIX-FIXME
 
-// TODO: Make it possible to run this test when cross-compiling and running via a SSH executor
-//       This is a workaround to silence issues reported in https://github.com/llvm/llvm-project/pull/66842#issuecomment-1728701639
-// XFAIL: buildhost=windows && target={{.+}}-linux-{{.+}}
-
 // <iostream>
 
 // istream cin;
diff --git a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-imbue.sh.cpp b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-imbue.sh.cpp
index 27c9b0cf7adac58..6bdffc93f3b6693 100644
--- a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-imbue.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-imbue.sh.cpp
@@ -9,10 +9,6 @@
 // TODO: Investigate
 // UNSUPPORTED: LIBCXX-AIX-FIXME
 
-// TODO: Make it possible to run this test when cross-compiling and running via a SSH executor
-//       This is a workaround to silence issues reported in https://github.com/llvm/llvm-project/pull/66842#issuecomment-1728701639
-// XFAIL: buildhost=windows && target={{.+}}-linux-{{.+}}
-
 // <iostream>
 
 // wistream wcin;
diff --git a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin.sh.cpp b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin.sh.cpp
index 3780be1d5cbf226..c0f2c3258b540f6 100644
--- a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin.sh.cpp
@@ -9,10 +9,6 @@
 // TODO: Investigate
 // UNSUPPORTED: LIBCXX-AIX-FIXME
 
-// TODO: Make it possible to run this test when cross-compiling and running via a SSH executor
-//       This is a workaround to silence issues reported in https://github.com/llvm/llvm-project/pull/66842#issuecomment-1728701639
-// XFAIL: buildhost=windows && target={{.+}}-linux-{{.+}}
-
 // <iostream>
 
 // wistream wcin;
diff --git a/libcxx/utils/ssh.py b/libcxx/utils/ssh.py
index e1eaa5aae067e79..ec16efc3165ab1b 100755
--- a/libcxx/utils/ssh.py
+++ b/libcxx/utils/ssh.py
@@ -62,7 +62,8 @@ def runCommand(command, *args_, **kwargs):
         ssh("mktemp -d {}/libcxx.XXXXXXXXXX".format(args.tempdir)),
         universal_newlines=True,
         check=True,
-        capture_output=True
+        capture_output=True,
+        stdin=subprocess.DEVNULL
     ).stdout.strip()
 
     # HACK:
@@ -80,7 +81,7 @@ def runCommand(command, *args_, **kwargs):
         if args.codesign_identity:
             for exe in filter(isTestExe, commandLine):
                 codesign = ["codesign", "-f", "-s", args.codesign_identity, exe]
-                runCommand(codesign, env={}, check=True)
+                runCommand(codesign, env={}, check=True, stdin=subprocess.DEVNULL)
 
         # tar up the execution directory (which contains everything that's needed
         # to run the test), and copy the tarball over to the remote host.
@@ -93,7 +94,7 @@ def runCommand(command, *args_, **kwargs):
             # the temporary file while still open doesn't work on Windows.
             tmpTar.close()
             remoteTarball = pathOnRemote(tmpTar.name)
-            runCommand(scp(tmpTar.name, remoteTarball), check=True)
+            runCommand(scp(tmpTar.name, remoteTarball), check=True, stdin=subprocess.DEVNULL)
         finally:
             # Make sure we close the file in case an exception happens before
             # we've closed it above -- otherwise close() is idempotent.
@@ -130,6 +131,8 @@ def runCommand(command, *args_, **kwargs):
         remoteCommands.append(subprocess.list2cmdline(commandLine))
 
         # Finally, SSH to the remote host and execute all the commands.
+        # Make sure to forward stdin to the process so that the test suite
+        # can pipe stuff into the executor.
         rc = runCommand(ssh(" && ".join(remoteCommands))).returncode
         return rc
 



More information about the libcxx-commits mailing list