Whamcloud - gitweb
LU-12045 tests: honor EXCEPT tests when using ONLY list
[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 export TF_SKIP=/tmp/tf.skip
15
16 usage() {
17         less -F <<EOF
18 Usage ${0##*/} [options]  suite [suite options] [suite [suite options]]
19 Run Lustre regression tests suites.
20       -c CONFIG Test environment config file
21       -d LOGDIR Top level directory for logs
22       -D FULLLOGDIR Full directory for logs
23       -f STR    Config name (cfg/<name>.sh)
24       -g GROUP  Test group file (Overrides tests listed on command line)
25       -S TESTSUITE First test suite to run allows for restarts
26       -H        Honor the EXCEPT and ALWAYS_EXCEPT list when --only is used
27       -i N      Repeat tests N times (default 1). A new directory
28                 will be created under LOGDIR for each iteration.
29       -k        Don't stop when subtests fail
30       -R        Remount lustre between tests
31       -r        Reformat (during initial configuration if needed)
32       -s        SLOW=yes
33       -v        Verbose mode
34       -l        Send logs to the Maloo database after run
35                   (can be done later by running maloo_upload.sh)
36       -L        Script language of test suite. Default: bash
37       -h        This help.
38
39 Suite options
40 These are suite specific options that can be specified after each suite on
41 the command line.
42    suite-name  [options]
43       --only LIST         Run only specific list of subtests
44       --except LIST       Skip list of subtests
45       --start-at SUBTEST  Start testing from subtest
46       --stop-at SUBTEST   Stop testing at subtest
47       --time-limit LIMIT  Don't allow this suite to run longer
48                           than LIMT seconds. [UNIMPLEMENTED]
49
50 Example usage:
51 Run all of sanity and all of replay-single except for 70b with SLOW=y using
52 the default "local" configuration.
53
54   auster -s sanity replay-single --except 70b
55
56 Run all tests in the regression group 5 times using large config.
57
58   auster -f large -g test-groups/regression -i 5
59
60 EOF
61         exit
62 }
63
64 dry_run=false
65 do_reset=false
66 verbose=false
67 repeat_count=1
68 upload_logs=false
69 reformat=false
70 script_lang=bash
71 test_logs_dir=/tmp/test_logs/$(date +%Y-%m-%d)/$(date +%H%M%S)
72 export HONOR_EXCEPT=
73 export ${SLOW:=no}
74 export ${NAME:=local}
75 while getopts "c:d:D:nkf:S:g:Hi:rRslL:hv" opt
76 do
77         case "$opt" in
78                 c) export CONFIG=$OPTARG;;
79                 d) test_logs_dir=$OPTARG/$(date +%Y-%m-%d)/$(date +%H%M%S);;
80                 D) test_logs_dir=$OPTARG;;
81                 g) test_group_file=$OPTARG;;
82                 S) FIRST_SUITE=$OPTARG;;
83                 k) export FAIL_ON_ERROR=false;;
84                 n) dry_run=:;;
85                 v) verbose=:;;
86                 H) export HONOR_EXCEPT="y";;
87                 i) repeat_count=$OPTARG;;
88                 f) NAME=$OPTARG;;
89                 R) do_reset=:;;
90                 r) reformat=:;;
91                 s) export SLOW=yes;;
92                 l) upload_logs=true;;
93                 L) script_lang=$OPTARG;;
94                 h|\?) usage;;
95         esac
96 done
97
98 # If a test_group_file is specified, then ignore rest of command line
99 if [[ $test_group_file ]]; then
100     export TEST_GROUP=$(basename $test_group_file)
101     set $(sed 's/#.*$//' $test_group_file)
102 else
103     shift $((OPTIND -1))
104 fi
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 && CLEANUP_DM_DEV=true 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 [ -f $dir/$target ]; then
163             echo $dir/$target
164             return 0
165         fi
166         if [ -f $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         local suite_name=$1
192         local suite_script=$2
193         title $suite_name
194         log_test $suite_name
195
196         rm -f $TF_FAIL
197         touch $TF_SKIP
198         local start_ts=$(date +%s)
199         doit $script_lang $suite_script
200         local rc=$?
201         local duration=$(($(date +%s) - $start_ts))
202
203         local status="PASS"
204         if [[ $rc -ne 0 || -f $TF_FAIL ]]; then
205                 status="FAIL"
206         elif [[ -f $TF_SKIP ]]; then
207                 status="SKIP"
208         fi
209         log_test_status $duration $status
210         [[ ! -f $TF_SKIP ]] || rm -f $TF_SKIP
211
212         reset_lustre
213 }
214
215 run_suite_logged() {
216     local suite_name=${1%.sh}
217     local suite=$(echo ${suite_name} | tr "[:lower:]-" "[:upper:]_")
218
219     suite_script=$(find_script_in_path $suite_name $LUSTRE/tests)
220
221     if [[ -z $suite_script ]]; then
222         echo "Can't find test script for $suite_name"
223         return 1
224     fi
225
226     echo "run_suite $suite_name $suite_script"
227     local log_name=${suite_name}.suite_log.$(hostname -s).log
228     if $verbose; then
229         run_suite $suite_name $suite_script 2>&1 |tee  $LOGDIR/$log_name
230     else
231         run_suite $suite_name $suite_script > $LOGDIR/$log_name 2>&1
232     fi
233
234 }
235
236 #
237 # Add this to test-framework somewhere.
238 reset_logging() {
239     export LOGDIR=$1
240     unset YAML_LOG
241     init_logging
242 }
243
244 split_commas() {
245     echo "${*//,/ }"
246 }
247
248 run_suites() {
249     local n=0
250     local argv=("$@")
251     while ((n < repeat_count)); do
252         local RC=0
253         local logdir=${test_logs_dir}
254         local first_suite=$FIRST_SUITE
255         ((repeat_count > 1)) && logdir="$logdir/$n"
256         reset_logging $logdir
257         set -- "${argv[@]}"
258         while [[ -n $1 ]]; do
259             unset ONLY EXCEPT START_AT STOP_AT
260             local opts=""
261             local time_limit=""
262             #echo "argv: $*"
263             suite=$1
264             shift;
265             while [[ -n $1 ]]; do
266                 case "$1" in
267                     --only)
268                         shift;
269                         export ONLY=$(split_commas $1)
270                         opts+="ONLY=$ONLY ";;
271                     --except)
272                         shift;
273                         export EXCEPT=$(split_commas $1)
274                         opts+="EXCEPT=$EXCEPT ";;
275                     --start-at)
276                         shift;
277                         export START_AT=$1
278                         opts+="START_AT=$START_AT ";;
279                     --stop-at)
280                         shift;
281                         export STOP_AT=$1
282                         opts+="STOP_AT=$STOP_AT ";;
283                     --time-limit)
284                         shift;
285                         time_limit=$1;;
286                     *)
287                         break;;
288                 esac
289                 shift
290             done
291             if [ "x"$first_suite == "x" ] || [ $first_suite == $suite ]; then   # If first_suite not set or this is the first suite
292                 echo "running: $suite $opts"
293                 run_suite_logged $suite || RC=$?
294                 unset first_suite
295                 echo $suite returned $RC
296             fi
297         done
298         if $upload_logs; then
299             $upload_script $LOGDIR
300         fi
301         n=$((n + 1))
302     done
303 }
304
305 if [ $upload_logs = true ] ; then
306     upload_script=$(find_script_in_path maloo_upload.sh $PATH:$LUSTRE/tests)
307     if [[ -z $upload_script ]]; then
308         echo "Can't find maloo_upload.sh script"
309         exit 1
310     fi
311
312     if [ ! -r ~/.maloorc ] ; then
313         echo "A ~/.maloorc file is required in order to upload results."
314         echo "Visit your maloo web interface to download your .maloorc file"
315         exit 1
316     fi
317 fi
318
319 export NAME MOUNT START CLEAN
320 . ${CONFIG:-$LUSTRE/tests/cfg/$NAME.sh}
321
322 assert_env mds_HOST
323 assert_env ost_HOST OSTCOUNT
324 assert_env FSNAME MOUNT MOUNT2
325
326 echo "Started at `date`"
327 setup_if_needed
328
329 run_suites "$@"
330 RC=$?
331
332 if [[ $RC -eq 0 ]]; then
333     cleanup_if_needed
334 fi
335
336 echo "Finished at `date` in $((`date +%s` - $STARTTIME))s"
337 echo "$0: completed with rc $RC" && exit $RC