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