|
Packit |
6c4009 |
#!/bin/bash
|
|
Packit |
6c4009 |
# Run a testcase on a remote system, via ssh.
|
|
Packit |
6c4009 |
# Copyright (C) 2012-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
# This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
# modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
# License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
# version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
# Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
# License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
# <http://www.gnu.org/licenses/>.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# usage: cross-test-ssh.sh [--ssh SSH] HOST COMMAND ...
|
|
Packit |
6c4009 |
# Run with --help flag to get more detailed help.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
progname="$(basename $0)"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
usage="usage: ${progname} [--ssh SSH] HOST COMMAND ..."
|
|
Packit |
6c4009 |
help="Run a glibc test COMMAND on the remote machine HOST, via ssh,
|
|
Packit |
6c4009 |
preserving the current working directory, and respecting quoting.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If the '--ssh SSH' flag is present, use SSH as the SSH command,
|
|
Packit |
6c4009 |
instead of ordinary 'ssh'.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If the '--timeoutfactor FACTOR' flag is present, set TIMEOUTFACTOR on
|
|
Packit |
6c4009 |
the remote machine to the specified FACTOR.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
To use this to run glibc tests, invoke the tests as follows:
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
$ make test-wrapper='ABSPATH/cross-test-ssh.sh HOST' tests
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
where ABSPATH is the absolute path to this script, and HOST is the
|
|
Packit |
6c4009 |
name of the machine to connect to via ssh.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If you need to connect to the test machine as a different user, you
|
|
Packit |
6c4009 |
may specify that just as you would to SSH:
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
$ make test-wrapper='ABSPATH/cross-test-ssh.sh USER@HOST' tests
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Naturally, the remote user must have an appropriate public key, and
|
|
Packit |
6c4009 |
you will want to ensure that SSH does not prompt interactively for a
|
|
Packit |
6c4009 |
password on each connection.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
HOST and the build machines (on which 'make check' is being run) must
|
|
Packit |
6c4009 |
share a filesystem; all files needed by the tests must be visible at
|
|
Packit |
6c4009 |
the same paths on both machines.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
${progname} runs COMMAND in the same directory on the HOST that
|
|
Packit |
6c4009 |
${progname} itself is run in on the build machine.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The command and arguments are passed to the remote host in a way that
|
|
Packit |
6c4009 |
avoids any further shell substitution or expansion, on the assumption
|
|
Packit |
6c4009 |
that the shell on the build machine has already done them
|
|
Packit |
6c4009 |
appropriately."
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ssh='ssh'
|
|
Packit |
6c4009 |
timeoutfactor=$TIMEOUTFACTOR
|
|
Packit |
6c4009 |
while [ $# -gt 0 ]; do
|
|
Packit |
6c4009 |
case "$1" in
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
"--ssh")
|
|
Packit |
6c4009 |
shift
|
|
Packit |
6c4009 |
if [ $# -lt 1 ]; then
|
|
Packit |
6c4009 |
break
|
|
Packit |
6c4009 |
fi
|
|
Packit |
6c4009 |
ssh="$1"
|
|
Packit |
6c4009 |
;;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
"--timeoutfactor")
|
|
Packit |
6c4009 |
shift
|
|
Packit |
6c4009 |
if [ $# -lt 1 ]; then
|
|
Packit |
6c4009 |
break
|
|
Packit |
6c4009 |
fi
|
|
Packit |
6c4009 |
timeoutfactor="$1"
|
|
Packit |
6c4009 |
;;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
"--help")
|
|
Packit |
6c4009 |
echo "$usage"
|
|
Packit |
6c4009 |
echo "$help"
|
|
Packit |
6c4009 |
exit 0
|
|
Packit |
6c4009 |
;;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
*)
|
|
Packit |
6c4009 |
break
|
|
Packit |
6c4009 |
;;
|
|
Packit |
6c4009 |
esac
|
|
Packit |
6c4009 |
shift
|
|
Packit |
6c4009 |
done
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if [ $# -lt 1 ]; then
|
|
Packit |
6c4009 |
echo "$usage" >&2
|
|
Packit |
6c4009 |
echo "Type '${progname} --help' for more detailed help." >&2
|
|
Packit |
6c4009 |
exit 1
|
|
Packit |
6c4009 |
fi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
host="$1"; shift
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# Print the sequence of arguments as strings properly quoted for the
|
|
Packit |
6c4009 |
# Bourne shell, separated by spaces.
|
|
Packit |
6c4009 |
bourne_quote ()
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
local arg qarg
|
|
Packit |
6c4009 |
for arg in "$@"; do
|
|
Packit |
6c4009 |
qarg=${arg//\'/\'\\\'\'}
|
|
Packit |
6c4009 |
echo -n "'$qarg' "
|
|
Packit |
6c4009 |
done
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# Transform the current argument list into a properly quoted Bourne shell
|
|
Packit |
6c4009 |
# command string.
|
|
Packit |
6c4009 |
command="$(bourne_quote "$@")"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# Add command to set the current directory.
|
|
Packit |
6c4009 |
command="cd $(bourne_quote "$PWD")
|
|
Packit |
6c4009 |
${command}"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# Add command to set the timeout factor, if required.
|
|
Packit |
6c4009 |
if [ "$timeoutfactor" ]; then
|
|
Packit |
6c4009 |
command="export TIMEOUTFACTOR=$(bourne_quote "$timeoutfactor")
|
|
Packit |
6c4009 |
${command}"
|
|
Packit |
6c4009 |
fi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# HOST's sshd simply concatenates its arguments with spaces and
|
|
Packit |
6c4009 |
# passes them to some shell. We want to force the use of /bin/sh,
|
|
Packit |
6c4009 |
# so we need to re-quote the whole command to ensure it appears as
|
|
Packit |
6c4009 |
# the sole argument of the '-c' option.
|
|
Packit |
6c4009 |
full_command="$(bourne_quote "${command}")"
|
|
Packit |
6c4009 |
$ssh "$host" /bin/sh -c "$full_command"
|