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