opts: produce valid command line in qemu_opts_print
[qemu.git] / tests / qemu-iotests / common.config
blob596bb2b1e566ffb4e501d4e9682c0c24e9d38adb
1 #!/bin/bash
3 # Copyright (C) 2009 Red Hat, Inc.
4 # Copyright (c) 2000-2003,2006 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # setup and check for config parameters, and in particular
21 # EMAIL - email of the script runner.
22 # TEST_DIR - scratch test directory
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.
33 # all tests should use a common language setting to prevent golden
34 # output mismatches.
35 export LANG=C
37 PATH=".:$PATH"
39 HOST=`hostname -s 2> /dev/null`
40 HOSTOS=`uname -s`
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`
47 # $1 = prog to look for, $2* = default pathnames if not found in $PATH
48 set_prog_path()
50 p=`command -v $1 2> /dev/null`
51 if [ -n "$p" -a -x "$p" ]; then
52 echo $p
53 return 0
55 p=$1
57 shift
58 for f; do
59 if [ -x $f ]; then
60 echo $f
61 return 0
63 done
65 echo ""
66 return 1
69 _fatal()
71 echo "$*"
72 status=1
73 exit 1
76 export PERL_PROG="`set_prog_path perl`"
77 [ "$PERL_PROG" = "" ] && _fatal "perl not found"
79 export AWK_PROG="`set_prog_path awk`"
80 [ "$AWK_PROG" = "" ] && _fatal "awk not found"
82 export SED_PROG="`set_prog_path sed`"
83 [ "$SED_PROG" = "" ] && _fatal "sed not found"
85 export BC_PROG="`set_prog_path bc`"
86 [ "$BC_PROG" = "" ] && _fatal "bc not found"
88 export PS_ALL_FLAGS="-ef"
90 if [ -z "$QEMU_PROG" ]; then
91 export QEMU_PROG="`set_prog_path qemu`"
94 if [ -z "$QEMU_IMG_PROG" ]; then
95 export QEMU_IMG_PROG="`set_prog_path qemu-img`"
98 if [ -z "$QEMU_IO_PROG" ]; then
99 export QEMU_IO_PROG="`set_prog_path qemu-io`"
102 if [ -z "$QEMU_NBD_PROG" ]; then
103 export QEMU_NBD_PROG="`set_prog_path qemu-nbd`"
106 _qemu_wrapper()
108 (exec "$QEMU_PROG" $QEMU_OPTIONS "$@")
111 _qemu_img_wrapper()
113 (exec "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS "$@")
116 _qemu_io_wrapper()
118 (exec "$QEMU_IO_PROG" $QEMU_IO_OPTIONS "$@")
121 _qemu_nbd_wrapper()
123 (exec "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS "$@")
126 export QEMU=_qemu_wrapper
127 export QEMU_IMG=_qemu_img_wrapper
128 export QEMU_IO=_qemu_io_wrapper
129 export QEMU_NBD=_qemu_nbd_wrapper
131 default_machine=$($QEMU -machine \? | awk '/(default)/{print $1}')
132 default_alias_machine=$($QEMU -machine \? |\
133 awk -v var_default_machine="$default_machine"\)\
134 '{if ($(NF-2)=="(alias"&&$(NF-1)=="of"&&$(NF)==var_default_machine){print $1}}')
135 if [ ! -z "$default_alias_machine" ]; then
136 default_machine="$default_alias_machine"
139 export QEMU_DEFAULT_MACHINE="$default_machine"
141 [ -f /etc/qemu-iotest.config ] && . /etc/qemu-iotest.config
143 if [ -z "$TEST_DIR" ]; then
144 TEST_DIR=`pwd`/scratch
147 if [ ! -e "$TEST_DIR" ]; then
148 mkdir "$TEST_DIR"
151 if [ ! -d "$TEST_DIR" ]; then
152 echo "common.config: Error: \$TEST_DIR ($TEST_DIR) is not a directory"
153 exit 1
156 export TEST_DIR
158 if [ -z "$SAMPLE_IMG_DIR" ]; then
159 SAMPLE_IMG_DIR="$source_iotests/sample_images"
162 if [ ! -d "$SAMPLE_IMG_DIR" ]; then
163 echo "common.config: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory"
164 exit 1
167 export SAMPLE_IMG_DIR
169 _readlink()
171 if [ $# -ne 1 ]; then
172 echo "Usage: _readlink filename" 1>&2
173 exit 1
176 perl -e "\$in=\"$1\";" -e '
177 $lnk = readlink($in);
178 if ($lnk =~ m!^/.*!) {
179 print "$lnk\n";
181 else {
182 chomp($dir = `dirname $in`);
183 print "$dir/$lnk\n";
187 # make sure this script returns success
188 true