Whamcloud - gitweb
LU-1866 osd: ancillary work for initial OI scrub
[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       -S TESTSUITE First test suite to run allows for restarts
25       -i N      Repeat tests N times (default 1). A new directory
26                 will be created under LOGDIR for each iteration.
27       -k        Don't stop when subtests fail
28       -R        Remount lustre between tests
29       -r        Reformat (during initial configuration if needed)
30       -s        SLOW=yes
31       -v        Verbose mode
32       -l        Send logs to the Maloo database after run
33                   (can be done later by running maloo_upload.sh)
34       -h        This help.
35
36 Suite options
37 These are suite specific options that can be specified after each suite on
38 the command line.
39    suite-name  [options]
40       --only LIST         Run only specific list of subtests
41       --except LIST       Skip list of subtests
42       --start-at SUBTEST  Start testing from subtest
43       --stop-at SUBTEST   Stop testing at subtest
44       --time-limit LIMIT  Don't allow this suite to run longer
45                           than LIMT seconds. [UNIMPLEMENTED]
46
47 Example usage:
48 Run all of sanity and all of replay-single except for 70b with SLOW=y using
49 the default "local" configuration.
50
51   auster -s sanity replay-single --except 70b
52
53 Run all tests in the regression group 5 times using large config.
54
55   auster -f large -g test-groups/regression  -r 5
56
57 EOF
58     exit
59 }
60
61 dry_run=false
62 do_reset=false
63 verbose=false
64 repeat_count=1
65 upload_logs=false
66 reformat=false
67 test_logs_dir=/tmp/test_logs/$(date +%Y-%m-%d)/$(date +%H%M%S)
68 export ${SLOW:=no}
69 export ${NAME:=local}
70 while getopts "c:d:D:nkf:S:g:i:rRslhv" opt
71 do
72     case "$opt" in
73         c) CONFIG=$OPTARG;;
74         d) test_logs_dir=$OPTARG/$(date +%Y-%m-%d)/$(date +%H%M%S);;
75         D) test_logs_dir=$OPTARG;;
76         g) test_group_file=$OPTARG;;
77         S) FIRST_SUITE=$OPTARG;;
78         k) export FAIL_ON_ERROR=false;;
79         n) dry_run=:;;
80         v) verbose=:;;
81         i) repeat_count=$OPTARG;;
82         f) NAME=$OPTARG;;
83         R) do_reset=:;;
84         r) reformat=:;;
85         s) SLOW=yes;;
86         l) upload_logs=true;;
87         h|\?) usage;;
88     esac
89 done
90
91 # If a test_group_file is specified, then ignore rest of command line
92 if [[ $test_group_file ]]; then
93     export TEST_GROUP=$(basename $test_group_file)
94     set $(sed 's/#.*$//' $test_group_file)
95 else
96     shift $((OPTIND -1))
97 fi
98
99 #
100 # Various paramters for the tests scripts
101 #
102 #: ${SIZE:=$((RAMKB * 2))}
103 #: ${RSIZE:=512}
104 #: ${UID:=1000}
105 #: ${MOUNT=/mnt/lustre}
106 #: ${MOUNT2:=${MOUNT}2}
107 #: ${COUNT:=1000}
108 #: ${TMP:=/tmp}
109
110 reset_lustre() {
111     if $do_reset; then
112         stopall
113         setupall
114     fi
115 }
116
117 STARTTIME=`date +%s`
118
119 : ${LUSTRE:=$(cd $(dirname $0)/..; echo $PWD)}
120 . $LUSTRE/tests/test-framework.sh
121 init_test_env
122
123 print_summary () {
124     trap 0
125     local form="%-13s %-17s %s\n"
126     printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
127     echo "------------------------------------------------------------------------------------"
128     echo "Done!"
129 }
130
131
132 setup_if_needed() {
133     nfs_client_mode && return
134     auster_cleanup=false
135
136     local MOUNTED=$(mounted_lustre_filesystems)
137     if $(echo $MOUNTED' ' | grep -w -q $MOUNT' '); then
138         check_config_clients $MOUNT
139        # init_facets_vars
140        # init_param_vars
141         return
142     fi
143
144     echo "Lustre is not mounted, trying to do setup ... "
145     $reformat && formatall
146     setupall
147
148     MOUNTED=$(mounted_lustre_filesystems)
149     if ! $(echo $MOUNTED' ' | grep -w -q $MOUNT' '); then
150         echo "Lustre is not mounted after setup! "
151         exit 1
152     fi
153     auster_cleanup=true
154 }
155
156 cleanup_if_needed() {
157     if $auster_cleanup; then
158         cleanupall
159     fi
160 }
161
162 find_script_in_path() {
163     target=$1
164     path=$2
165     for dir in $(tr : " " <<< $path); do
166         if [ -f $dir/$target ]; then
167             echo $dir/$target
168             return 0
169         fi
170         if [ -f $dir/$target.sh ]; then
171             echo $dir/$target.sh
172             return 0
173         fi
174     done
175     return 1
176 }
177
178 title() {
179     log "-----============= acceptance-small: "$*" ============----- `date`"
180 }
181
182 doit() {
183     if $dry_run; then
184         printf "Would have run: %s\n" "$*"
185         return 0
186     fi
187     if $verbose; then
188         printf "Running: %s\n" "$*"
189     fi
190     "$@"
191 }
192
193
194 run_suite() {
195     suite_name=$1
196     suite_script=$2
197     title $suite_name
198     log_test $suite_name
199
200     rm -f $TF_FAIL
201     local start_ts=$(date +%s)
202     doit bash $suite_script
203     rc=$?
204     duration=$(($(date +%s) - $start_ts))
205     if [ -f $TF_FAIL -o $rc -ne 0 ]; then
206         status="FAIL"
207     else
208         status="PASS"
209     fi
210     log_test_status $duration $status
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