[libcxx-commits] [libcxx] 07e4625 - [libc++] Allow running .sh.cpp tests with SSHExecutors
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Mar 31 12:51:12 PDT 2020
Author: Louis Dionne
Date: 2020-03-31T15:50:42-04:00
New Revision: 07e462526d0cbae40b320e1a4307ce11e197fb0a
URL: https://github.com/llvm/llvm-project/commit/07e462526d0cbae40b320e1a4307ce11e197fb0a
DIFF: https://github.com/llvm/llvm-project/commit/07e462526d0cbae40b320e1a4307ce11e197fb0a.diff
LOG: [libc++] Allow running .sh.cpp tests with SSHExecutors
This commit adds a script that can be used as an %{exec} substitution
such that .sh.cpp tests can now run on remote hosts when using the
SSHExecutor.
Added:
libcxx/utils/ssh.py
Modified:
libcxx/test/libcxx/double_include.sh.cpp
libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
libcxx/test/libcxx/selftest/exec.sh.cpp
libcxx/test/libcxx/selftest/test.sh.cpp
libcxx/test/libcxx/strings/basic.string/PR42676.sh.cpp
libcxx/test/std/containers/associative/map/PR28469_undefined_behavior_segfault.sh.cpp
libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_terminates.sh.cpp
libcxx/utils/libcxx/test/config.py
libcxx/utils/libcxx/test/format.py
Removed:
################################################################################
diff --git a/libcxx/test/libcxx/double_include.sh.cpp b/libcxx/test/libcxx/double_include.sh.cpp
index b2d475c18aec..17236df3cda7 100644
--- a/libcxx/test/libcxx/double_include.sh.cpp
+++ b/libcxx/test/libcxx/double_include.sh.cpp
@@ -9,6 +9,7 @@
// Test that we can include each header in two TU's and link them together.
+// FILE_DEPENDENCIES: %t.exe
// RUN: %{cxx} -c %s -o %t.first.o %{flags} %{compile_flags}
// RUN: %{cxx} -c %s -o %t.second.o -DWITH_MAIN %{flags} %{compile_flags}
// RUN: %{cxx} -o %t.exe %t.first.o %t.second.o %{flags} %{link_flags}
diff --git a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
index 7c6692d489b4..da5f3b6b12b4 100644
--- a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
+++ b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
@@ -39,6 +39,7 @@
// GCC doesn't support the aligned-allocation flags.
// XFAIL: gcc
+// FILE_DEPENDENCIES: %t.exe
// RUN: %{build} -faligned-allocation -fsized-deallocation
// RUN: %{run}
// RUN: %{build} -faligned-allocation -fno-sized-deallocation -DNO_SIZE
diff --git a/libcxx/test/libcxx/selftest/exec.sh.cpp b/libcxx/test/libcxx/selftest/exec.sh.cpp
index 19c3d590978b..de42de3e7df2 100644
--- a/libcxx/test/libcxx/selftest/exec.sh.cpp
+++ b/libcxx/test/libcxx/selftest/exec.sh.cpp
@@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
+// FILE_DEPENDENCIES: %t.exe
+
// RUN: %{build}
// RUN: %{exec} %t.exe "HELLO"
diff --git a/libcxx/test/libcxx/selftest/test.sh.cpp b/libcxx/test/libcxx/selftest/test.sh.cpp
index 5c4db16d84d1..ad75f0227e81 100644
--- a/libcxx/test/libcxx/selftest/test.sh.cpp
+++ b/libcxx/test/libcxx/selftest/test.sh.cpp
@@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
+// FILE_DEPENDENCIES: %t.exe
+
// RUN: %{build}
// RUN: %{run}
diff --git a/libcxx/test/libcxx/strings/basic.string/PR42676.sh.cpp b/libcxx/test/libcxx/strings/basic.string/PR42676.sh.cpp
index 31bf81efa004..18faaf02871d 100644
--- a/libcxx/test/libcxx/strings/basic.string/PR42676.sh.cpp
+++ b/libcxx/test/libcxx/strings/basic.string/PR42676.sh.cpp
@@ -8,6 +8,7 @@
// Regression test for PR42676.
+// FILE_DEPENDENCIES: %t.exe
// RUN: %{cxx} %{flags} %s -o %t.exe %{compile_flags} %{link_flags} -D_LIBCPP_HIDE_FROM_ABI_PER_TU
// RUN: %{run}
diff --git a/libcxx/test/std/containers/associative/map/PR28469_undefined_behavior_segfault.sh.cpp b/libcxx/test/std/containers/associative/map/PR28469_undefined_behavior_segfault.sh.cpp
index 4bd33ce4bb32..83aa36dff3dd 100644
--- a/libcxx/test/std/containers/associative/map/PR28469_undefined_behavior_segfault.sh.cpp
+++ b/libcxx/test/std/containers/associative/map/PR28469_undefined_behavior_segfault.sh.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+// FILE_DEPENDENCIES: %t.exe
// RUN: %{build} -O2
// RUN: %{run}
diff --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_terminates.sh.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_terminates.sh.cpp
index df02f7a2c47b..0ee02919f221 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_terminates.sh.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_terminates.sh.cpp
@@ -13,6 +13,7 @@
// class condition_variable_any;
+// FILE_DEPENDENCIES: %t.exe
// RUN: %{build}
// RUN: %{run} 1
// RUN: %{run} 2
diff --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py
index b59370766280..9c154bafa808 100644
--- a/libcxx/utils/libcxx/test/config.py
+++ b/libcxx/utils/libcxx/test/config.py
@@ -1038,13 +1038,21 @@ def configure_substitutions(self):
# Configure exec prefix substitutions.
# Configure run env substitution.
codesign_ident = self.get_lit_conf('llvm_codesign_identity', '')
- run_py = os.path.join(self.libcxx_src_root, 'utils', 'run.py')
env_vars = ' '.join('%s=%s' % (k, pipes.quote(v)) for (k, v) in self.exec_env.items())
- exec_str = '%s %s --codesign_identity "%s" --working_directory "%%S" ' \
- '--dependencies %%{file_dependencies} --env %s -- ' % \
- (pipes.quote(sys.executable), pipes.quote(run_py),
- codesign_ident, env_vars)
- sub.append(('%{exec}', exec_str))
+ exec_args = [
+ '--codesign_identity "{}"'.format(codesign_ident),
+ '--dependencies %{file_dependencies}',
+ '--env {}'.format(env_vars)
+ ]
+ if isinstance(self.executor, SSHExecutor):
+ exec_args.append('--host {}'.format(self.executor.user_prefix + self.executor.host))
+ executor = os.path.join(self.libcxx_src_root, 'utils', 'ssh.py')
+ else:
+ exec_args.append('--working_directory "%S"')
+ executor = os.path.join(self.libcxx_src_root, 'utils', 'run.py')
+ sub.append(('%{exec}', '{} {} {} -- '.format(pipes.quote(sys.executable),
+ pipes.quote(executor),
+ ' '.join(exec_args))))
sub.append(('%{run}', '%{exec} %t.exe'))
# Configure not program substitutions
not_py = os.path.join(self.libcxx_src_root, 'utils', 'not.py')
diff --git a/libcxx/utils/libcxx/test/format.py b/libcxx/utils/libcxx/test/format.py
index a9eb7d9855c5..ff23273ab9a6 100644
--- a/libcxx/utils/libcxx/test/format.py
+++ b/libcxx/utils/libcxx/test/format.py
@@ -18,6 +18,7 @@
# pylint: disable=import-error
from libcxx.test.executor import LocalExecutor as LocalExecutor
+from libcxx.test.executor import SSHExecutor as SSHExecutor
import libcxx.util
@@ -168,8 +169,9 @@ def _execute(self, test, lit_config):
# Dispatch the test based on its suffix.
if is_sh_test:
- if not isinstance(self.executor, LocalExecutor):
- # We can't run ShTest tests with a executor yet.
+ if not isinstance(self.executor, LocalExecutor) and not isinstance(self.executor, SSHExecutor):
+ # We can't run ShTest tests with other executors than
+ # LocalExecutor and SSHExecutor yet.
# For now, bail on trying to run them
return lit.Test.UNSUPPORTED, 'ShTest format not yet supported'
test.config.environment = self.executor.merge_environments(os.environ, self.exec_env)
diff --git a/libcxx/utils/ssh.py b/libcxx/utils/ssh.py
new file mode 100644
index 000000000000..20acaeb00e3d
--- /dev/null
+++ b/libcxx/utils/ssh.py
@@ -0,0 +1,90 @@
+#===----------------------------------------------------------------------===##
+#
+# 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
+#
+#===----------------------------------------------------------------------===##
+
+"""
+Runs an executable on a remote host.
+
+This is meant to be used as an executor when running the C++ Standard Library
+conformance test suite.
+"""
+
+import argparse
+import os
+import subprocess
+import sys
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--host', type=str, required=True)
+ parser.add_argument('--codesign_identity', type=str, required=False)
+ parser.add_argument('--dependencies', type=str, nargs='*', required=True)
+ parser.add_argument('--env', type=str, nargs='*', required=True)
+ (args, remaining) = parser.parse_known_args(sys.argv[1:])
+
+ if len(remaining) < 2:
+ sys.stderr.write('Missing actual commands to run')
+ exit(1)
+ remaining = remaining[1:] # Skip the '--'
+
+ # HACK:
+ # If the first argument is a file that ends in `.tmp.exe`, assume it is
+ # the name of an executable generated by a test file. This allows us to
+ # do custom processing like codesigning the executable and changing its
+ # path when running on the remote host. It's possible for there to be no
+ # such executable, for example in the case of a .sh.cpp test.
+ exe = None
+ if os.path.exists(remaining[0]) and remaining[0].endswith('.tmp.exe'):
+ exe = remaining.pop(0)
+
+ # If there's an executable, do any necessary codesigning.
+ if exe and args.codesign_identity:
+ rc = subprocess.call(['xcrun', 'codesign', '-f', '-s', args.codesign_identity, exe], env={})
+ if rc != 0:
+ sys.stderr.write('Failed to codesign: {}'.format(exe))
+ return rc
+
+ ssh = lambda command: ['ssh', '-oBatchMode=yes', args.host, command]
+ scp = lambda src, dst: ['scp', '-oBatchMode=yes', '-r', src, '{}:{}'.format(args.host, dst)]
+
+ # Create a temporary directory where the test will be run
+ tmp = subprocess.check_output(ssh('mktemp -d /tmp/libcxx.XXXXXXXXXX')).strip()
+
+ # Ensure the test dependencies exist and scp them to the temporary directory.
+ # Test dependencies can be either files or directories, so the `scp` command
+ # needs to use `-r`.
+ for dep in args.dependencies:
+ if not os.path.exists(dep):
+ sys.stderr.write('Missing file or directory {} marked as a dependency of a test'.format(dep))
+ exit(1)
+ subprocess.call(scp(dep, tmp))
+
+ # If there's an executable, change its path to be in the temporary directory.
+ # We know it has been copied to the remote host when we handled the test
+ # dependencies above.
+ if exe:
+ exe = os.path.join(tmp, os.path.basename(exe))
+
+ # If there's an executable, make sure it has 'execute' permissions on the
+ # remote host. The host that compiled the executable might not have a notion
+ # of 'executable' permissions.
+ if exe:
+ subprocess.call(ssh('chmod +x {}'.format(exe)))
+
+ # Execute the command through SSH in the temporary directory, with the
+ # correct environment.
+ command = [exe] + remaining if exe else remaining
+ res = subprocess.call(ssh('cd {} && env -i {} {}'.format(tmp, ' '.join(args.env), ' '.join(command))))
+
+ # Remove the temporary directory when we're done.
+ subprocess.call(ssh('rm -r {}'.format(tmp)))
+
+ return res
+
+if __name__ == '__main__':
+ exit(main())
More information about the libcxx-commits
mailing list