Big filesystem testing update - skip the repair check for the moment, takes too long...
[xfstests-dev.git] / tools / auto-qa
1 #!/bin/sh
2 #
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of version 2 of the GNU General Public License as
7 # published by the Free Software Foundation.
8
9 # This program is distributed in the hope that it would be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 # Further, this software is distributed without any warranty that it is
14 # free of the rightful claim of any third person regarding infringement
15 # or the like.  Any license provided herein, whether implied or
16 # otherwise, applies only to this software file.  Patent licenses, if
17 # any, provided herein do not apply to combinations of this program with
18 # other software, or any other product whatsoever.
19
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write the Free Software Foundation, Inc., 59
22 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
23
24 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 # Mountain View, CA  94043, or:
26
27 # http://www.sgi.com 
28
29 # For further information regarding this notice, see: 
30
31 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #
33
34 # automatic qa system. 31/08/00 dxm@sgi.com
35
36 # configuration (you could tune this)
37
38 _log()
39 {
40     echo "$*" >&2
41     echo "$*" >> $LOG
42     sync
43 }
44
45 _fail()
46 {
47     if [ "$started" = "1" ] 
48     then
49         echo "auto-qa stopped" | wall
50         started=0
51     fi
52
53     _log "$*"
54     
55     # send special email if a cron'd qa run fails
56     case $state
57     in
58         cron*)
59             mail -s "XFS QA status report" $EMAIL \
60                 < $LOG 2>&1
61         ;;
62     esac
63
64     status=1
65     exit 1
66 }
67
68 _get_kernel_version()
69 {
70     [ -x "$WORKAREA" ] \
71         || _fail "can't access workarea $WORKAREA"
72     [ -r "$WORKAREA/linux/Makefile" ] \
73         || _fail "can't read makefile $WORKAREA/linux/Makefile"
74
75     eval `awk '
76         BEGIN { FS = "[ \t=]+" }
77         /^VERSION =/ { a=$2 }
78         /^PATCHLEVEL =/ { b=$2 }
79         /^SUBLEVEL =/ { c=$2 }
80         /^EXTRAVERSION =/ { d=$2 }
81         END { 
82             print "VERSION=" a "." b "." c d " ; SVERSION=" a "." b "." c
83         }
84    ' < $WORKAREA/linux/Makefile`
85 }
86
87 # this should be constant
88
89 ROOT="$HOME/qa"
90 HOST=`hostname -s`
91 if [ ! -z "$CVSROOT" ]; then
92     WORKAREA="$ROOT/linux-2.4-xfs"
93 else
94     [ -z "$WORKAREA" ] && WORKAREA="$ROOT/linux-xfs"
95 fi
96 export WORKAREA
97
98
99 export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/ptools:/usr/local/bin"
100 STATE=$ROOT/qa.state
101 QADIR="$WORKAREA/cmd/xfstests"
102 SUDO="su -c"
103 CONFIG="$ROOT/$HOST.config"
104 COMMON_CONFIG="$WORKAREA/cmd/xfstests/common.config"
105 SH="/bin/sh"
106 LOG="$ROOT/qa.log"
107
108 # do some cleanup on exit
109
110 _cleanup()
111 {
112     umount $SCRATCH_DEV &> /dev/null
113     umount $TEST_DEV &> /dev/null
114     if [ "$started" = 1 ]
115     then
116         echo "auto-qa stopped" | wall
117         started=0
118     fi
119 }
120 status=1
121 trap "_cleanup; exit \$status" 0 1 2 3 15
122
123 # clean exit
124
125 _success()
126 {
127     status=0
128     exit 0
129 }
130
131 _get_state()
132 {
133     state=`cat $STATE`
134 }
135
136 _set_state()
137 {
138     echo $1 > $STATE
139     _get_state
140 }
141
142 _change_state()
143 {
144     new=$1
145     
146     case $state
147     in
148         *-*)
149             case $new
150             in
151                 *-*)
152                     _set_state $new
153                     ;;
154                 *)
155                     _set_state `echo $state | sed "s/-.*$/-$new/"`
156                     ;;
157             esac
158             ;;
159         *)
160             _set_state $new
161             ;;
162     esac
163 }
164
165 _sudo()
166 {
167     $ROOT/su -c "$*" < /dev/null ;# HACK - we need a hacked su at the mo
168 }
169
170 _restart()
171 {
172     exec $ROOT/su -c "(shutdown -r now \"auto-qa rebooting\" )&" < /dev/null
173 }
174
175 _update_autoqa_file()
176 {
177     SELF="$ROOT/auto-qa"
178     SELF_UPDATE="cmd/xfstests/tools/auto-qa"
179     if [ -z "$CVSROOT" ]; then
180             cmd="p_tupdate $SELF_UPDATE"
181     else
182             cmd="cvs -z3 update $SELF_UPDATE"
183     fi
184     exec $SH -c "cd $WORKAREA ; $cmd; chmod +x $SELF_UPDATE ; exec $SELF"
185 }
186
187 _update_workarea()
188 {
189     if [ -z "$CVSROOT" ]; then
190         _log "  *** p_tupdate"
191         cd $WORKAREA 
192         p_tupdate 2>&1 \
193                         || _fail "          !!! p_tupdate failed"
194
195         _log "  *** p_check/p_purge"
196         cd $WORKAREA 
197         p_check -s | p_purge -yiu 2>&1 \
198                         || _fail "          !!! p_check/p_purge failed"
199
200         _log "  *** non-trunk files"
201         cd $WORKAREA 
202         p_list -c 2>&1 \
203                         || _fail "          !!! p_list failed"
204     else
205         _log "  *** cvs update"
206         cd $WORKAREA
207         cvs -z3 update -d
208     fi
209 }
210
211 _test_mkfs_xfs()
212 {
213     TEST_OPTIONS=""
214     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
215         TEST_OPTIONS="$TEST_OPTIONS -rrtdev=$TEST_RTDEV"
216     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
217         TEST_OPTIONS="$TEST_OPTIONS -llogdev=$TEST_LOGDEV"
218     _sudo /sbin/mkfs.xfs -f $TEST_OPTIONS $MKFS_OPTIONS $* $TEST_DEV
219     mkfs_status=$?
220     if [ "$USE_BIG_LOOPFS" = yes ]; then
221         [ -z "$RETAIN_AG_BYTES" ] && RETAIN_AG_BYTES=0
222         _sudo $QADIR/tools/ag-wipe -q -r $RETAIN_AG_BYTES $TEST_DEV
223     fi
224     return $mkfs_status
225 }
226
227 _test_mount()
228 {
229     TEST_OPTIONS=""
230     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
231         TEST_OPTIONS="$TEST_OPTIONS -ortdev=$TEST_RTDEV"
232     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
233         TEST_OPTIONS="$TEST_OPTIONS -ologdev=$TEST_LOGDEV"
234     _sudo mount -t xfs $TEST_OPTIONS $* $TEST_DEV $TEST_DIR
235 }
236
237
238 _log "*** linux-xfs QA (`date`)"
239
240 _get_state
241
242 # check preconditions for starting state
243 case $1
244 in
245     cron-init)
246         case $state
247         in
248             *done)
249                 ;;
250             *)
251                 _fail "    !!! cron-init while not in \"*done\" state"
252                 ;;
253         esac
254         ;;
255     cron-restarted)
256         # we don't auto restart after reboot, but cron the restart
257         # to happen a bit later - it's much easier and safer that way
258         if [ "$state" != "cron-restarted" ]
259         then
260             _fail "    !!! cron-restarted while not in \"cron-restarted\" state"
261         fi
262         ;;
263 esac
264
265 if [ "$1" != "" ]
266 then
267     _set_state $1
268 fi
269
270 [ "$UID" -eq 0 ]        && _fail "    !!! QA most be run as a normal user"
271 [ -d "$ROOT" ]          || _fail "    !!! QA root \"$ROOT\" not found"
272 [ -d "$WORKAREA" ]      || _fail "    !!! QA workarea \"$WORKAREA\" not found"
273 [ -r "$CONFIG" ]        || _fail "    !!! Can't read config file $CONFIG"
274 . "$COMMON_CONFIG"      || _fail "    !!! Couldn't source $COMMON_CONFIG"
275
276 _get_kernel_version
277 IMAGE="$BOOT/vmlinuz$EXTRA"
278 SYSTEMMAP="$BOOT/System.map-$VERSION$EXTRA"
279 MODULES="/lib/modules/$SVERSION"
280
281 cd $ROOT
282
283 started=1
284 echo "auto-qa started" | wall
285
286 while true
287 do
288     _get_state
289
290     _log "    *** state $state start (`date`)"
291     _log "      (user=$USER, host=$HOST)"
292     new_state=""
293
294     case $state
295     in
296         *init)
297             echo "" > $ROOT/qa.log
298             echo "" > $ROOT/qa.full
299             _log "******************************************************"
300             _log "QA init $VERSION (`date`)"
301             _log "******************************************************"
302             _log "--- kernel ($IMAGE)"
303             _log "--- modules ($MODULES)"
304
305             _change_state "inited"
306             _update_autoqa_file
307             ;;
308             
309         *inited)
310             _log "      *** QA initialized"
311             new_state="update"
312             ;;
313         
314         *update)
315             _update_workarea
316             new_state="clean"
317             ;;
318
319         *clean)
320             # we need to configure or else we might fail to clean
321             for pkg in attr acl xfsprogs dmapi xfsdump xfstests
322             do
323                 cd $WORKAREA/cmd/$pkg
324                 _log "  *** clean $pkg tools"
325                 make realclean 2>&1 \
326                         || _fail "          !!! clean $pkg failed"
327             done
328
329             _log "      *** clean linux"
330             cd $WORKAREA/linux
331             make mrproper 2>&1 \
332                         || _fail "          !!! clean linux failed"
333
334             _log "      *** install configuration file"
335             cp -f $CONFIG $WORKAREA/linux/.config 2>&1 \
336                         || _fail "          !!! failed to install config"
337             
338             _log "      *** remove version file"
339             rm -f include/linux/version.h 2>&1 \
340                         || _fail "          !!! failed to clean version"
341
342             new_state="reconfig"
343             ;;
344             
345         *reconfig)
346         
347             _log "      *** reconfig kernel"
348             
349             _change_state "clean" ; # we better start from scratch if this fails
350             
351             cd $WORKAREA/linux
352             # we want to use default options for any new config options.
353             echo -e "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" | \
354                 make EXTRAVERSION=$EXTRA oldconfig 2>&1 \
355                         || _fail "          !!! reconfig oldconfig failed"
356             make EXTRAVERSION=$EXTRA dep 2>&1 \
357                         || _fail "          !!! reconfig dep failed"
358
359             new_state="buildtools"
360             ;;
361             
362         *buildtools)
363             _log "      *** build and install tools"
364             for pkg in attr acl xfsprogs dmapi xfsdump xfstests 
365             do
366                 cd $WORKAREA/cmd/$pkg
367
368                 # use e-fence - but this will only take effect on configure
369                 make configure 2>&1 \
370                         || _fail "          !!! configure $pkg failed"
371                 make default 2>&1 \
372                         || _fail "          !!! build $pkg failed"
373
374                 _sudo make install install-dev 2>&1 \
375                         || _fail "          !!! install $pkg failed"
376
377                 # attr and acl now have install-lib targets as well
378                 [ "$pkg" = "attr" -o "$pkg" = "acl" ] || continue
379                 _sudo make install-lib 2>&1 \
380                         || _fail "          !!! install $pkg failed"
381             done
382
383             new_state="buildkernel"
384             ;;
385
386         *buildkernel)
387             _log "      *** build kernel"
388             
389             _change_state "clean" ; # we better start from scratch if this fails
390             
391             cd $WORKAREA/linux
392             make -j4 EXTRAVERSION=$EXTRA bzImage modules 2>&1 \
393                         || _fail "          !!! build bzImage/modules failed"
394             new_state="install"
395             ;;
396
397         *install)
398             _log "      *** blat old modules"
399             
400             _sudo rm -rf $MODULES
401             
402             _log "      *** install kernel"
403             cd $WORKAREA/linux
404             _sudo cp -f $WORKAREA/linux/arch/i386/boot/bzImage $IMAGE 2>&1 \
405                         || _fail "          !!! install kernel failed"
406             _sudo cp -f $WORKAREA/linux/System.map $SYSTEMMAP 2>&1 \
407                         || _fail "          !!! install kernel failed"
408             _sudo make EXTRAVERSION=$EXTRA modules_install 2>&1 \
409                         || _fail "          !!! install modules failed"
410
411             _log "      *** reinit lilo"
412             _sudo /sbin/lilo 2>&1 \
413                         || _fail "          !!! reinit lilo failed"
414             new_state="restart"
415             ;;
416             
417         *restart)
418             _log "          *** select qa kernel"
419             _sudo /sbin/lilo -R linux-xfs-qa $KERNEL_OPTIONS 2>&1 \
420                         || _fail "          !!! lilo failed"
421             
422             _log "          *** prepare to restart"
423             _change_state "restarted"
424             
425             _log "          *** restarting"
426
427             _restart # doesn't return
428             ;;
429             
430         *restarted)
431             _log "          *** QA reentered after restart"
432             
433             new_state="check"
434             ;;
435           
436         *check)
437             uname=`uname -ar`
438             _log "          *** uname $uname"
439             _log "          *** kernel"
440             ls -l /boot/*$EXTRA*  2>&1
441             _log "          *** kernel modules"
442             [ -d /lib/modules/$SVERSION$EXTRA/kernel/fs/xfs ] && \
443                 ls -l /lib/modules/$SVERSION$EXTRA/kernel/fs/xfs/*
444
445             if [ "$MODULAR" -eq 0 ]
446             then
447                 new_state="reset"
448             else
449                 new_state="probe"
450             fi
451             ;;
452             
453         *probe)
454             _log "          *** modules dependencies"
455             
456             _sudo depmod -a  2>&1 \
457                         || _fail "          !!! failed to depmod -a" 
458             
459             _log "          *** unmounting XFS mounts"
460             
461             _sudo umount -a -t xfs 2>&1
462             
463             _log "          *** removing modules"
464             
465             for m in xfsidbg xfs kdbm_pg kdbm_vm
466             do
467                 _sudo rmmod $m 2> /dev/null
468             done
469             
470             _log "          *** installing modules"
471
472             _sudo modprobe xfs 2>&1 \
473                         || _fail "          !!! failed to modprobe xfs"
474
475             new_state="reset"
476             ;;
477             
478         *reset)
479             
480             _log "          *** unmounting TEST_DEV"
481             
482             _sudo umount $TEST_DEV 2>&1
483             
484             _log "          *** unmounting SCRATCH_DEV"
485             
486             _sudo umount $SCRATCH_DEV 2>&1
487             
488             _log "          *** clean TEST_DEV"
489             
490             _test_mkfs_xfs 2>&1 \
491                         || _fail "          !!! failed to mkfs TEST_DEV"
492             
493             _log "          *** mounting TEST_DEV"
494             
495             _test_mount 2>&1 \
496                         || _fail "          !!! failed to mount"
497                                     
498             new_state="run"
499             ;;
500             
501         soak-run)
502             cd $QADIR
503             
504             _log "          *** run soak test"
505             _sudo ./soak $SOAK_PASSES $SOAK_STRESS $SOAK_PROC \
506                         || _fail "          !!! failed to run soak test"
507
508             new_state="done"
509             ;;
510             
511         bench-run)
512             cd $QADIR
513             
514             # $BENCHMARK is typically unset, which equates to "all"
515             #
516             _log "          *** run benchmarks"
517             _sudo ./bench $BENCH_PASSES `id -nu && id -ng` $BENCHMARK \
518                         || _fail "          !!! failed to run benchmarks"
519
520             _log ""
521             _log "          *** send results mail"
522             mail -s "XFS QA benchmark results" $EMAIL < $QADIR/bench.out 2>&1
523         
524             new_state="done"
525             ;;
526             
527         *run)
528             cd $QADIR
529             
530             _log "          *** run tests ($CHECK_OPTIONS)"
531             _sudo ./check -l $CHECK_OPTIONS 2>&1 | tee $ROOT/qa.out
532             
533             _log ""
534             _log "          *** send status mail"
535             mail -s "XFS QA status report" $EMAIL < $ROOT/qa.out 2>&1
536         
537             new_state="done"
538             ;;
539             
540         *done)
541             _log "*** QA run complete"
542
543             _success
544             ;;
545             
546         *nothing)
547             new_state="done"
548             _log "    *** do nothing"
549             ;;
550             
551         *)
552             _fail "        !!! unknown state $state"
553             ;;
554     esac
555
556     _log "    *** state $state done (`date`)"
557     [ "$new_state" = "" ] && _fail "    !!! no new state set"
558     _change_state $new_state
559     
560 done