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