patch more_set_prog_path
[xfstests-dev.git] / common.config
1 ##/bin/sh
2 #
3 # Copyright (c) 2000-2003,2006 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # setup and check for config parameters, and in particular
6 #
7 # EMAIL -           email of the script runner.
8 # TEST_DIR -        scratch test directory that is in an already
9 #                   mounted XFS file system, needs to be be world
10 #                   writeable
11 # TEST_DEV -        device for file system containing TEST_DIR
12 # SCRATCH_DEV -     device you can make a scratch file system on
13 # SCRATCH_MNT -     mount point for scratch file system
14 #
15 # and optionally:
16 # SCRATCH_LOGDEV -  scratch log device for external log testing
17 # SCRATCH_RTDEV -   scratch rt dev
18 # TEST_LOGDEV -     test log device for external log testing
19 # TEST_RTDEV -      test rt dev
20 # TAPE_DEV -        the tape device for the xfsdump tests
21 # RMT_TAPE_DEV -    the remote tape device for the xfsdump tests
22 # RMT_IRIXTAPE_DEV- the IRIX remote tape device for the xfsdump tests
23 # RMT_TAPE_USER -   remote user for tape device
24 #
25 # - These can be added to $HOST_CONFIG_DIR (witch default to ./config)
26 #   below or a separate local configuration file can be used (using
27 #   the HOST_OPTIONS variable).
28 # - This script is shared by the stress test system and the auto-qa
29 #   system (includes both regression test and benchmark components).
30 # - TEST_DEV & TEST_DIR must be assigned.
31 # - this script shouldn't make any assertions about filesystem
32 #   validity or mountedness.
33 #
34
35 # all tests should use a common language setting to prevent golden
36 # output mismatches.
37 export LANG=C
38
39 # Warning: don't put freeware before /usr/bsd on IRIX coz you'll
40 #  get the wrong hostname and set your system name to -s  :)
41 [ -d /usr/bsd ] && PATH=$PATH:/usr/bsd
42 [ -d /usr/freeware/bin ] && PATH=$PATH:/usr/freeware/bin
43 PATH=".:$PATH"
44
45 HOST=`hostname -s`
46 HOSTOS=`uname -s`
47 [ "$HOSTOS" = "IRIX64" ] && HOSTOS="IRIX"
48
49 MODULAR=0               # using XFS as a module or not
50 BOOT="/boot"            # install target for kernels
51 export EXTRA=${EXTRA:=xfs-qa}
52
53 # general parameters (mainly for auto-qa)
54 SOAK_PROC=3             # -p option to fsstress
55 SOAK_STRESS=10000       # -n option to fsstress
56 SOAK_PASSES=-1          # count of repetitions of fsstress (while soaking)
57 EMAIL=root@localhost    # where auto-qa will send its status messages
58 export HOST_OPTIONS=${HOST_OPTIONS:=local.config}
59 export CHECK_OPTIONS=${CHECK_OPTIONS:="-g auto"}
60 export BENCH_PASSES=${BENCH_PASSES:=5}
61 export XFS_MKFS_OPTIONS=${XFS_MKFS_OPTIONS:=-bsize=4096}
62
63 export PWD=`pwd`
64 #export DEBUG=${DEBUG:=...} # arbitrary CFLAGS really.
65 export MALLOCLIB=${MALLOCLIB:=/usr/lib/libefence.a}
66 export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes}
67
68 # $1 = prog to look for, $2* = default pathnames if not found in $PATH
69 set_prog_path()
70 {
71     p=`which $1 2> /dev/null`
72     if [ -n "$p" -a -x "$p" ]; then
73         echo $p
74         return 0
75     fi
76     p=$1
77
78     shift
79     for f; do
80         if [ -x $f ]; then
81             echo $f
82             return 0
83         fi
84     done
85
86     echo ""
87     return 1
88 }
89
90 _fatal()
91 {
92     echo "$*"
93     status=1
94     exit 1
95 }
96
97 export MKFS_PROG="`set_prog_path mkfs`"
98 [ "$MKFS_PROG" = "" ] && _fatal "mkfs not found"
99
100 export MOUNT_PROG="`set_prog_path mount`"
101 [ "$MOUNT_PROG" = "" ] && _fatal "mount not found"
102
103 export UMOUNT_PROG="`set_prog_path umount`"
104 [ "$UMOUNT_PROG" = "" ] && _fatal "umount not found"
105
106 export FSSTRESS_PROG="`set_prog_path fsstress $PWD/ltp/fsstress`"
107 [ "$FSSTRESS_PROG" = "" ] && _fatal "fsstress not found"
108
109 export NSLOOKUP_PROG="`set_prog_path nslookup`"
110 [ "$NSLOOKUP_PROG" = "" ] && _fatal "nslookup not found"
111
112 export PERL_PROG="`set_prog_path perl`"
113 [ "$PERL_PROG" = "" ] && _fatal "perl not found"
114
115 export AWK_PROG="`set_prog_path awk`"
116 [ "$AWK_PROG" = "" ] && _fatal "awk not found"
117
118 export SED_PROG="`set_prog_path sed`"
119 [ "$SED_PROG" = "" ] && _fatal "sed not found"
120
121 export BC_PROG="`set_prog_path bc`"
122 [ "$BC_PROG" = "" ] && _fatal "bc not found"
123
124 # Tests handle these if missing
125 export ATTR_PROG="`set_prog_path attr`"
126 export GETFATTR_PROG="`set_prog_path getfattr`"
127 export CHACL_PROG="`set_prog_path chacl`"
128 export KILLALL_PROG="`set_prog_path killall`"
129 export INDENT_PROG="`set_prog_path indent`"
130
131 export PS_ALL_FLAGS="-ef"
132
133 export DF_PROG="`set_prog_path df`"
134 [ "$DF_PROG" = "" ] && _fatal "df not found"
135 [ "$HOSTOS" = "Linux" ] && export DF_PROG="$DF_PROG -T"
136
137 export XFS_LOGPRINT_PROG="`set_prog_path xfs_logprint`"
138 export XFS_REPAIR_PROG="`set_prog_path xfs_repair`"
139 export XFS_CHECK_PROG="`set_prog_path xfs_check`"
140 export XFS_DB_PROG="`set_prog_path xfs_db`"
141 export XFS_GROWFS_PROG=`set_prog_path xfs_growfs`
142 export XFS_IO_PROG="`set_prog_path xfs_io`"
143 export XFS_COPY_PROG="`set_prog_path xfs_copy`"
144 export XFS_PARALLEL_REPAIR_PROG="`set_prog_path xfs_prepair`"
145 export XFS_PARALLEL_REPAIR64_PROG="`set_prog_path xfs_prepair64`"
146 export XFSDUMP_PROG="`set_prog_path xfsdump`"
147 export XFSRESTORE_PROG="`set_prog_path xfsrestore`"
148 export XFSINVUTIL_PROG="`set_prog_path xfsinvutil`"
149 export XFS_QUOTA_PROG="`set_prog_path xfs_quota`"
150
151 # Generate a comparable xfsprogs version number in the form of
152 # major * 10000 + minor * 100 + release
153 #
154 # $ xfs_db -V
155 # xfs_db version 2.9.7
156 #
157 # so, 2.9.7 = 20907
158 _version=`$XFS_DB_PROG -V | $AWK_PROG '
159         /version/ {
160                 if (split($3,ver,".") == 3)
161                         print (ver[1] * 10000) + (ver[2] * 100) + ver[3];
162         }'`
163 [ -z "$_version" ] && _fatal "xfsprogs version cannot be found"
164 export XFSPROGS_VERSION="$_version"
165
166 case "$HOSTOS" in
167     IRIX*)
168         export MKFS_XFS_PROG="`set_prog_path mkfs_xfs`"
169         export MKFS_UDF_PROG="`set_prog_path mkfs_udf`"
170         export XFS_FSR_PROG="`set_prog_path /usr/etc/fsr_xfs`"
171         export MKFS_NFS_PROG="false"
172         ;;
173     Linux)
174         export MKFS_XFS_PROG="`set_prog_path mkfs.xfs`"
175         export MKFS_UDF_PROG="`set_prog_path mkudffs`"
176         export XFS_FSR_PROG="`set_prog_path xfs_fsr`"
177         export MKFS_NFS_PROG="false"
178         ;;
179 esac
180
181 known_hosts()
182 {
183   [ "$HOST_CONFIG_DIR" ] || HOST_CONFIG_DIR=`pwd`/configs
184
185   [ -f /etc/xfsqa.config ]             && . /etc/xfsqa.config
186   [ -f $HOST_CONFIG_DIR/$HOST ]        && . $HOST_CONFIG_DIR/$HOST
187   [ -f $HOST_CONFIG_DIR/$HOST.config ] && . $HOST_CONFIG_DIR/$HOST.config
188
189   MC=""
190 #  Non-Mandatory Config values.
191 #  [ -z "$MODULAR" ]        && MC="$MC MODULAR"
192 #  [ -z "$TEST_LOGDEV" ]    && MC="$MC TEST_LOGDEV"
193 #  [ -z "$SCRATCH_LOGDEV" ] && MC="$MC SCRATCH_LOGDEV"
194 #  [ -z "$SCRATCH_RTDEV" ]  && MC="$MC SCRATCH_RTDEV"
195
196   [ -z "$EMAIL" ]          && MC="$MC EMAIL"
197   [ -z "$TEST_DIR" ]       && MC="$MC TEST_DIR"
198   [ -z "$TEST_DEV" ]       && MC="$MC TEST_DEV"
199
200   [ -z "$SCRATCH_MNT" ]    && MC="$MC SCRATCH_MNT"
201   [ -z "$SCRATCH_DEV" ]    && MC="$MC SCRATCH_DEV"
202
203   [ "$MC" ] && (echo "Warning: need to define parameters for host $HOST";\
204                 echo "       or set variables:"; \
205                 echo "       $MC")
206 #  if [ -e configs/$HOST.config ]
207 #     then echo "Not carring, we have a configfile ($HOST_CONFIG_DIR/$HOST)"
208 #  else
209      [ "$MC" ] &&  exit 1
210 #  fi
211 }
212
213 if [ -f "$HOST_OPTIONS" ]; then
214     . "$HOST_OPTIONS"
215 else
216     known_hosts
217 fi
218
219 echo $TEST_DEV | grep -q ":" > /dev/null 2>&1
220 if [ ! -b "$TEST_DEV" -a "$?" != "0" ]; then
221     echo "common.config: Error: \$TEST_DEV ($TEST_DEV) is not a block device or a NFS filesystem"
222     exit 1
223 fi
224
225 if [ ! -d "$TEST_DIR" ]; then
226     echo "common.config: Error: \$TEST_DIR ($TEST_DIR) is not a directory"
227     exit 1
228 fi
229
230 echo $SCRATCH_DEV | grep -q ":" > /dev/null 2>&1
231 if [ ! -z "$SCRATCH_DEV" -a ! -b "$SCRATCH_DEV" -a "$?" != "0" ]; then
232     echo "common.config: Error: \$SCRATCH_DEV ($SCRATCH_DEV) is not a block device or a NFS filesystem"
233     exit 1
234 fi
235
236 if [ ! -z "$SCRATCH_MNT" -a ! -d "$SCRATCH_MNT" ]; then
237     echo "common.config: Error: \$SCRATCH_MNT ($SCRATCH_MNT) is not a directory"
238     exit 1
239 fi
240
241 _readlink()
242 {
243     if [ $# -ne 1 ]; then
244         echo "Usage: _readlink filename" 1>&2
245         exit 1
246     fi
247
248     perl -e "\$in=\"$1\";" -e '
249     $lnk = readlink($in);
250     if ($lnk =~ m!^/.*!) {
251         print "$lnk\n";
252     }
253     else {
254         chomp($dir = `dirname $in`);
255         print "$dir/$lnk\n";
256     }'
257 }
258
259 # if devfs is running expand the full /dev/.. pathname - this is what will be
260 # returned by utilities such as mount
261 [ -L "$TEST_DEV" ] && TEST_DEV=`_readlink $TEST_DEV`
262 [ -L "$SCRATCH_DEV" ] && SCRATCH_DEV=`_readlink $SCRATCH_DEV`
263 [ -L "$SCRATCH_LOGDEV" ] && SCRATCH_LOGDEV=`_readlink $SCRATCH_LOGDEV`
264 [ -L "$SCRATCH_RTDEV" ] && SCRATCH_RTDEV=`_readlink $SCRATCH_LOGDEV`
265
266 # make sure this script returns success
267 /bin/true