]>
Commit | Line | Data |
---|---|---|
df381762 JM |
1 | #! /bin/bash |
2 | # Run a testcase on a remote system, via ssh. | |
f7a9f785 | 3 | # Copyright (C) 2012-2016 Free Software Foundation, Inc. |
df381762 JM |
4 | # This file is part of the GNU C Library. |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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/>. | |
19 | ||
20 | # usage: cross-test-ssh.sh [--ssh SSH] HOST COMMAND ... | |
21 | # Run with --help flag to get more detailed help. | |
22 | ||
23 | progname="$(basename $0)" | |
df381762 JM |
24 | |
25 | usage="usage: ${progname} [--ssh SSH] HOST COMMAND ..." | |
26 | help="Run a glibc test COMMAND on the remote machine HOST, via ssh, | |
8540f6d2 | 27 | preserving the current working directory, and respecting quoting. |
df381762 JM |
28 | |
29 | If the '--ssh SSH' flag is present, use SSH as the SSH command, | |
30 | instead of ordinary 'ssh'. | |
31 | ||
8540f6d2 JM |
32 | If the '--timeoutfactor FACTOR' flag is present, set TIMEOUTFACTOR on |
33 | the remote machine to the specified FACTOR. | |
34 | ||
df381762 JM |
35 | To use this to run glibc tests, invoke the tests as follows: |
36 | ||
37 | $ make test-wrapper='ABSPATH/cross-test-ssh.sh HOST' tests | |
38 | ||
39 | where ABSPATH is the absolute path to this script, and HOST is the | |
40 | name of the machine to connect to via ssh. | |
41 | ||
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: | |
44 | ||
45 | $ make test-wrapper='ABSPATH/cross-test-ssh.sh USER@HOST' tests | |
46 | ||
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. | |
50 | ||
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. | |
54 | ||
55 | ${progname} runs COMMAND in the same directory on the HOST that | |
56 | ${progname} itself is run in on the build machine. | |
57 | ||
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 | |
8540f6d2 | 61 | appropriately." |
df381762 JM |
62 | |
63 | ssh='ssh' | |
f2f6d82f | 64 | timeoutfactor=$TIMEOUTFACTOR |
df381762 JM |
65 | while [ $# -gt 0 ]; do |
66 | case "$1" in | |
67 | ||
68 | "--ssh") | |
69 | shift | |
70 | if [ $# -lt 1 ]; then | |
71 | break | |
72 | fi | |
73 | ssh="$1" | |
74 | ;; | |
75 | ||
8540f6d2 JM |
76 | "--timeoutfactor") |
77 | shift | |
78 | if [ $# -lt 1 ]; then | |
79 | break | |
80 | fi | |
81 | timeoutfactor="$1" | |
82 | ;; | |
83 | ||
df381762 JM |
84 | "--help") |
85 | echo "$usage" | |
86 | echo "$help" | |
87 | exit 0 | |
88 | ;; | |
89 | ||
90 | *) | |
91 | break | |
92 | ;; | |
93 | esac | |
94 | shift | |
95 | done | |
96 | ||
97 | if [ $# -lt 1 ]; then | |
98 | echo "$usage" >&2 | |
99 | echo "Type '${progname} --help' for more detailed help." >&2 | |
100 | exit 1 | |
101 | fi | |
102 | ||
103 | host="$1"; shift | |
104 | ||
105 | # Print the sequence of arguments as strings properly quoted for the | |
106 | # Bourne shell, separated by spaces. | |
107 | bourne_quote () | |
108 | { | |
109 | local arg qarg | |
110 | for arg in "$@"; do | |
111 | qarg=${arg//\'/\'\\\'\'} | |
112 | echo -n "'$qarg' " | |
113 | done | |
114 | } | |
115 | ||
df381762 JM |
116 | # Transform the current argument list into a properly quoted Bourne shell |
117 | # command string. | |
118 | command="$(bourne_quote "$@")" | |
119 | ||
8540f6d2 JM |
120 | # Add command to set the current directory. |
121 | command="cd $(bourne_quote "$PWD") | |
a542b389 | 122 | ${command}" |
df381762 | 123 | |
8540f6d2 JM |
124 | # Add command to set the timeout factor, if required. |
125 | if [ "$timeoutfactor" ]; then | |
126 | command="export TIMEOUTFACTOR=$(bourne_quote "$timeoutfactor") | |
127 | ${command}" | |
128 | fi | |
129 | ||
df381762 JM |
130 | # HOST's sshd simply concatenates its arguments with spaces and |
131 | # passes them to some shell. We want to force the use of /bin/sh, | |
132 | # so we need to re-quote the whole command to ensure it appears as | |
133 | # the sole argument of the '-c' option. | |
134 | full_command="$(bourne_quote "${command}")" | |
135 | $ssh "$host" /bin/sh -c "$full_command" |