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