Blame scripts/cross-test-ssh.sh

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