Whamcloud - gitweb
ff29a4cddbb1db239290b8d9f847aea97c6e154a
[fs/lustre-release.git] / lustre / tests / auster
1 #!/bin/bash
2 #
3 #
4 # auster - drive lustre tests
5 # TODO
6 #  1. --time-limt <seconds>  add per test time limit, kill test if it runs to long
7 #  2. Read list of tests to run from a file. same syntax as cli, but one test per line
8 #  3. Run test on remote node
9 #  4. Use long opts for auster options
10
11 set -e
12
13 export TF_FAIL=/tmp/tf.fail
14
15 usage() {
16     cat <<EOF
17 Usage ${0##*/} [options]  suite [suite optoins] [suite [suite options]]
18 Run Lustre regression tests suites.
19       -c CONFIG Test environment config file
20       -d LOGDIR Top level directory for logs
21       -f STR    Config name (cfg/<name>.sh)
22       -i N      Repeat tests N times (default 1). A new directory
23                 will be created under LOGDIR for each iteration.
24       -k        Don't stop when subtests fail
25       -R        Remount lustre between tests
26       -r        Reformat (during initial configuration if needed)
27       -s        SLOW=yes
28       -v        Verbose mode
29       -l        No logger to Maloo database
30       -h        This help.
31
32 Suite options
33 These are suite specific options that can be specified after each suite on
34 the command line.
35    suite-name  [options]
36       --only LIST         Run only specific list of subtests
37       --except LIST       Skip list of subtests
38       --start-at SUBTEST  Start testing from subtest
39       --stop-at SUBTEST   Stop testing at subtest
40       --time-limit LIMIT  Don't allow this suite to run longer
41                           than LIMT seconds. [UNIMPLEMENTED]
42
43 Example usage:
44 Run all of sanity and all of replay-single except for 70b with SLOW=y using
45 the default "local" configuration.
46
47   auster -s sanity replay-single --except 70b
48
49 Run test listed in batch-list 5 times  using large config.
50
51   auster -f large -r 5 -b batch-list
52
53 EOF
54     exit
55 }
56
57 dry_run=false
58 do_reset=false
59 verbose=false
60 repeat_count=1
61 logging=true
62 reformat=false
63 test_logs_dir=/tmp/test_logs
64 export SLOW=no
65 export ${NAME:=local}
66 while getopts "c:d:nkf:i:rRslhv" opt
67 do
68     case "$opt" in
69         c) CONFIG=$OPTARG;;
70         d) test_logs_dir=$OPTARG;;
71         k) export FAIL_ON_ERROR=false;;
72         n) dry_run=:;;
73         v) verbose=:;;
74         i) repeat_count=$OPTARG;;
75         f) NAME=$OPTARG;;
76         R) do_reset=:;;
77         r) reformat=:;;
78         s) SLOW=yes;;
79         l) logging=false;;
80         h|\?) usage;;
81     esac
82 done
83 shift $((OPTIND -1))
84
85 if [ $logging = true ] ; then
86   if [ ! -r ~/.maloorc ] ; then
87     echo "A ~/.maloorc file is required in order to upload results."
88     echo "  * Use -l to run without results upload (you can upload results later)"
89     echo "  or "
90     echo "  * Visit your maloo web interface to download your .maloorc file"
91     exit -1
92   fi
93 fi
94
95 #
96 # Various paramters for the tests scripts
97
98 #: ${SIZE:=$((RAMKB * 2))}
99 #: ${RSIZE:=512}
100 #: ${UID:=1000}
101 #: ${MOUNT=/mnt/lustre}
102 #: ${MOUNT2:=${MOUNT}2}
103 #: ${COUNT:=1000}
104 #: ${TMP:=/tmp}
105
106 reset_lustre() {
107     if $do_reset; then
108         stopall
109         setupall
110     fi
111 }
112
113 STARTTIME=`date +%s`
114
115 : ${LUSTRE:=$(cd $(dirname $0)/..; echo $PWD)}
116 . $LUSTRE/tests/test-framework.sh
117 init_test_env
118
119 print_summary () {
120     trap 0
121     local form="%-13s %-17s %s\n"
122     printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
123     echo "------------------------------------------------------------------------------------"
124     echo "Done!"
125 }
126
127
128 setup_if_needed() {
129     nfs_client_mode && return
130     auster_cleanup=false
131
132     local MOUNTED=$(mounted_lustre_filesystems)
133     if $(echo $MOUNTED | grep -w -q $MOUNT); then
134         check_config_clients $MOUNT
135        # init_facets_vars
136        # init_param_vars
137         return
138     fi
139
140     echo "Lustre is not mounted, trying to do setup ... "
141     $reformat && formatall
142     setupall
143
144     MOUNTED=$(mounted_lustre_filesystems)
145     if ! $(echo $MOUNTED | grep -w -q $MOUNT); then
146         echo "Lustre is not mounted after setup! "
147         exit 1
148     fi
149     auster_cleanup=true
150 }
151
152 cleanup_if_needed() {
153     if $auster_cleanup; then
154         cleanupall
155     fi
156 }
157
158 find_script_in_path() {
159     target=$1
160     path=$2
161     for dir in $(tr : " " <<< $path); do
162       if [ -e $dir/$target ]; then
163           echo $dir/$target
164           return 0
165       fi
166       if [ -e $dir/$target.sh ]; then
167           echo $dir/$target.sh
168           return 0
169       fi
170     done
171     return 1
172 }
173
174 title() {
175     log "-----============= acceptance-small: "$*" ============----- `date`"
176 }
177
178 doit() {
179     if $dry_run; then
180         printf "Would have run: %s\n" "$*"
181         return 0
182     fi
183     if $verbose; then
184         printf "Running: %s\n" "$*" 
185     fi
186     "$@"
187 }
188
189
190 run_suite() {
191     suite_name=$1
192     suite_script=$2
193     only=$3
194     title $suite_name
195     log_test $suite_name
196
197     local start_ts=$(date +%s)
198     doit bash $suite_script $only
199     rc=$?
200     duration=$(($(date +%s) - $start_ts))
201     if [ -f $TF_FAIL -o $rc -ne 0 ]; then
202         status="FAIL"
203     else
204         status="PASS"
205     fi
206     log_test_status $duration $status
207
208     reset_lustre
209 }
210
211 run_suite_logged() {
212     local suite_name=${1%.sh}
213     local suite=$(echo ${suite_name} | tr "[:lower:]-" "[:upper:]_")
214     local suite_only=${suite}_ONLY
215
216     suite_script=$(find_script_in_path $suite_name $PATH:$LUSTRE/tests)
217
218     if [[ -z $suite_script ]]; then
219         echo "Can't find test script for $suite_name"
220         return 1
221     fi
222     
223     echo "run_suite $suite_name $suite_script ${!suite_only}"
224     local log_name=${suite_name}.suite_log.$(hostname).log
225     run_suite $suite_name $suite_script "${!suite_only}"  > $LOGDIR/$log_name 2>&1
226 #    run_suite $suite_name $suite_script "${!suite_only}" 2>&1 |tee  $LOGDIR/$log_name
227
228 }
229
230 #
231 # Add this to test-framework somewhere.
232 reset_logging() {
233     export LOGDIR=${1:-/tmp/test_logs/$(date +%Y-%m-%d)/$(date +%H%M%S)}
234     unset YAML_LOG
235     init_logging
236 }
237
238 split_commas() {
239     echo "${*//,/ }"
240 }
241
242 run_suites() {
243     local n=0
244     local argv=("$@")
245     local basedir=${test_logs_dir}/$(date +%Y-%m-%d)/$(date +%H%M%S)
246     while ((n < repeat_count)); do
247         local RC=0
248         local logdir=$basedir
249         ((repeat_count > 1)) && logdir="$logdir/$n"
250         reset_logging $logdir
251         set -- "${argv[@]}"
252         while [[ -n $1 ]]; do
253             unset ONLY EXCEPT START_AT STOP_AT
254             local opts=""
255             local time_limit=""
256 #           echo "argv: $*"
257             suite=$1
258             shift;
259             while [[ -n $1 ]]; do
260                 case "$1" in
261                     --only)
262                         shift;
263                         export ONLY=$(split_commas $1)
264                         opts+="ONLY=$ONLY ";;
265                     --except)
266                         shift;
267                         export EXCEPT=$(split_commas $1)
268                         opts+="EXCEPT=$EXCEPT ";;
269                     --start-at)
270                         shift;
271                         export START_AT=$1
272                         opts+="START_AT=$START_AT ";;
273                     --stop-at)
274                         shift;
275                         export STOP_AT=$1
276                         opts+="STOP_AT=$STOP_AT ";;
277                     --time-limit)
278                         shift;
279                         time_limit=$1;;
280                     *)
281                         break;;
282                 esac
283                 shift
284             done
285             echo "running: $suite $opts"
286             run_suite_logged $suite || RC=$?
287             echo $suite returned $RC
288         done
289         if [ $logging = true ]; then
290                 ./maloo_upload.sh $LOGDIR
291         fi
292         n=$((n + 1))
293     done
294 }
295
296 export NAME MOUNT START CLEAN
297 . ${CONFIG:-$LUSTRE/tests/cfg/$NAME.sh}
298
299 assert_env mds_HOST MDS_MKFS_OPTS
300 assert_env ost_HOST OST_MKFS_OPTS OSTCOUNT
301 assert_env FSNAME MOUNT MOUNT2
302
303 setup_if_needed
304
305 run_suites "$@"
306 RC=$?
307
308 if [[ $RC -eq 0 ]]; then
309     cleanup_if_needed
310 fi
311
312 echo "Finished at `date` in $((`date +%s` - $STARTTIME))s"
313 echo "$0: completed with rc $RC" && exit $RC