2 # Run a testcase on a remote system, via ssh.
3 # Copyright (C) 2012-2014 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <http://www.gnu.org/licenses/>.
20 # usage: cross-test-ssh.sh [--ssh SSH] HOST COMMAND ...
21 # Run with --help flag to get more detailed help.
23 progname
="$(basename $0)"
24 env_blacklist
='HOME LOGNAME MAIL PATH SHELL SHLVL SSH_CLIENT SSH_CONNECTION
25 USER TERM TERMCAP PWD'
27 usage
="usage: ${progname} [--ssh SSH] HOST COMMAND ..."
28 help="Run a glibc test COMMAND on the remote machine HOST, via ssh,
29 passing environment variables, preserving the current working directory,
30 and respecting quoting.
32 If the '--ssh SSH' flag is present, use SSH as the SSH command,
33 instead of ordinary 'ssh'.
35 To use this to run glibc tests, invoke the tests as follows:
37 $ make test-wrapper='ABSPATH/cross-test-ssh.sh HOST' tests
39 where ABSPATH is the absolute path to this script, and HOST is the
40 name of the machine to connect to via ssh.
42 If you need to connect to the test machine as a different user, you
43 may specify that just as you would to SSH:
45 $ make test-wrapper='ABSPATH/cross-test-ssh.sh USER@HOST' tests
47 Naturally, the remote user must have an appropriate public key, and
48 you will want to ensure that SSH does not prompt interactively for a
49 password on each connection.
51 HOST and the build machines (on which 'make check' is being run) must
52 share a filesystem; all files needed by the tests must be visible at
53 the same paths on both machines.
55 ${progname} runs COMMAND in the same directory on the HOST that
56 ${progname} itself is run in on the build machine.
58 The command and arguments are passed to the remote host in a way that
59 avoids any further shell substitution or expansion, on the assumption
60 that the shell on the build machine has already done them
63 ${progname} propagates the values all environment variables through to
64 the remote target, except the following:
68 while [ $# -gt 0 ]; do
94 echo "Type '${progname} --help' for more detailed help." >&2
100 # Print the sequence of arguments as strings properly quoted for the
101 # Bourne shell, separated by spaces.
106 qarg
=${arg//\'/\'\\\'\'}
111 # Unset all variables from the blacklist. Then echo all exported
115 (unset ${env_blacklist}; export -p) |
sed 's/^declare -x/export/'
118 # Produce commands to carry over the current environment, less blacklisted
120 exports
="$(blacklist_exports)"
122 # Transform the current argument list into a properly quoted Bourne shell
124 command="$(bourne_quote "$@
")"
126 # Add commands to set environment variables and the current directory.
128 cd $(bourne_quote "$PWD")
131 # HOST's sshd simply concatenates its arguments with spaces and
132 # passes them to some shell. We want to force the use of /bin/sh,
133 # so we need to re-quote the whole command to ensure it appears as
134 # the sole argument of the '-c' option.
135 full_command
="$(bourne_quote "${command}")"
136 $ssh "$host" /bin
/sh
-c "$full_command"