]>
Commit | Line | Data |
---|---|---|
908eaf68 | 1 | #!/bin/bash |
6bf19c94 CH |
2 | # |
3 | # Copyright (C) 2009 Red Hat, Inc. | |
4 | # Copyright (c) 2000-2003,2006 Silicon Graphics, Inc. All Rights Reserved. | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License as | |
8 | # published by the Free Software Foundation. | |
9 | # | |
10 | # This program is distributed in the hope that it would be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
e8c212d6 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6bf19c94 CH |
17 | # |
18 | # | |
19 | # setup and check for config parameters, and in particular | |
20 | # | |
21 | # EMAIL - email of the script runner. | |
79e40ab1 | 22 | # TEST_DIR - scratch test directory |
6bf19c94 CH |
23 | # |
24 | # - These can be added to $HOST_CONFIG_DIR (witch default to ./config) | |
25 | # below or a separate local configuration file can be used (using | |
26 | # the HOST_OPTIONS variable). | |
27 | # - This script is shared by the stress test system and the auto-qa | |
28 | # system (includes both regression test and benchmark components). | |
29 | # - this script shouldn't make any assertions about filesystem | |
30 | # validity or mountedness. | |
31 | # | |
32 | ||
33 | # all tests should use a common language setting to prevent golden | |
34 | # output mismatches. | |
35 | export LANG=C | |
36 | ||
37 | PATH=".:$PATH" | |
38 | ||
29926112 | 39 | HOST=`hostname -s 2> /dev/null` |
6bf19c94 CH |
40 | HOSTOS=`uname -s` |
41 | ||
42 | EMAIL=root@localhost # where auto-qa will send its status messages | |
43 | export HOST_OPTIONS=${HOST_OPTIONS:=local.config} | |
44 | export CHECK_OPTIONS=${CHECK_OPTIONS:="-g auto"} | |
45 | export PWD=`pwd` | |
46 | ||
f6c8c2e0 JC |
47 | export _QEMU_HANDLE=0 |
48 | ||
6bf19c94 CH |
49 | # $1 = prog to look for, $2* = default pathnames if not found in $PATH |
50 | set_prog_path() | |
51 | { | |
e465ce7d | 52 | p=`command -v $1 2> /dev/null` |
6bf19c94 CH |
53 | if [ -n "$p" -a -x "$p" ]; then |
54 | echo $p | |
55 | return 0 | |
56 | fi | |
57 | p=$1 | |
58 | ||
59 | shift | |
60 | for f; do | |
61 | if [ -x $f ]; then | |
62 | echo $f | |
63 | return 0 | |
64 | fi | |
65 | done | |
66 | ||
67 | echo "" | |
68 | return 1 | |
69 | } | |
70 | ||
71 | _fatal() | |
72 | { | |
73 | echo "$*" | |
74 | status=1 | |
75 | exit 1 | |
76 | } | |
77 | ||
78 | export PERL_PROG="`set_prog_path perl`" | |
79 | [ "$PERL_PROG" = "" ] && _fatal "perl not found" | |
80 | ||
81 | export AWK_PROG="`set_prog_path awk`" | |
82 | [ "$AWK_PROG" = "" ] && _fatal "awk not found" | |
83 | ||
84 | export SED_PROG="`set_prog_path sed`" | |
85 | [ "$SED_PROG" = "" ] && _fatal "sed not found" | |
86 | ||
87 | export BC_PROG="`set_prog_path bc`" | |
88 | [ "$BC_PROG" = "" ] && _fatal "bc not found" | |
89 | ||
90 | export PS_ALL_FLAGS="-ef" | |
91 | ||
d305fd5d LMR |
92 | if [ -z "$QEMU_PROG" ]; then |
93 | export QEMU_PROG="`set_prog_path qemu`" | |
94 | fi | |
6bf19c94 | 95 | |
d305fd5d LMR |
96 | if [ -z "$QEMU_IMG_PROG" ]; then |
97 | export QEMU_IMG_PROG="`set_prog_path qemu-img`" | |
98 | fi | |
6bf19c94 | 99 | |
d305fd5d LMR |
100 | if [ -z "$QEMU_IO_PROG" ]; then |
101 | export QEMU_IO_PROG="`set_prog_path qemu-io`" | |
102 | fi | |
a9660664 NT |
103 | |
104 | if [ -z "$QEMU_NBD_PROG" ]; then | |
105 | export QEMU_NBD_PROG="`set_prog_path qemu-nbd`" | |
106 | fi | |
6bf19c94 | 107 | |
934659c4 HR |
108 | _qemu_wrapper() |
109 | { | |
f6c8c2e0 JC |
110 | ( |
111 | if [ -n "${QEMU_NEED_PID}" ]; then | |
846a1d11 | 112 | echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid" |
f6c8c2e0 JC |
113 | fi |
114 | exec "$QEMU_PROG" $QEMU_OPTIONS "$@" | |
115 | ) | |
934659c4 HR |
116 | } |
117 | ||
118 | _qemu_img_wrapper() | |
119 | { | |
120 | (exec "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS "$@") | |
121 | } | |
122 | ||
123 | _qemu_io_wrapper() | |
124 | { | |
5f1525a6 | 125 | local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind |
076003f5 DB |
126 | local QEMU_IO_ARGS="$QEMU_IO_OPTIONS" |
127 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | |
128 | QEMU_IO_ARGS="--image-opts $QEMU_IO_ARGS" | |
b7e875b2 DB |
129 | if [ -n "$IMGKEYSECRET" ]; then |
130 | QEMU_IO_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IO_ARGS" | |
131 | fi | |
076003f5 | 132 | fi |
e6c17669 JC |
133 | local RETVAL |
134 | ( | |
135 | if [ "${VALGRIND_QEMU}" == "y" ]; then | |
076003f5 | 136 | exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" |
e6c17669 | 137 | else |
076003f5 | 138 | exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" |
e6c17669 JC |
139 | fi |
140 | ) | |
141 | RETVAL=$? | |
142 | if [ "${VALGRIND_QEMU}" == "y" ]; then | |
143 | if [ $RETVAL == 99 ]; then | |
144 | cat "${VALGRIND_LOGFILE}" | |
145 | fi | |
146 | rm -f "${VALGRIND_LOGFILE}" | |
147 | fi | |
148 | (exit $RETVAL) | |
934659c4 HR |
149 | } |
150 | ||
151 | _qemu_nbd_wrapper() | |
152 | { | |
f6c8c2e0 | 153 | ( |
846a1d11 | 154 | echo $BASHPID > "${QEMU_TEST_DIR}/qemu-nbd.pid" |
f6c8c2e0 JC |
155 | exec "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS "$@" |
156 | ) | |
934659c4 HR |
157 | } |
158 | ||
159 | export QEMU=_qemu_wrapper | |
160 | export QEMU_IMG=_qemu_img_wrapper | |
161 | export QEMU_IO=_qemu_io_wrapper | |
162 | export QEMU_NBD=_qemu_nbd_wrapper | |
163 | ||
076003f5 DB |
164 | QEMU_IMG_EXTRA_ARGS= |
165 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | |
166 | QEMU_IMG_EXTRA_ARGS="--image-opts $QEMU_IMG_EXTRA_ARGS" | |
b7e875b2 DB |
167 | if [ -n "$IMGKEYSECRET" ]; then |
168 | QEMU_IMG_EXTRA_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IMG_EXTRA_ARGS" | |
169 | fi | |
076003f5 DB |
170 | fi |
171 | export QEMU_IMG_EXTRA_ARGS | |
172 | ||
173 | ||
8a7607c2 BT |
174 | default_machine=$($QEMU -machine help | sed -n '/(default)/ s/ .*//p') |
175 | default_alias_machine=$($QEMU -machine help | \ | |
176 | sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }") | |
177 | if [[ "$default_alias_machine" ]]; then | |
e166b414 BT |
178 | default_machine="$default_alias_machine" |
179 | fi | |
180 | ||
181 | export QEMU_DEFAULT_MACHINE="$default_machine" | |
6bf19c94 CH |
182 | |
183 | [ -f /etc/qemu-iotest.config ] && . /etc/qemu-iotest.config | |
184 | ||
5e654e08 | 185 | if [ -z "$TEST_DIR" ]; then |
79e40ab1 | 186 | TEST_DIR=`pwd`/scratch |
5e654e08 ML |
187 | fi |
188 | ||
846a1d11 JC |
189 | QEMU_TEST_DIR="${TEST_DIR}" |
190 | ||
6bf19c94 | 191 | if [ ! -e "$TEST_DIR" ]; then |
79e40ab1 | 192 | mkdir "$TEST_DIR" |
6bf19c94 CH |
193 | fi |
194 | ||
195 | if [ ! -d "$TEST_DIR" ]; then | |
196 | echo "common.config: Error: \$TEST_DIR ($TEST_DIR) is not a directory" | |
197 | exit 1 | |
198 | fi | |
199 | ||
049255b6 SH |
200 | export TEST_DIR |
201 | ||
85edbd37 | 202 | if [ -z "$SAMPLE_IMG_DIR" ]; then |
e8f8624d | 203 | SAMPLE_IMG_DIR="$source_iotests/sample_images" |
85edbd37 JC |
204 | fi |
205 | ||
206 | if [ ! -d "$SAMPLE_IMG_DIR" ]; then | |
207 | echo "common.config: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory" | |
208 | exit 1 | |
209 | fi | |
210 | ||
211 | export SAMPLE_IMG_DIR | |
212 | ||
6bf19c94 CH |
213 | _readlink() |
214 | { | |
215 | if [ $# -ne 1 ]; then | |
216 | echo "Usage: _readlink filename" 1>&2 | |
217 | exit 1 | |
218 | fi | |
219 | ||
220 | perl -e "\$in=\"$1\";" -e ' | |
221 | $lnk = readlink($in); | |
222 | if ($lnk =~ m!^/.*!) { | |
223 | print "$lnk\n"; | |
224 | } | |
225 | else { | |
226 | chomp($dir = `dirname $in`); | |
227 | print "$dir/$lnk\n"; | |
228 | }' | |
229 | } | |
230 | ||
231 | # make sure this script returns success | |
a2d9c0c4 | 232 | true |